Fixed problem with ssh keys

ssh key variable is a list of keys, not a single key. Use a loop
and the authorized keys module to fix this.
This commit is contained in:
Patrick Marchand 2019-01-18 09:30:42 -05:00
parent ec4070302d
commit 77269a2c3f
2 changed files with 28 additions and 25 deletions

View file

@ -1,26 +1,7 @@
---
- name: Create admins accounts
user:
state: present
name: '{{ item.value.name }}'
uid: '{{ item.value.uid }}'
password: '{{ item.value.password_hash_openbsd }}'
groups: wheel
shell: /bin/ksh
append: yes
with_dict:
"{{ evolix_users }}"
tags:
- admin
- name: Add admins ssh keys
lineinfile:
state: present
dest: '/home/{{ item.value.name }}/.ssh/authorized_keys'
line: '{{ item.value.ssh_keys }}'
create: yes
with_dict:
"{{ evolix_users }}"
tags:
- admin
- name: Create user accounts
include: user.yml
vars:
user: "{{ item.value }}"
with_dict: "{{ evolinux_users }}"
when: evolinux_users != {}

View file

@ -0,0 +1,22 @@
---
- name: "User '{{ user.name }}' is present"
user:
state: present
name: '{{ user.name }}'
uid: '{{ user.uid }}'
password: '{{ user.password_hash_openbsd }}'
groups: wheel
shell: /bin/ksh
append: yes
tags:
- admin
- name: "SSH public keys for '{{ user.name }}' are present"
authorized_key:
user: "{{ user.name }}"
key: "{{ ssk_key }}"
state: present
with_items: "{{ user.ssh_keys }}"
loop_control:
loop_var: ssk_key
when: user.ssh_keys is defined