Skip to content

Instantly share code, notes, and snippets.

Created July 11, 2017 12:49
Show Gist options
  • Save anonymous/55f1cff79c72418c8e7172588e1d962b to your computer and use it in GitHub Desktop.
Save anonymous/55f1cff79c72418c8e7172588e1d962b to your computer and use it in GitHub Desktop.
- 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: "{{ item.home }}"
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
@lanky
Copy link

lanky commented Jul 11, 2017

so I would....

  1. create host_vars and group_vars dirs in the same location as your playbook
  2. in group_vars/all I'd have
    home_root: /home
  3. in host_vars/SOMEHOST I'd have
    home_root: /someotherhome

and then in your variables files, wherever it says home:

admins:
- name: username
home: "{{ home_root|default('/home') }}/username
...
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment