2018-08-13 14:02:31 +00:00
|
|
|
---
|
2018-08-26 13:10:15 +00:00
|
|
|
- name: Add/Remove group
|
2018-08-13 14:02:31 +00:00
|
|
|
group:
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
gid: "{{ item.gid | default(omit) }}"
|
2018-08-15 18:35:23 +00:00
|
|
|
state: "{{ item.state | default('present') }}"
|
2018-08-13 14:02:31 +00:00
|
|
|
with_items: "{{ user_groups }}"
|
|
|
|
|
2018-08-15 18:35:23 +00:00
|
|
|
|
2018-08-26 13:10:15 +00:00
|
|
|
- name: Add/Remove user
|
2018-08-13 14:02:31 +00:00
|
|
|
user:
|
|
|
|
name: "{{ item.name }}"
|
2018-08-15 18:35:23 +00:00
|
|
|
state: "{{ item.state | default('present') }}"
|
|
|
|
password: "{{ item.password | default(omit) }}"
|
2018-08-13 14:02:31 +00:00
|
|
|
groups: "{{ item.groups | default(omit) }}"
|
2018-08-15 18:35:23 +00:00
|
|
|
uid: "{{ item.uid | default(omit) }}"
|
2018-08-13 14:02:31 +00:00
|
|
|
shell: "{{ item.shell | default(default_shell) }}"
|
2018-08-26 13:10:15 +00:00
|
|
|
remove: yes
|
|
|
|
no_log: False
|
2018-08-13 14:02:31 +00:00
|
|
|
with_items: "{{ users }}"
|
|
|
|
|
|
|
|
|
2018-08-26 13:10:15 +00:00
|
|
|
- name: Configure bashrc lines
|
2018-08-13 14:02:31 +00:00
|
|
|
lineinfile:
|
|
|
|
path: "/home/{{ item.0.name }}/.bashrc"
|
|
|
|
line: "{{ item.1.line }}"
|
2018-08-15 18:35:23 +00:00
|
|
|
state: "{{ item.1.state | default('present') }}"
|
|
|
|
backup: yes
|
2018-08-13 14:02:31 +00:00
|
|
|
with_subelements:
|
|
|
|
- "{{ users }}"
|
2018-08-18 12:07:19 +00:00
|
|
|
- bash_lines
|
2018-08-13 14:02:31 +00:00
|
|
|
- skip_missing: true
|
2018-08-26 13:10:15 +00:00
|
|
|
when: ansible_os_family == 'Debian' and item.0.state == "present"
|
2018-08-15 18:35:23 +00:00
|
|
|
|
2018-08-26 13:10:15 +00:00
|
|
|
- name: Configure bashrc blocks
|
|
|
|
blockinfile:
|
|
|
|
path: "/home/{{ item.0.name }}/.bashrc"
|
|
|
|
content: "{{ item.1.content }}"
|
|
|
|
marker: "# {mark} ANSIBLE managed content. Block item #{{ listitem }}"
|
|
|
|
state: "{{ item.1.state | default('present') }}"
|
|
|
|
backup: yes
|
|
|
|
with_subelements:
|
|
|
|
- "{{ users }}"
|
|
|
|
- bash_blocks
|
|
|
|
- skip_missing: true
|
|
|
|
when: ansible_os_family == 'Debian' and item.0.state == "present"
|
|
|
|
loop_control:
|
|
|
|
index_var: listitem
|
2018-08-13 14:02:31 +00:00
|
|
|
|
2018-08-26 13:10:15 +00:00
|
|
|
- name: Configure cshrc lines
|
2018-08-13 14:02:31 +00:00
|
|
|
lineinfile:
|
|
|
|
path: "/home/{{ item.0.name }}/.cshrc"
|
|
|
|
line: "{{ item.1.line }}"
|
2018-08-15 18:35:23 +00:00
|
|
|
state: "{{ item.1.state | default('present')}}"
|
2018-08-26 13:10:15 +00:00
|
|
|
backup: yes
|
2018-08-13 14:02:31 +00:00
|
|
|
with_subelements:
|
|
|
|
- "{{ users }}"
|
2018-08-18 12:07:19 +00:00
|
|
|
- csh_lines
|
2018-08-13 14:02:31 +00:00
|
|
|
- skip_missing: true
|
2018-08-26 13:10:15 +00:00
|
|
|
when: ansible_os_family == 'FreeBSD' and item.0.state == "present"
|
|
|
|
|
|
|
|
- name: Configure cshrc blocks
|
|
|
|
blockinfile:
|
|
|
|
path: "/home/{{ item.0.name }}/.cshrc"
|
2018-09-19 19:55:45 +00:00
|
|
|
content: "{{ item.1.content }}"
|
2018-08-26 13:10:15 +00:00
|
|
|
marker: "# {mark} ANSIBLE managed content. Block item #{{ listitem }}"
|
|
|
|
state: "{{ item.1.state | default('present')}}"
|
|
|
|
backup: yes
|
|
|
|
with_subelements:
|
|
|
|
- "{{ users }}"
|
|
|
|
- csh_blocks
|
|
|
|
- skip_missing: true
|
|
|
|
when: ansible_os_family == 'FreeBSD' and item.0.state == "present"
|
|
|
|
loop_control:
|
|
|
|
index_var: listitem
|
|
|
|
|
|
|
|
- name: Ensure sudo is installed (Debian)
|
|
|
|
apt:
|
|
|
|
name: sudo
|
|
|
|
update_cache: yes
|
|
|
|
cache_valid_time: "{{ apt_cache_valid | default('86400') }}"
|
|
|
|
when: ansible_os_family == "Debian"
|
|
|
|
|
|
|
|
- name: Ensure sudo is installed (FreeBSD)
|
|
|
|
portinstall:
|
|
|
|
name: sudo
|
|
|
|
state: present
|
|
|
|
when: ansible_os_family == "FreeBSD"
|
|
|
|
|
|
|
|
- name: Enable sudo for user
|
|
|
|
lineinfile:
|
|
|
|
path: "{{ sudoers_path }}/{{ item.name }}"
|
|
|
|
line: "{{ item.name }} ALL=(ALL) NOPASSWD:ALL"
|
|
|
|
state: present
|
|
|
|
create: true
|
|
|
|
when: item.enable_sudo is defined and item.enable_sudo == true
|
|
|
|
with_items: "{{ users }}"
|
|
|
|
|
|
|
|
- name: Disable sudo for user
|
|
|
|
file:
|
|
|
|
path: "{{ sudoers_path }}/{{ item.name }}"
|
|
|
|
state: absent
|
|
|
|
when: item.enable_sudo is defined and item.enable_sudo == false
|
|
|
|
with_items: "{{ users }}"
|
|
|
|
|
|
|
|
- name: Include sudoers.d
|
|
|
|
lineinfile:
|
|
|
|
dest: "{{ sudo_config_path }}"
|
|
|
|
state: present
|
|
|
|
regexp: '^\#includedir {{ sudoers_path }}'
|
|
|
|
line: '#includedir {{ sudoers_path }}'
|
|
|
|
validate: 'visudo -cf %s'
|
2018-08-13 14:02:31 +00:00
|
|
|
|