Closed zhan9san closed 4 weeks ago
If there is no customized _common_config_dir defined, it will raise an error, FAILED! => {"changed": false, "msg": "useradd: invalid home directory ''\n", "name": "foo", "rc": 3}.
_common_config_dir
FAILED! => {"changed": false, "msg": "useradd: invalid home directory ''\n", "name": "foo", "rc": 3}
Here is an Minimal reproducible example
- hosts: ubuntu become: true vars: _common_system_user: foo _common_system_group: foo _common_config_dir: "" tasks: - name: "Create system group {{ _common_system_group }}" ansible.builtin.group: name: "{{ _common_system_group }}" system: true state: present become: true - name: "Create system user {{ _common_system_user }}" ansible.builtin.user: name: "{{ _common_system_user }}" system: true shell: "/usr/sbin/nologin" group: "{{ _common_system_group }}" home: "{{ _common_config_dir | default('/') }}" create_home: false become: true
❯ ansible-playbook -i invenotory.yaml test.yaml PLAY [ubuntu] *************************************************************************************************************************************************************************************************** TASK [Gathering Facts] **************************************************************************************************************************************************************************************************** ok: [ubuntu] TASK [Create system group foo] ******************************************************************************************************************************************************************************************** ok: [ubuntu] TASK [Create system user foo] ********************************************************************************************************************************************************************************************* fatal: [ubuntu]: FAILED! => {"changed": false, "msg": "useradd: invalid home directory ''\n", "name": "foo", "rc": 3} PLAY RECAP **************************************************************************************************************************************************************************************************************** ubuntu : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
If there is no customized
_common_config_dir
defined, it will raise an error,FAILED! => {"changed": false, "msg": "useradd: invalid home directory ''\n", "name": "foo", "rc": 3}
.Here is an Minimal reproducible example
Playbook
Result