yet another question about loops
I want to be able to merge users across servers.
For example,
I want user1 to be on all of my hosts
and I want user_special_at_office to be only at my office's servers
So I made inventory file, where I specified all of the groups.
I made group_vars for all and for office
As I've read I can merge only dictionaries.
file group_vars/all
---
users:
user1:
comment: 'user1'
authorized:
- 'ssh-rsa 123'
- 'ssh-rsa 999'
- 'ssh-rsa 345'
file group_vars/office
---
users:
user_special_at_office:
comment: 'user_special_at_office'
authorized:
- 'ssh-rsa 555'
- 'ssh-rsa 444'
with this play
---
- hosts: all
tasks:
- name: add users
user: name={{ item.key }} comment="{{ item.value.comment }}"
with_dict: users
tags: user
- name: add sshkey for users
authorized_key: user={{ item.0.key }} key="{{ item.1 }}"
with_subelements:
- users
- authorized
tags: user_key
When I run this play with --tags user I get two users - so the merging is working.
But I'm completely hopeless to get the task "add sshkey for users" working.
One or more undefined variables: 'dict object' has no attribute 'key'
Please advise me how can I accoplish what I want