Ansible with subelements referencing a dict -


bear me, please. i've never had complex ansible , i'm struggling piece together.

to sum up, have dict , task deploy our employee's ssh accounts , public keys our servers. re-use dict deploy employee keys website user accounts. example explains better can.

employee_ssh_users:   user1: 'user1key'   user2: 'user2key'   user3: 'user3key'   user4: 'user4key'  - name: add employee ssh users   user:      name: "{{ item.key }}"     state: present   with_dict: "{{ employee_ssh_users }}"  - name: add employee public keys employee accounts   authorized_key:     user: "{{ item.key }}"     state: present     key: "{{ item.value }}"   with_dict: "{{ employee_ssh_users }}" 

the above configuration , tasks work fine adding our employees , keys servers. now, want re-use these keys can add employees other users without having copy , paste employee's keys. here i'm trying do:

website_keys:   - name: site1     authorized:       - user1       - user3   - name: site2     authorized:       - user1       - user2  - name: add employee public keys website accounts   authorized_key:     user: "{{ item.0.name }}"     key: "{{ hostvars[inventory_hostname]['employee_ssh_users'][' + item.1 '] }}"   with_subelements:     - "{{ website_keys }}"     - authorized 

basically, can't figure out need interpolate subelement key variable, if it's possible @ all.

it's quite simple:

- name: add employee public keys website accounts   authorized_key:     user: "{{ item.0.name }}"     key: "{{ employee_ssh_users[item.1] }}"   with_subelements:     - "{{ website_keys }}"     - authorized 

you can query employee_ssh_users name , use item.1 without quotes, variable itself.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -