---
- name: Deploy Users and Keys
hosts: tag_AddUsers_
sudo: yes
vars_files:
- "OpsTeam.yaml"
tasks:
- name: establish if user exists
shell: /usr/bin/getent passwd {{
item.name }} | /usr/bin/wc -l | tr -d ' '
register: user_exists
with_items: users
- name: create user group if doesnt already exist
when: user_exists.stdout == 0
with_together:
- users
- user_exists
- name: Add in Ops sudoers.d file
template: src=./ops dest=/etc/sudoers.d/ops
- name: add users
user: name={{
item.name }} createhome=yes group={{
item.name }} groups=ops append=no state=present shell=/bin/bash
when: user_exists.stdout == 0