Last active
October 12, 2022 07:03
-
-
Save qrkourier/cf585933ae58fb0c5b2073c7bf10a0e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about cronjobs or mail?