Skip to content

Instantly share code, notes, and snippets.

@qrkourier
Last active October 12, 2022 07:03
Show Gist options
  • Save qrkourier/cf585933ae58fb0c5b2073c7bf10a0e1 to your computer and use it in GitHub Desktop.
Save qrkourier/cf585933ae58fb0c5b2073c7bf10a0e1 to your computer and use it in GitHub Desktop.
# ansible playbook illustrating two approaches to change a list of users' uid:gid and
# update homedir files owner and mode to match
- hosts: all
vars:
user_dict:
bob: 2001
alice: 2002
user_list:
- bob
- alice
tasks:
- name: declare user and uid from parallel sets
user:
name: "{{ item.0 }}"
uid: "{{ item.1 }}"
group: "{{ item.0 }}"
with_together:
- "{{ user_list }}"
- "{{ range(2001,2003} | list }}"
- name: declare user and uid from dictionary
user:
name: "{{ item.key }}"
uid: "{{ item.value }}"
group: "{{ item.value }}"
with_dict: "{{ user_dict }}"
- name: declare group name and numeric id from parallel sets
group:
name: "{{ item.0 }}"
gid: "{{ item.1 }}"
with_together:
- "{{ user_list }}"
- "{{ range(2001,2003} | list }}"
- name: declare homedir owner and permission mode recursively using symbols from a list
file:
recurse: yes
path: "/home/{{ item }}"
owner: "{{ item }}"
group: "{{ item }}"
mode: u+rwX,go-rwx
with_items:
- "{{ user_list }}"
@reedloden
Copy link

What about cronjobs or mail?

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