Skip to content

Instantly share code, notes, and snippets.

@lanky
Forked from anonymous/gist:55f1cff79c72418c8e7172588e1d962b
Last active July 11, 2017 13:23
Show Gist options
  • Save lanky/e062dc55c463ea3c68d9a718927124e8 to your computer and use it in GitHub Desktop.
Save lanky/e062dc55c463ea3c68d9a718927124e8 to your computer and use it in GitHub Desktop.
admins:
- name: username1
pass: <redacted>
- name: username2
pass: <redacted>
home: "elephant" <-- means you'll get HOMEROOT/elephant rather that HOMEROOT/username2
---
home_root: /home
---
# homedirs on host THISHOST are somewhere non-standard
home_root: /users/homes
- hosts: all
tasks:
- include_vars: "variables/adminusers.yml"
- include_vars: "variables/delusers.yml"
- name: Remove users
user:
name: "{{ item.name }}"
# uid: "{{ item.uid }}"
state: absent
remove: yes
with_items: "{{ delusers }}"
- name: Create admin users
user:
name: "{{ item.name }}"
password: "{{ item.pass }}"
uid: "{{ item.uid }}"
group: users
shell: "{{ item.shell }}"
state: present
groups: sudo
home: "{{ home_root|default('/home') }}/{{ item.home|default(item.name) }}"
createhome: yes
with_items: "{{ admins }}"
- name: Add SSH keys
authorized_key:
user: "{{ item.0.name }}"
state: present
manage_dir: yes
key: "{{ item.1 }}"
with_subelements:
- "{{ admins }}"
- authorized_keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment