Verify if login exists

This commit is contained in:
Gregory Colpart 2017-08-17 14:47:37 +02:00
parent 94223e54a0
commit 35198325c4

View file

@ -1,5 +1,12 @@
---
- name: "Test if '{{ user.name }}' exists"
command: 'getent passwd {{ user.name }}'
register: loginisbusy
failed_when: False
changed_when: False
check_mode: no
- name: "Test if uid exists for '{{ user.name }}'"
command: 'getent passwd {{ user.uid }}'
register: uidisbusy
@ -16,7 +23,7 @@
shell: /bin/bash
password: '{{ user.password_hash }}'
update_password: on_create
when: uidisbusy.rc != 0
when: loginisbusy.rc != 0 and uidisbusy.rc != 0
- name: "Add Unix account with random uid for '{{ user.name }}'"
user:
@ -26,7 +33,7 @@
shell: /bin/bash
password: '{{ user.password_hash }}'
update_password: on_create
when: uidisbusy.rc == 0
when: loginisbusy.rc != 0 and uidisbusy.rc == 0
- name: "Create {{ admin_users_group }}"
group: