I am trying to learn Ansible and I've been dabbling with some roles that I've found on Github, specifically this one that automates user creation together with sudo rules and SSH key deployment:
https://github.com/GROG/ansible-role-management-user
I've cloned all four roles that are dependent and I am trying to use it to make two or more management users on a test server. I am having issues understanding, how to list more users to add:
- If I use the defaults/main.yml file of management role to list more users under the management_user_settings, the users get created, but their SSH keys are not deployed - they are deployed if there is only one user there.
management_user_settings:
- name: usr1
state: present
comment: user1 mykiy
shell: '/bin/bash'
authorized_keys:
- key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
exclusive: no
sudo:
hosts: ALL
as: ALL
commands: ALL
nopasswd: yes
- name: usr2
comment: user2 otherkiy
shell: '/bin/bash'
authorized_keys:
- key: "{{ lookup('file', '/home/user/SSH/user.name/id_rsa.pub') }}"
exclusive: no
sudo:
hosts: ALL
as: ORACLE
commands: ALL
nopasswd: yes
I've tried to list variables in a playbook for this role, but I have the same issue, users get created, but their SSH key is not deployed.
I've also tried to make a list with variables and use with_items: command, but I can't get it to work.
---
- hosts: all
user: root
vars:
user_list:
name: "{{ item.name }}"
comment: "{{ item.comment }}"
shell: '/bin/bash'
uid: "{{ item.uid }}"
groups: "{{ item.groups }}"
password: "{{ item.password }}"
state: "{{ item.state }}"
authorized_keys:
- key: "{{ item.key }}"
sudo: "{{ item.sudo }}"
management_user_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
management_user_settings:
- "{{ user_list }}"
management_user_list:
- "{{ management_user_settings }}"
management_user_list_host: []
management_user_list_group: []
sudo_root:
hosts: ALL
as: ALL
commands: ALL
nopasswd: yes
sudo_oracle:
hosts: ALL
as: ORACLE
commands: ALL
nopasswd: yes
roles:
- role: user-role-management
with_items:
- { name: abc1, comment: "a user", uid: 1300, password: somepw, state: present, key: "{{ lookup('file', '/home/user/SSH/user.name/id_rsa.pub') }}", sudo: "{{ sudo.root }}" }
- { name: abc2, comment: "b user", state: present, key: "{{ management_user_key }}", sudo: "{{ sudo.oracle }}" }
Is there a simple answer how do you add more management users with this role?
user_list
in the playbook is not a list.