I want to use register with loops (
http://docs.ansible.com/ansible/playbooks_loops.html#using-register-with-a-loop)
to accomplish below tasks:
-- Surf through couple of variables arrays in with_together format and save
result to a variable
-- now surf through that result set variable and perform specific action.
My register works fine with usual playbooks but the moment I use register
with with_together then no value is saved in variable? :(
*My playbook:*
- name: check for port on remote host
hosts: localhost
connection: local
vars_files:
- vars1.yml
tasks:
- name: check for ports
debug: msg="x is {{ item.0 }}, y is {{ item.1 }} and z is {{ item.2
}}"
with_together:
- "{{ x }}"
- "{{ y }}"
- "{{ z }}"
register: result
- debug: var=result.stdout_lines
*My Variables File:*
---
x: ['1','1','1','1','1','2','2','2','2','2','3','3']
y: ['0','0','0','0','0','0','0','0','0','0','0','0']
z: ['1','2','3','4','5','1','2','3','4','5','1','2']
*My output (as you can see I get variable not defined at the end. I have
tested that if I did not have "with_together" then register works just
fine):*
ansible-playbook pb.yml
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [check for port on remote host]
*******************************************
TASK [setup]
*******************************************************************
ok: [localhost]
TASK [check for ports]
*********************************************************
ok: [localhost] => (item=[u'1', u'0', u'1']) => {
"item": [
"1",
"0",
"1"
],
"msg": "x is 1, y is 0 and z is 1"
}
ok: [localhost] => (item=[u'1', u'0', u'2']) => {
"item": [
"1",
"0",
"2"
],
"msg": "x is 1, y is 0 and z is 2"
}
ok: [localhost] => (item=[u'1', u'0', u'3']) => {
"item": [
"1",
"0",
"3"
],
"msg": "x is 1, y is 0 and z is 3"
}
ok: [localhost] => (item=[u'1', u'0', u'4']) => {
"item": [
"1",
"0",
"4"
],
"msg": "x is 1, y is 0 and z is 4"
}
ok: [localhost] => (item=[u'1', u'0', u'5']) => {
"item": [
"1",
"0",
"5"
],
"msg": "x is 1, y is 0 and z is 5"
}
ok: [localhost] => (item=[u'2', u'0', u'1']) => {
"item": [
"2",
"0",
"1"
],
"msg": "x is 2, y is 0 and z is 1"
}
ok: [localhost] => (item=[u'2', u'0', u'2']) => {
"item": [
"2",
"0",
"2"
],
"msg": "x is 2, y is 0 and z is 2"
}
ok: [localhost] => (item=[u'2', u'0', u'3']) => {
"item": [
"2",
"0",
"3"
],
"msg": "x is 2, y is 0 and z is 3"
}
ok: [localhost] => (item=[u'2', u'0', u'4']) => {
"item": [
"2",
"0",
"4"
],
"msg": "x is 2, y is 0 and z is 4"
}
ok: [localhost] => (item=[u'2', u'0', u'5']) => {
"item": [
"2",
"0",
"5"
],
"msg": "x is 2, y is 0 and z is 5"
}
ok: [localhost] => (item=[u'3', u'0', u'1']) => {
"item": [
"3",
"0",
"1"
],
"msg": "x is 3, y is 0 and z is 1"
}
ok: [localhost] => (item=[u'3', u'0', u'2']) => {
"item": [
"3",
"0",
"2"
],
"msg": "x is 3, y is 0 and z is 2"
}
TASK [debug]
*******************************************************************
ok: [localhost] => {
"result.stdout_lines": "VARIABLE IS NOT DEFINED!"
}
PLAY RECAP
*********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/a587a43c-72a4-4826-aaca-b78aa45759ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.