Below is my playbook which loads variables and passes it to ls command on
remote hosts.
- name: Load repository
include_vars:
file="{{ playbook_dir }}/vars/listing.yml"
name=user1
- set_fact:
allinonecmd: "{{ allinonecmd | default('') + 'ls -ltr ' + item.path
+ ' '}}"
loop: "{{ user1[inventory_hostname] }}"
- name: Get stat
shell: "ssh {{ USER }}@{{ inventory_hostname }} '{{ allinonecmd }}'
>/web/htdocs/{{ item.ccode }}{{ item.ipseg }}.html"
delegate_to: localhost
loop: "{{ user1[inventory_hostname] }}"
below is my listing.yml
10.0.0.15:
- name: SCRIPT
path: /tmp/scripts
ccode: GRM-APP-
ipseg: "0.15"
- name: MOC
path: /tmp/moc
- name: EXE
path: /tmp/exe
- name: MTR
path: /tmp/mtr
This worked fine without ccode and ipseg entries in the listing.yml. I have
multiple entries for path which i loop over and construct the allinonecmd
string but the ccode is just needed once.
I get this error with a single entry of ccode in listing.yml
fatal: [10.0.0.15]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The
error was: 'dict object' has no attribute 'ccode'
For my existing playbook to work i have to specify ccode and ipseg under
each entry like below which works but looks ugly. It should be specified
just one time and the playbook should work.
10.0.0.15:
- name: SCRIPT
path: /tmp/scripts
ccode: GRM-APP-
ipseg: "0.15"
- name: MOC
path: /tmp/moc
ccode: GRM-APP-
ipseg: "0.15"
- name: EXE
path: /tmp/exe
ccode: GRM-APP-
ipseg: "0.15"
- name: MTR
path: /tmp/mtr
ccode: GRM-APP-
ipseg: "0.15"
Can you please suggest a clean way to get this to work ?
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/2d8d2651-2ffc-4f36-b565-0df941508cbb%40googlegroups.com.