Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: update default home directory #442

Merged

Conversation

zhan9san
Copy link
Contributor

@zhan9san zhan9san commented Oct 29, 2024

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

- 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

Result

❯ 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   

roles/_common/tasks/install.yml Outdated Show resolved Hide resolved
@github-actions github-actions bot added bugfix and removed bugfix labels Oct 29, 2024
Copy link
Member

@gardar gardar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@gardar gardar merged commit f9e5d1b into prometheus-community:main Oct 29, 2024
635 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment