Looping over Subelements

69 views
Skip to first unread message

Sacha Vukovic

unread,
Sep 6, 2015, 10:42:07 AM9/6/15
to Ansible Project
Hello,

I try to understand how works looping overs subelements, after reading this loops_subelements I had copy & past the example and he doesn't work :


TASK: [dbtier | debug msg="name={{ item.0.user }} password={{ item.0.mysql.password }} host={{ item.1 }} priv={{ item.0.mysql.privs | join('/') }}"] *** 
fatal: [srv-lbn-tux5] => could not find 'mysql.hosts' key in iterated item '{'authorized': ['/tmp/alice/onekey.pub', '/tmp/alice/twokey.pub'], 'name': 'alice', 'mysql': {'password': 'mysql-password', 'hosts': ['%', '127.0.0.1', '::1', 'localhost'], 'privs': ['*.*:SELECT', 'DB1.*:ALL']}}'

FATAL: all hosts have already failed -- aborting


 my tasks:

- debug: msg="name={{ item.0.user }} password={{ item.0.mysql.password }} host={{ item.1 }} priv={{ item.0.mysql.privs | join('/') }}"
  with_subelements:
    - users1
    - mysql.hosts
  tags: debug

vars_file:
users1:
  - name: alice
    authorized:
      - /tmp/alice/onekey.pub
      - /tmp/alice/twokey.pub
    mysql:
        password: mysql-password
        hosts:
          - "%"
          - "127.0.0.1"
          - "::1"
          - "localhost"
        privs:
          - "*.*:SELECT"
          - "DB1.*:ALL"
  - name: bob
    authorized:
      - /tmp/bob/id_rsa.pub
    mysql:
        password: other-mysql-password
        hosts:
          - "db1"
        privs:
          - "*.*:SELECT"
          - "DB2.*:ALL"


Ansible version:1.9.2

Can you explain me why ? 



Serge van Ginderachter

unread,
Sep 6, 2015, 11:22:12 AM9/6/15
to ansible...@googlegroups.com

On 5 September 2015 at 16:35, Sacha Vukovic <vukovic...@gmail.com> wrote:
I try to understand how works looping overs subelements, after reading this loops_subelements I had copy & past the example and he doesn't work :


​The extended feature where you can target a subkey, is a featur eonly available in the developmen version - the upcoming v 2.0.

(The docs online seem to nog show that I'm afraid)​


Sacha Vukovic

unread,
Sep 6, 2015, 2:27:13 PM9/6/15
to Ansible Project
Erf :( , are you sure of that ? 
Reply all
Reply to author
Forward
0 new messages