| 1 |
--- |
| 2 |
# Copyright (c) Ansible Project |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
# Get systemd version and if it doesn't exist don't run these tests. |
| 7 |
- name: check systemd version |
| 8 |
command: "systemctl --version" |
| 9 |
register: systemd_version |
| 10 |
ignore_errors: true |
| 11 |
|
| 12 |
- name: check homectl version |
| 13 |
command: homectl --version |
| 14 |
register: homectl_version |
| 15 |
ignore_errors: true |
| 16 |
|
| 17 |
- block: |
| 18 |
- name: Install legacycrypt on Python 3.13+ (non-Archlinux) |
| 19 |
pip: |
| 20 |
name: legacycrypt |
| 21 |
when: |
| 22 |
- ansible_facts.python_version is version("3.13", ">=") |
| 23 |
- ansible_facts.distribution != 'Archlinux' |
| 24 |
|
| 25 |
- name: Install passlib on Archlinux |
| 26 |
package: |
| 27 |
name: python-passlib |
| 28 |
state: present |
| 29 |
when: ansible_facts.distribution == 'Archlinux' |
| 30 |
|
| 31 |
- name: Check and start systemd-homed service |
| 32 |
service: |
| 33 |
name: systemd-homed.service |
| 34 |
state: started |
| 35 |
enabled: true |
| 36 |
|
| 37 |
- name: Add a user 'james' |
| 38 |
community.general.homectl: |
| 39 |
name: james |
| 40 |
password: myreallysecurepassword1! |
| 41 |
state: present |
| 42 |
|
| 43 |
- name: verify user added |
| 44 |
command: homectl inspect james |
| 45 |
register: james_info |
| 46 |
|
| 47 |
- name: Add the user 'tom' with a zsh shell, uid of 1000, and gid of 1000 |
| 48 |
community.general.homectl: |
| 49 |
name: tom |
| 50 |
password: myreallysecurepassword1! |
| 51 |
state: present |
| 52 |
shell: /bin/zsh |
| 53 |
uid: 1000 |
| 54 |
gid: 1000 |
| 55 |
disksize: 10G |
| 56 |
register: tom_userinfo |
| 57 |
|
| 58 |
- name: Try to add user 'james' that already exists |
| 59 |
community.general.homectl: |
| 60 |
name: james |
| 61 |
password: myreallysecurepassword1! |
| 62 |
state: present |
| 63 |
shell: /bin/ksh |
| 64 |
register: user_exists |
| 65 |
|
| 66 |
- name: Try to use 'resize=yes' option without 'disksize' option (not allowed) |
| 67 |
community.general.homectl: |
| 68 |
name: foo |
| 69 |
password: uq4895738!@#$%dfd |
| 70 |
state: present |
| 71 |
resize: true |
| 72 |
register: resize_out |
| 73 |
ignore_errors: true |
| 74 |
|
| 75 |
- name: Use option 'disksize=1G' without option resize (allowed) |
| 76 |
community.general.homectl: |
| 77 |
name: foobar |
| 78 |
password: "uq4895738!@#$%dfd" |
| 79 |
state: present |
| 80 |
disksize: 1G |
| 81 |
register: disk_out |
| 82 |
ignore_errors: true |
| 83 |
|
| 84 |
- name: Try to Create user without giving password |
| 85 |
community.general.homectl: |
| 86 |
name: danielle |
| 87 |
register: danielle_out |
| 88 |
ignore_errors: true |
| 89 |
|
| 90 |
- name: remove user 'foobar' without requiring password |
| 91 |
community.general.homectl: |
| 92 |
name: foobar |
| 93 |
state: absent |
| 94 |
register: delete_foobar_out |
| 95 |
|
| 96 |
- name: modify user 'james' to have zsh shell and timezone 'America/New_York' |
| 97 |
community.general.homectl: |
| 98 |
name: james |
| 99 |
password: myreallysecurepassword1! |
| 100 |
state: present |
| 101 |
shell: /bin/zsh |
| 102 |
timezone: America/New_York |
| 103 |
register: lukuser_modify_out |
| 104 |
|
| 105 |
- name: create user 'jake' with all mount options |
| 106 |
community.general.homectl: |
| 107 |
name: jake |
| 108 |
password: myreallysecurepassword12! |
| 109 |
mountopts: noexec,nosuid,nodev |
| 110 |
sshkeys: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDUSW/q2qFZPr2vS0qrmAs+1iQI1jLIBdJ4CVIhE3KnIwxkkiInS8mJ+t0FBTeK3ks3GZLPVYC1v9o2P+oqyUk1CiBnCsMXGJud+L/t8b5r8MiJMyP7Jzd6yhmcvenjvz+vY06jQ9chWAtThEknuaOMongIpQQzSLGbdMy0yMsz4GEjicwdcj1PDwItPvUt4TL4K7V9NE672idADlRt6qng4UwpziqlYgsyIG46ettDras8hGAPricrhFWUS2rLDsCD0thkPFdR8HL1ZWTZ6LtolhO4MYtgntzXn708TTmFC2oIDluzyxVoUYmsfVotVdXFZcOWffnwbCgU+tn75JXTLozgTbV3VWmkxpJFErCWPerxcZv3+7b0f36/Y0gRNjM9HERLDSE1c8yz29NOLY0qH5306aByjOaerxNq9+ZOU/Fmf5/VfGIUp/FdLxDw+V0AzejFG580VAcstEMsOHSdwTbi3gf6LoGSiRyWKKDod0TZCMC6RzfdsfdsfI9CClGl0s= [email protected]" |
| 111 |
register: jake_out |
| 112 |
|
| 113 |
- name: Try to remove user 'janet' that doesn't exist |
| 114 |
community.general.homectl: |
| 115 |
name: janet |
| 116 |
state: absent |
| 117 |
register: user_not_exist |
| 118 |
ignore_errors: true |
| 119 |
|
| 120 |
- name: Use check_mode to try and create user 'diana' |
| 121 |
community.general.homectl: |
| 122 |
name: diana |
| 123 |
password: helloworld123!@ |
| 124 |
state: present |
| 125 |
check_mode: true |
| 126 |
register: diana_create_checkmode_out |
| 127 |
|
| 128 |
- name: Verify user 'diana' was not created with check_mode |
| 129 |
command: homectl inspect diana |
| 130 |
register: user_diana_exists |
| 131 |
ignore_errors: true |
| 132 |
|
| 133 |
- name: Try to modify user 'jake' with only noexec mount option in check_mode |
| 134 |
community.general.homectl: |
| 135 |
name: jake |
| 136 |
password: myreallysecurepassword12! |
| 137 |
state: present |
| 138 |
mountopts: noexec |
| 139 |
check_mode: true |
| 140 |
register: jake_checkmode_out |
| 141 |
|
| 142 |
- name: Verify user 'jake' was not modified and still has all mount options |
| 143 |
command: homectl inspect jake |
| 144 |
register: user_jake_details_out |
| 145 |
|
| 146 |
- name: Modify user 'jake' with only noexec mount option |
| 147 |
community.general.homectl: |
| 148 |
name: jake |
| 149 |
password: myreallysecurepassword12! |
| 150 |
state: present |
| 151 |
mountopts: noexec |
| 152 |
register: jake_modify_out |
| 153 |
|
| 154 |
- name: modify user 'jake' again with only noexec mount option to make sure changed is false as nothing has changed. |
| 155 |
community.general.homectl: |
| 156 |
name: jake |
| 157 |
password: myreallysecurepassword12! |
| 158 |
state: present |
| 159 |
mountopts: noexec |
| 160 |
register: jake_modify_again_out |
| 161 |
|
| 162 |
- name: Try to modify user 'jake' with an incorrect password |
| 163 |
community.general.homectl: |
| 164 |
name: jake |
| 165 |
password: incorrectPassword! |
| 166 |
state: present |
| 167 |
mountopts: noexec |
| 168 |
locked: true |
| 169 |
ignore_errors: true |
| 170 |
register: jake_incorrect_pass_out |
| 171 |
|
| 172 |
- assert: |
| 173 |
that: |
| 174 |
- james_info.rc == 0 |
| 175 |
- tom_userinfo.data['gid'] == 1000 and tom_userinfo.data['uid'] == 1000 |
| 176 |
- user_exists is changed and user_exists.data['shell'] == '/bin/ksh' |
| 177 |
- resize_out is not changed |
| 178 |
- disk_out is changed |
| 179 |
- delete_foobar_out is changed |
| 180 |
- danielle_out is not changed |
| 181 |
- lukuser_modify_out.data['timeZone'] == "America/New_York" and lukuser_modify_out.data['shell'] == "/bin/zsh" |
| 182 |
- user_not_exist is not changed and user_not_exist.msg == "User does not exist!" |
| 183 |
- jake_out is changed and jake_out.data['mountNoDevices'] == True and jake_out.data['mountNoSuid'] == True and jake_out.data['mountNoExecute'] == True |
| 184 |
- diana_create_checkmode_out is changed and 'No home for user diana known' in user_diana_exists.stderr |
| 185 |
- "jake_checkmode_out is changed and 'Mount Flags: nosuid nodev noexec' in user_jake_details_out.stdout" |
| 186 |
- jake_modify_out is changed and jake_modify_out.data['privileged']['sshAuthorizedKeys'] is not none |
| 187 |
- jake_modify_out.data['mountNoDevices'] == False and jake_modify_out.data['mountNoExecute'] == True and jake_modify_out.data['mountNoSuid'] == False |
| 188 |
- jake_modify_again_out is not changed |
| 189 |
- jake_incorrect_pass_out is not changed and jake_incorrect_pass_out is failed and jake_incorrect_pass_out.msg == 'User exists but password is incorrect!' |
| 190 |
|
| 191 |
# homectl was first introduced in systemd 245 so check version >= 245 and make sure system has systemd and homectl command |
| 192 |
when: |
| 193 |
- systemd_version.rc == 0 and (systemd_version.stdout | regex_search('[0-9][0-9][0-9]') | int >= 245) and homectl_version.rc == 0 |
| 194 |
- ansible_facts.distribution != 'Fedora' or ansible_facts.distribution_major_version|int < 36 # TODO! |