I am trying to automate the same credential for cyberark to make different queries using Ansible. You can see the same details repeat and repeat again for:
username: user
password: p@ssword
server: abc.com
i have written a module for cyberark to handle all functions like retrieving passwords, creating new accounts, check account existence, etc
While I know it is possible for yaml to create duplicated nodes and modifying its value. I have tested the following code is working fine in a single playbook:
hosts: localhost
gather_facts: no
vars:
cyberArkUsername: user
cyberArkPassword: p@ssword
server: abc.com
Details: &basicCA
state:
username: "{{ cyberArkUsername }}"
password: "{{ cyberArkPassword }}"
server: "{{ server }}"
account:
accountname:
tasks:
- name: check exist
CyberArkModule:
<<: *basicCA
state: check
account:
accountname: test_CA
However when i try to migrate this logic to a role It doesn't work at all
var declared in vars/main.yml
CADetails: &login
state:
server: abc.com
username: user
password: p@ssword
account:
when I try to run tasks/main.yml
- name: fetch password
CyberarkModule:
<<: *login
state: check
account:
accountname: test_CA
it will prompt
Syntax Error while loading YAML. found undefined alias
what's the right way to save the few lines of code and duplication?