Paulo,
I Think the fix should be:
- name: 'Item'
debug:
var: item
with_items: "{{ databases}}"
Op donderdag 6 juli 2017 00:54:11 UTC+2 schreef Paolo Galizzi:
>
> Hello,
>
> I have some trouble on reusing a code wrote for Ansible 2.1.1.0 with
> Ansible 2.3.1.0.
> With Ansible 2.3 when I try reading, from a task of a role, a nested
> variable that comes from "group_vars", tells me that variable isn't define.
>
> I remove all unnecessary from my code and create an example code
> (following).
>
> The structure is :
> - test.yml
> - group_vars:
> - db.yml
> - hosts:
> - dev
> - roles:
> - dbtest:
> - tasks:
> - main.yml
>
>
> Where "test.yml" is:
> - name: test
> hosts: db
> gather_facts: false
> roles:
> - dbtest
>
>
> "db.yml" under group_vars is:
> databases:
> - name: dbName
> encoding: utf8
>
>
> "dev" under "hosts" is :
> [local-db]
> localhost
>
> [db:children]
> local-db
>
>
> "main.yml" under "roles/dbtest/tasks" is:
> - name: 'Print databases'
> debug:
> var: databases
>
>
> - name: 'Item'
> debug:
> var: item
> with_items: databases
>
>
> - name: 'Item Name'
> debug:
> var: item.name
> with_items: databases
>
>
> When I run the code with Ansible 2.1.1.0 calling
> ansible-playbook -i hosts/dev test.yml
> ,I got this output:
>
>
>
> PLAY [test]
> ********************************************************************
>
>
> TASK [dbtest : Print databases]
> ************************************************
> ok: [localhost] => {
> "databases": [
> {
> "encoding": "utf8",
> "name": "dbName"
> }
> ]
> }
>
>
> TASK [dbtest : Item]
> ***********************************************************
> ok: [localhost] => (item={u'name': u'dbName', u'encoding': u'utf8'}) => {
> "item": {
> "encoding": "utf8",
> "name": "dbName"
> }
> }
>
>
> TASK [dbtest : Item Name]
> ******************************************************
> ok: [localhost] => (item={u'name': u'dbName', u'encoding': u'utf8'}) => {
> "item": {
> "encoding": "utf8",
> "name": "dbName"
> },
> "item.name": "dbName"
> }
>
>
> PLAY RECAP
> *********************************************************************
> localhost : ok=3 changed=0 unreachable=0 failed=
> 0
>
>
> When I run with Ansible 2.3.1.0 the output is:
>
> PLAY [test]
> **********************************************************************************************************
>
>
> TASK [dbtest : Print databases]
> **************************************************************************************
> ok: [localhost] => {
> "databases": [
> {
> "encoding": "utf8",
> "name": "dbName"
> }
> ]
> }
>
>
> TASK [dbtest : Item]
> *************************************************************************************************
> ok: [localhost] => (item=databases) => {
> "item": "databases"
> }
>
>
> TASK [dbtest : Item Name]
> ********************************************************************************************
> ok: [localhost] => (item=databases) => {
> "item": "databases",
> "item.name": "VARIABLE IS NOT DEFINED!"
> }
>
>
> PLAY RECAP
> ***********************************************************************************************************
> localhost : ok=3 changed=0 unreachable=0 failed=
> 0
>
>
> As you can see, on the last step when I try to read "item.name" the old
> one works, the new one doesn't see the variable.
>
> I'd like to understand if is possible and how modify my code in order that
> will work also with Ansible 2.3 (considering that in my full code I widely
> use nested variable as describe above.
>
> Tell me if you need more information and if you have any suggestion, thanks
>
> Paolo
>
--
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/4d214db8-e661-441c-8e15-519d1e71c927%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.