Hello Folks,
I have a debugging question that has left me scratching my head. I
have a vars file with the following vars (using ansible 2.3.2.0):
packages1:
one:
version: "one-ish"
two:
version: "two-ish"
##
I have a playbook with the following debugging statements:
---
- hosts: localhost
connection: local
gather_facts: no
vars_files:
- vars.yml
tasks:
- debug:
var: "{{ item.version }}"
with_items: "{{ packages1 }}"
- debug:
var: packages1.one.version
- debug:
var: packages1
##
Here is the result:
TASK [debug]
********************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args'
has an invalid value, which appears to include a variable that is
undefined. The error was: *'ansible.vars.unsafe_proxy.AnsibleUnsafeText
object'*
if I just print the items:
---
- hosts: localhost
connection: local
gather_facts: no
vars_files:
- vars.yml
tasks:
- debug:
var: "{{ item }}"
with_items: "{{ packages1 }}"
- debug:
var: packages1.one.version
- debug:
var: packages1
I get the following results:
ansible-playbook play.yml
[WARNING]: Host file not found: /etc/ansible/hosts
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [localhost]
****************************************************************************************************************************************************************************************
TASK [debug]
********************************************************************************************************************************************************************************************
ok: [localhost] => (item=two) => {
"item": "two",
"two": "VARIABLE IS NOT DEFINED!"
}
ok: [localhost] => (item=one) => {
"item": "one",
"one": "VARIABLE IS NOT DEFINED!"
}
TASK [debug]
********************************************************************************************************************************************************************************************
ok: [localhost] => {
"packages1.one.version": "one-ish"
}
TASK [debug]
********************************************************************************************************************************************************************************************
ok: [localhost] => {
"packages1": {
"one": {
"version": "one-ish"
},
"two": {
"version": "two-ish"
}
}
}
PLAY RECAP
**********************************************************************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
Why can't the "with_items" loop pickup list elements and it's values?? What
am I missing here?
--
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/ad5dca6e-26e0-458c-adac-1b7c08f2649e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.