Hi all,
I am trying to set a loop on with_together way but I am using nested variables with lists, and I do not have clear how the is code .
My first variable is the next:
-
vmStorage: { vcpu: 1,
ram: 1024,
storage: 10,
vms: [{name: storage1-dev02,ip: 10.199.3.87},
{name: storage2-dev02,ip: 10.199.3.88},
{name: storage3-dev02,ip: 10.199.3.89}]
}
My second variable is a register created on this way: -
name: getting tty
shell: virsh dumpxml {{ item.name }} | grep “tty=” | cut -d= -f3 | cut -d/ -f4 | cut -d' -f1
with_items: vmHash.vms
register: ntty
Then I am using ntty variable as this without problem:
- name: entering on the shell inside each tty
shell: “echo ‘6’ > /dev/pts/{{ item.stdout }}”
with_items: ntty.results
and also vmHash.vms variables, for example with:
- name: Do not worry about the previous error, checking if the vms are up
wait_for: host={{ item.ip }}
port=22
timeout=200
delegate_to: localhost
with_items: vmHash.vms
but the problem is when I want to use the with_together loop with these variables.
The command is the next:
shell: “echo ‘sed -i ‘’ ‘s/{{ goldenip }}/{{ first list variables }}/g’ /cf/conf/config.xml’ > /dev/pts/{{ second list variables }}”
I have tried a lot of ways without success, for example:
- name: send stuff2 to all ttys
shell: “echo ‘sed -i ‘’ ‘s/{{ goldenip }}/{{ item.0.ip }}/g’ /cf/conf/config.xml’ > /dev/pts/{{ item.1.stdout }}”
with_together:- vmHash.vms
- ntty.results
with the next error TASK: [send stuff2 to all ttys] ***********************************************
fatal: [x.x] => One or more undefined variables: ‘str object’ has no attribute ‘ip’
or
- name: send stuff2 to all ttys
shell: “echo ‘sed -i ‘’ ‘s/{{ goldenip }}/{{ item.0 }}/g’ /cf/conf/config.xml’ > /dev/pts/{{ item.1 }}”
with_together:- vmHash.vms.ip
- ntty.results.ip
with the next error:
TASK: [send stuff2 to all ttys] ***********************************************
failed: [s04.lab] => (item=[‘v’, ‘n’]) => {“changed”: true, “cmd”: "echo ‘sed -i ‘’ ‘s/10.199.3.82/v/g’ /cf/conf/config.xml’ > /dev/pts/n ", “delta”: “0:00:00.005936”, “end”: “2013-12-17 16:04:15.616932”, “item”: [“v”, “n”], “rc”: 1, “start”: “2013-12-17 16:04:15.610996”}
stderr: /bin/sh: /dev/pts/n: Permission denied
failed: [s04.lab] => (item=[‘m’, ‘t’]) => {“changed”: true, “cmd”: "echo ‘sed -i ‘’ ‘s/10.199.3.82/m/g’ /cf/conf/config.xml’ > /dev/pts/t ", “delta”: “0:00:00.005735”, “end”: “2013-12-17 16:04:17.796956”, “item”: [“m”, “t”], “rc”: 1, “start”: “2013-12-17 16:04:17.791221”}
stderr: /bin/sh: /dev/pts/t: Permission denied
(It is getting the name of the variable)
How could I run the command using the ip and the number of tty?
Cheers,
Pablo Hinojosa