status
stringclasses
1 value
repo_name
stringclasses
31 values
repo_url
stringclasses
31 values
issue_id
int64
1
104k
title
stringlengths
4
233
body
stringlengths
0
186k
issue_url
stringlengths
38
56
pull_url
stringlengths
37
54
before_fix_sha
stringlengths
40
40
after_fix_sha
stringlengths
40
40
report_datetime
timestamp[us, tz=UTC]
language
stringclasses
5 values
commit_datetime
timestamp[us, tz=UTC]
updated_file
stringlengths
7
188
chunk_content
stringlengths
1
1.03M
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
if found and not key and state == "absent": module.run_command([sshkeygen, '-R', host, '-f', path], check_rc=True) params['changed'] = True if replace_or_add or found != (state == "present"): try: inf = open(path, "r") except IOError as e: if e.errno == errno.ENOENT: inf = None else: module.fail_json(msg="Failed to read %s: %s" % (path, str(e))) try: with tempfile.NamedTemporaryFile(mode='w+', dir=os.path.dirname(path), delete=False) as outf: if inf is not None: for line_number, line in enumerate(inf): if found_line == (line_number + 1) and (replace_or_add or state == 'absent'): continue outf.write(line) inf.close() if state == 'present': outf.write(key) except (IOError, OSError) as e: module.fail_json(msg="Failed to write to file %s: %s" % (path, to_native(e))) else: module.atomic_move(outf.name, path) params['changed'] = True return params def sanity_check(module, host, key, sshkeygen):
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
'''Check supplied key is sensible host and key are parameters provided by the user; If the host provided is inconsistent with the key supplied, then this function quits, providing an error to the user. sshkeygen is the path to ssh-keygen, found earlier with get_bin_path ''' if not key: return if re.search(r'\S+(\s+)?,(\s+)?', host): module.fail_json(msg="Comma separated list of names is not supported. " "Please pass a single name to lookup in the known_hosts file.") with tempfile.NamedTemporaryFile(mode='w+') as outf: try: outf.write(key) outf.flush() except IOError as e: module.fail_json(msg="Failed to write to temporary file %s: %s" % (outf.name, to_native(e))) sshkeygen_command = [sshkeygen, '-F', host, '-f', outf.name] rc, stdout, stderr = module.run_command(sshkeygen_command) if stdout == '': module.fail_json(msg="Host parameter does not match hashed host field in supplied key") def search_for_host_key(module, host, key, path, sshkeygen):
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
'''search_for_host_key(module,host,key,path,sshkeygen) -> (found,replace_or_add,found_line) Looks up host and keytype in the known_hosts file path; if it's there, looks to see if one of those entries matches key. Returns: found (Boolean): is host found in path? replace_or_add (Boolean): is the key in path different to that supplied by user? found_line (int or None): the line where a key of the same type was found if found=False, then replace is always False. sshkeygen is the path to ssh-keygen, found earlier with get_bin_path ''' if os.path.exists(path) is False: return False, False, None sshkeygen_command = [sshkeygen, '-F', host, '-f', path] rc, stdout, stderr = module.run_command(sshkeygen_command, check_rc=False) if stdout == '' and stderr == '' and (rc == 0 or rc == 1): return False, False, None if rc != 0: module.fail_json(msg="ssh-keygen failed (rc=%d, stdout='%s',stderr='%s')" % (rc, stdout, stderr)) if not key: return True, False, None lines = stdout.split('\n')
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
new_key = normalize_known_hosts_key(key) for lnum, l in enumerate(lines): if l == '': continue elif l[0] == '#': try: found_line = int(re.search(r'found: line (\d+)', l).group(1)) except IndexError: module.fail_json(msg="failed to parse output of ssh-keygen for line number: '%s'" % l) else: found_key = normalize_known_hosts_key(l) if new_key['host'][:3] == '|1|' and found_key['host'][:3] == '|1|': new_key['host'] = found_key['host'] if new_key == found_key: return True, False, found_line elif new_key['type'] == found_key['type']: return True, True, found_line return True, True, None def hash_host_key(host, key): hmac_key = os.urandom(20) hashed_host = hmac.new(hmac_key, to_bytes(host), hashlib.sha1).digest() parts = key.strip().split() i = 1 if parts[0][0] == '@' else 0 parts[i] = '|1|%s|%s' % (to_native(base64.b64encode(hmac_key)), to_native(base64.b64encode(hashed_host))) return ' '.join(parts) def normalize_known_hosts_key(key):
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
''' Transform a key, either taken from a known_host file or provided by the user, into a normalized form. The host part (which might include multiple hostnames or be hashed) gets replaced by the provided host. Also, any spurious information gets removed from the end (like the username@host tag usually present in hostkeys, but absent in known_hosts files) ''' key = key.strip() k = key.split() d = dict() if k[0][0] == '@': d['options'] = k[0] d['host'] = k[1] d['type'] = k[2] d['key'] = k[3] else: d['host'] = k[0] d['type'] = k[1] d['key'] = k[2] return d def compute_diff(path, found_line, replace_or_add, state, key):
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
diff = { 'before_header': path, 'after_header': path, 'before': '', 'after': '', } try: inf = open(path, "r") except IOError as e: if e.errno == errno.ENOENT: diff['before_header'] = '/dev/null' else: diff['before'] = inf.read() inf.close() lines = diff['before'].splitlines(1) if (replace_or_add or state == 'absent') and found_line is not None and 1 <= found_line <= len(lines): del lines[found_line - 1] if state == 'present' and (replace_or_add or found_line is None): lines.append(key) diff['after'] = ''.join(lines) return diff def main():
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
module = AnsibleModule( argument_spec=dict( name=dict(required=True, type='str', aliases=['host']), key=dict(required=False, type='str', no_log=False), path=dict(default="~/.ssh/known_hosts", type='path'), hash_host=dict(required=False, type='bool', default=False), state=dict(default='present', choices=['absent', 'present']), ), supports_check_mode=True ) results = enforce_state(module, module.params) module.exit_json(**results) if __name__ == '__main__': main()
closed
ansible/ansible
https://github.com/ansible/ansible
82,241
handler include_tasks fails if no `main.yaml` in role tasks in Ansible 2.15 - worked in 2.14
### Summary In Ansible 2.14.3, e.g. package available in Debian Bullseye, `include_tasks` in a handler within a role always found the task file from `tasks` in that role, if it existed. When I install the current version using pip (2.15.6 at time of writing) this stops working if `tasks/main.yaml` does not exist in the role - creating an empty `main.yaml` (e.g. `touch roles/role_name/tasks/main.yaml`) is sufficient for `import_tasks` in a handler to start working again. I have manually downgraded to 2.14.3 with pip and verified the same code works with 2.14.3 but not 2.15.6 on the same system, so this is not a difference with the OS package compared to the one pip installs and a bug introduced between those two versions. In my specific use case, I have a role that is designed to be used via several entry points and has no default `main.yaml`. This has been working fine but started erroring in version 2.15.6. It has taken quite a bit of testing to discover what was making it fail (and why other similar roles for which I used the same pattern but did happen to have a `main.yaml`, were still working). ### Issue Type Bug Report ### Component Name ansible.builtin.import_tasks ### Ansible Version ```console $ # Broken version $ ansible --version ansible [core 2.15.6] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True $ # Working version (after "pip install --upgrade ansible-core==2.14.3") $ ansible --version ansible [core 2.14.3] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CONFIG_FILE() = None ``` ### OS / Environment Debian 12.0 Ansible installed in Python 3 VirtualEnv with this `requirements.txt` however should be reproducible with just `ansible-core`: ``` ansible-core # dnspython is required for community.general.dig lookup plugin dnspython # hvac required for Hashicorp Vault hvac # netaddr required for ansible.utils.ipaddr filter netaddr # To manage Windows systems pywinrm[credssp] ``` ### Steps to Reproduce `site.yaml`: ```yaml --- - name: Test hosts: all gather_facts: false # Not needed for example tasks: - ansible.builtin.import_role: name: test_role # Custom entry point (no main.yaml required in test_role/tasks) tasks_from: entry_point.yaml ... ``` `roles/test_role/tasks/entry_point.yaml`: ```yaml --- # This is not necessary to reproduce the problem, just # illustrating include_tasks works here without `main.yaml`. - name: Include tasks works here ansible.builtin.include_tasks: included_tasks.yaml # Somehow trigger the role's handler - how is not important, # but running the handler is necessary to illustrate the problem. - name: Trigger handler ansible.builtin.debug: changed_when: true # Force handler to always be notified notify: Test handler ... ``` `roles/test_role/tasks/included_tasks.yaml`: ```yaml --- - name: Included task ansible.builtin.debug: msg="Included task" ... ``` `roles/test_role/handlers/main.yaml`: ```yaml --- - name: Test handler ansible.builtin.include_tasks: included_tasks.yaml ... ``` ### Expected Results When handler runs, `included_tasks` file is found in role's `tasks` folder (expected behaviour can be seen by running with Ansible 2.14.3 or if empty `main.yaml` has been added to `test_role/tasks`): ``` $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ### Actual Results ```console With Ansible 2.15.6, error that `included_tasks.yaml` does not exist - in this example, despite it being included successfully in another task list. It is unexpected that `include_tasks`, even when used from a handler, cannot find a tasks file in the the role's `tasks` directory (i.e. where all of a role's tasks live). This used to work fine (and still does if downgrade `ansible-core` to previous version): $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* fatal: [localhost]: FAILED! => {"reason": "Could not find or access '/tmp/test/included_tasks.yaml' on the Ansible Controller."} PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=3 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ``` Note that creating `roles/test_role/main.yaml` causes the same code to begin working with 2.15.6 as well as 2.14.3. Although `main.yaml` is the default entry point, I am not aware of any other Ansible functionality that breaks if it does not exist and only other entry points are used for a specific role, so I think this is a bug. ``` $ touch roles/test_role/tasks/main.yaml $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82241
https://github.com/ansible/ansible/pull/82248
a4b00793be46f703e32ee4c440f303d19d2c652d
d664f13b4a117b324f107b603e9b8e2bb9af50c5
2023-11-18T17:48:36Z
python
2023-11-22T16:42:51Z
lib/ansible/playbook/included_file.py
# # # # from __future__ import annotations import os from ansible import constants as C from ansible.errors import AnsibleError from ansible.executor.task_executor import remove_omit from ansible.module_utils.common.text.converters import to_text from ansible.playbook.handler import Handler from ansible.playbook.task_include import TaskInclude from ansible.playbook.role_include import IncludeRole from ansible.template import Templar from ansible.utils.display import Display display = Display() class IncludedFile:
closed
ansible/ansible
https://github.com/ansible/ansible
82,241
handler include_tasks fails if no `main.yaml` in role tasks in Ansible 2.15 - worked in 2.14
### Summary In Ansible 2.14.3, e.g. package available in Debian Bullseye, `include_tasks` in a handler within a role always found the task file from `tasks` in that role, if it existed. When I install the current version using pip (2.15.6 at time of writing) this stops working if `tasks/main.yaml` does not exist in the role - creating an empty `main.yaml` (e.g. `touch roles/role_name/tasks/main.yaml`) is sufficient for `import_tasks` in a handler to start working again. I have manually downgraded to 2.14.3 with pip and verified the same code works with 2.14.3 but not 2.15.6 on the same system, so this is not a difference with the OS package compared to the one pip installs and a bug introduced between those two versions. In my specific use case, I have a role that is designed to be used via several entry points and has no default `main.yaml`. This has been working fine but started erroring in version 2.15.6. It has taken quite a bit of testing to discover what was making it fail (and why other similar roles for which I used the same pattern but did happen to have a `main.yaml`, were still working). ### Issue Type Bug Report ### Component Name ansible.builtin.import_tasks ### Ansible Version ```console $ # Broken version $ ansible --version ansible [core 2.15.6] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True $ # Working version (after "pip install --upgrade ansible-core==2.14.3") $ ansible --version ansible [core 2.14.3] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CONFIG_FILE() = None ``` ### OS / Environment Debian 12.0 Ansible installed in Python 3 VirtualEnv with this `requirements.txt` however should be reproducible with just `ansible-core`: ``` ansible-core # dnspython is required for community.general.dig lookup plugin dnspython # hvac required for Hashicorp Vault hvac # netaddr required for ansible.utils.ipaddr filter netaddr # To manage Windows systems pywinrm[credssp] ``` ### Steps to Reproduce `site.yaml`: ```yaml --- - name: Test hosts: all gather_facts: false # Not needed for example tasks: - ansible.builtin.import_role: name: test_role # Custom entry point (no main.yaml required in test_role/tasks) tasks_from: entry_point.yaml ... ``` `roles/test_role/tasks/entry_point.yaml`: ```yaml --- # This is not necessary to reproduce the problem, just # illustrating include_tasks works here without `main.yaml`. - name: Include tasks works here ansible.builtin.include_tasks: included_tasks.yaml # Somehow trigger the role's handler - how is not important, # but running the handler is necessary to illustrate the problem. - name: Trigger handler ansible.builtin.debug: changed_when: true # Force handler to always be notified notify: Test handler ... ``` `roles/test_role/tasks/included_tasks.yaml`: ```yaml --- - name: Included task ansible.builtin.debug: msg="Included task" ... ``` `roles/test_role/handlers/main.yaml`: ```yaml --- - name: Test handler ansible.builtin.include_tasks: included_tasks.yaml ... ``` ### Expected Results When handler runs, `included_tasks` file is found in role's `tasks` folder (expected behaviour can be seen by running with Ansible 2.14.3 or if empty `main.yaml` has been added to `test_role/tasks`): ``` $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ### Actual Results ```console With Ansible 2.15.6, error that `included_tasks.yaml` does not exist - in this example, despite it being included successfully in another task list. It is unexpected that `include_tasks`, even when used from a handler, cannot find a tasks file in the the role's `tasks` directory (i.e. where all of a role's tasks live). This used to work fine (and still does if downgrade `ansible-core` to previous version): $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* fatal: [localhost]: FAILED! => {"reason": "Could not find or access '/tmp/test/included_tasks.yaml' on the Ansible Controller."} PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=3 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ``` Note that creating `roles/test_role/main.yaml` causes the same code to begin working with 2.15.6 as well as 2.14.3. Although `main.yaml` is the default entry point, I am not aware of any other Ansible functionality that breaks if it does not exist and only other entry points are used for a specific role, so I think this is a bug. ``` $ touch roles/test_role/tasks/main.yaml $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82241
https://github.com/ansible/ansible/pull/82248
a4b00793be46f703e32ee4c440f303d19d2c652d
d664f13b4a117b324f107b603e9b8e2bb9af50c5
2023-11-18T17:48:36Z
python
2023-11-22T16:42:51Z
lib/ansible/playbook/included_file.py
def __init__(self, filename, args, vars, task, is_role=False): self._filename = filename self._args = args self._vars = vars self._task = task self._hosts = [] self._is_role = is_role self._results = [] def add_host(self, host): if host not in self._hosts: self._hosts.append(host) return raise ValueError() def __eq__(self, other):
closed
ansible/ansible
https://github.com/ansible/ansible
82,241
handler include_tasks fails if no `main.yaml` in role tasks in Ansible 2.15 - worked in 2.14
### Summary In Ansible 2.14.3, e.g. package available in Debian Bullseye, `include_tasks` in a handler within a role always found the task file from `tasks` in that role, if it existed. When I install the current version using pip (2.15.6 at time of writing) this stops working if `tasks/main.yaml` does not exist in the role - creating an empty `main.yaml` (e.g. `touch roles/role_name/tasks/main.yaml`) is sufficient for `import_tasks` in a handler to start working again. I have manually downgraded to 2.14.3 with pip and verified the same code works with 2.14.3 but not 2.15.6 on the same system, so this is not a difference with the OS package compared to the one pip installs and a bug introduced between those two versions. In my specific use case, I have a role that is designed to be used via several entry points and has no default `main.yaml`. This has been working fine but started erroring in version 2.15.6. It has taken quite a bit of testing to discover what was making it fail (and why other similar roles for which I used the same pattern but did happen to have a `main.yaml`, were still working). ### Issue Type Bug Report ### Component Name ansible.builtin.import_tasks ### Ansible Version ```console $ # Broken version $ ansible --version ansible [core 2.15.6] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True $ # Working version (after "pip install --upgrade ansible-core==2.14.3") $ ansible --version ansible [core 2.14.3] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CONFIG_FILE() = None ``` ### OS / Environment Debian 12.0 Ansible installed in Python 3 VirtualEnv with this `requirements.txt` however should be reproducible with just `ansible-core`: ``` ansible-core # dnspython is required for community.general.dig lookup plugin dnspython # hvac required for Hashicorp Vault hvac # netaddr required for ansible.utils.ipaddr filter netaddr # To manage Windows systems pywinrm[credssp] ``` ### Steps to Reproduce `site.yaml`: ```yaml --- - name: Test hosts: all gather_facts: false # Not needed for example tasks: - ansible.builtin.import_role: name: test_role # Custom entry point (no main.yaml required in test_role/tasks) tasks_from: entry_point.yaml ... ``` `roles/test_role/tasks/entry_point.yaml`: ```yaml --- # This is not necessary to reproduce the problem, just # illustrating include_tasks works here without `main.yaml`. - name: Include tasks works here ansible.builtin.include_tasks: included_tasks.yaml # Somehow trigger the role's handler - how is not important, # but running the handler is necessary to illustrate the problem. - name: Trigger handler ansible.builtin.debug: changed_when: true # Force handler to always be notified notify: Test handler ... ``` `roles/test_role/tasks/included_tasks.yaml`: ```yaml --- - name: Included task ansible.builtin.debug: msg="Included task" ... ``` `roles/test_role/handlers/main.yaml`: ```yaml --- - name: Test handler ansible.builtin.include_tasks: included_tasks.yaml ... ``` ### Expected Results When handler runs, `included_tasks` file is found in role's `tasks` folder (expected behaviour can be seen by running with Ansible 2.14.3 or if empty `main.yaml` has been added to `test_role/tasks`): ``` $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ### Actual Results ```console With Ansible 2.15.6, error that `included_tasks.yaml` does not exist - in this example, despite it being included successfully in another task list. It is unexpected that `include_tasks`, even when used from a handler, cannot find a tasks file in the the role's `tasks` directory (i.e. where all of a role's tasks live). This used to work fine (and still does if downgrade `ansible-core` to previous version): $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* fatal: [localhost]: FAILED! => {"reason": "Could not find or access '/tmp/test/included_tasks.yaml' on the Ansible Controller."} PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=3 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ``` Note that creating `roles/test_role/main.yaml` causes the same code to begin working with 2.15.6 as well as 2.14.3. Although `main.yaml` is the default entry point, I am not aware of any other Ansible functionality that breaks if it does not exist and only other entry points are used for a specific role, so I think this is a bug. ``` $ touch roles/test_role/tasks/main.yaml $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82241
https://github.com/ansible/ansible/pull/82248
a4b00793be46f703e32ee4c440f303d19d2c652d
d664f13b4a117b324f107b603e9b8e2bb9af50c5
2023-11-18T17:48:36Z
python
2023-11-22T16:42:51Z
lib/ansible/playbook/included_file.py
return (other._filename == self._filename and other._args == self._args and other._vars == self._vars and other._task._uuid == self._task._uuid and other._task._parent._uuid == self._task._parent._uuid) def __repr__(self): return "%s (args=%s vars=%s): %s" % (self._filename, self._args, self._vars, self._hosts) @staticmethod def process_include_results(results, iterator, loader, variable_manager): included_files = [] task_vars_cache = {} for res in results: original_host = res._host original_task = res._task if original_task.action in C._ACTION_ALL_INCLUDES: if original_task.loop: if 'results' not in res._result: continue include_results = res._result['results'] else: include_results = [res._result] for include_result in include_results: if 'skipped' in include_result and include_result['skipped'] or 'failed' in include_result and include_result['failed']: continue cache_key = (iterator._play, original_host, original_task) try: task_vars = task_vars_cache[cache_key] except KeyError:
closed
ansible/ansible
https://github.com/ansible/ansible
82,241
handler include_tasks fails if no `main.yaml` in role tasks in Ansible 2.15 - worked in 2.14
### Summary In Ansible 2.14.3, e.g. package available in Debian Bullseye, `include_tasks` in a handler within a role always found the task file from `tasks` in that role, if it existed. When I install the current version using pip (2.15.6 at time of writing) this stops working if `tasks/main.yaml` does not exist in the role - creating an empty `main.yaml` (e.g. `touch roles/role_name/tasks/main.yaml`) is sufficient for `import_tasks` in a handler to start working again. I have manually downgraded to 2.14.3 with pip and verified the same code works with 2.14.3 but not 2.15.6 on the same system, so this is not a difference with the OS package compared to the one pip installs and a bug introduced between those two versions. In my specific use case, I have a role that is designed to be used via several entry points and has no default `main.yaml`. This has been working fine but started erroring in version 2.15.6. It has taken quite a bit of testing to discover what was making it fail (and why other similar roles for which I used the same pattern but did happen to have a `main.yaml`, were still working). ### Issue Type Bug Report ### Component Name ansible.builtin.import_tasks ### Ansible Version ```console $ # Broken version $ ansible --version ansible [core 2.15.6] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True $ # Working version (after "pip install --upgrade ansible-core==2.14.3") $ ansible --version ansible [core 2.14.3] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CONFIG_FILE() = None ``` ### OS / Environment Debian 12.0 Ansible installed in Python 3 VirtualEnv with this `requirements.txt` however should be reproducible with just `ansible-core`: ``` ansible-core # dnspython is required for community.general.dig lookup plugin dnspython # hvac required for Hashicorp Vault hvac # netaddr required for ansible.utils.ipaddr filter netaddr # To manage Windows systems pywinrm[credssp] ``` ### Steps to Reproduce `site.yaml`: ```yaml --- - name: Test hosts: all gather_facts: false # Not needed for example tasks: - ansible.builtin.import_role: name: test_role # Custom entry point (no main.yaml required in test_role/tasks) tasks_from: entry_point.yaml ... ``` `roles/test_role/tasks/entry_point.yaml`: ```yaml --- # This is not necessary to reproduce the problem, just # illustrating include_tasks works here without `main.yaml`. - name: Include tasks works here ansible.builtin.include_tasks: included_tasks.yaml # Somehow trigger the role's handler - how is not important, # but running the handler is necessary to illustrate the problem. - name: Trigger handler ansible.builtin.debug: changed_when: true # Force handler to always be notified notify: Test handler ... ``` `roles/test_role/tasks/included_tasks.yaml`: ```yaml --- - name: Included task ansible.builtin.debug: msg="Included task" ... ``` `roles/test_role/handlers/main.yaml`: ```yaml --- - name: Test handler ansible.builtin.include_tasks: included_tasks.yaml ... ``` ### Expected Results When handler runs, `included_tasks` file is found in role's `tasks` folder (expected behaviour can be seen by running with Ansible 2.14.3 or if empty `main.yaml` has been added to `test_role/tasks`): ``` $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ### Actual Results ```console With Ansible 2.15.6, error that `included_tasks.yaml` does not exist - in this example, despite it being included successfully in another task list. It is unexpected that `include_tasks`, even when used from a handler, cannot find a tasks file in the the role's `tasks` directory (i.e. where all of a role's tasks live). This used to work fine (and still does if downgrade `ansible-core` to previous version): $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* fatal: [localhost]: FAILED! => {"reason": "Could not find or access '/tmp/test/included_tasks.yaml' on the Ansible Controller."} PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=3 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ``` Note that creating `roles/test_role/main.yaml` causes the same code to begin working with 2.15.6 as well as 2.14.3. Although `main.yaml` is the default entry point, I am not aware of any other Ansible functionality that breaks if it does not exist and only other entry points are used for a specific role, so I think this is a bug. ``` $ touch roles/test_role/tasks/main.yaml $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82241
https://github.com/ansible/ansible/pull/82248
a4b00793be46f703e32ee4c440f303d19d2c652d
d664f13b4a117b324f107b603e9b8e2bb9af50c5
2023-11-18T17:48:36Z
python
2023-11-22T16:42:51Z
lib/ansible/playbook/included_file.py
task_vars = task_vars_cache[cache_key] = variable_manager.get_vars(play=iterator._play, host=original_host, task=original_task) include_args = include_result.get('include_args', dict()) special_vars = {} loop_var = include_result.get('ansible_loop_var', 'item') index_var = include_result.get('ansible_index_var') if loop_var in include_result: task_vars[loop_var] = special_vars[loop_var] = include_result[loop_var] if index_var and index_var in include_result: task_vars[index_var] = special_vars[index_var] = include_result[index_var] if '_ansible_item_label' in include_result: task_vars['_ansible_item_label'] = special_vars['_ansible_item_label'] = include_result['_ansible_item_label'] if 'ansible_loop' in include_result: task_vars['ansible_loop'] = special_vars['ansible_loop'] = include_result['ansible_loop'] if original_task.no_log and '_ansible_no_log' not in include_args: task_vars['_ansible_no_log'] = special_vars['_ansible_no_log'] = original_task.no_log task_vars['ansible_search_path'] = original_task.get_search_path() if loader.get_basedir() not in task_vars['ansible_search_path']: task_vars['ansible_search_path'].append(loader.get_basedir()) templar = Templar(loader=loader, variables=task_vars) if original_task.action in C._ACTION_INCLUDE_TASKS: include_file = None if original_task._parent: parent_include = original_task._parent cumulative_path = None while parent_include is not None:
closed
ansible/ansible
https://github.com/ansible/ansible
82,241
handler include_tasks fails if no `main.yaml` in role tasks in Ansible 2.15 - worked in 2.14
### Summary In Ansible 2.14.3, e.g. package available in Debian Bullseye, `include_tasks` in a handler within a role always found the task file from `tasks` in that role, if it existed. When I install the current version using pip (2.15.6 at time of writing) this stops working if `tasks/main.yaml` does not exist in the role - creating an empty `main.yaml` (e.g. `touch roles/role_name/tasks/main.yaml`) is sufficient for `import_tasks` in a handler to start working again. I have manually downgraded to 2.14.3 with pip and verified the same code works with 2.14.3 but not 2.15.6 on the same system, so this is not a difference with the OS package compared to the one pip installs and a bug introduced between those two versions. In my specific use case, I have a role that is designed to be used via several entry points and has no default `main.yaml`. This has been working fine but started erroring in version 2.15.6. It has taken quite a bit of testing to discover what was making it fail (and why other similar roles for which I used the same pattern but did happen to have a `main.yaml`, were still working). ### Issue Type Bug Report ### Component Name ansible.builtin.import_tasks ### Ansible Version ```console $ # Broken version $ ansible --version ansible [core 2.15.6] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True $ # Working version (after "pip install --upgrade ansible-core==2.14.3") $ ansible --version ansible [core 2.14.3] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CONFIG_FILE() = None ``` ### OS / Environment Debian 12.0 Ansible installed in Python 3 VirtualEnv with this `requirements.txt` however should be reproducible with just `ansible-core`: ``` ansible-core # dnspython is required for community.general.dig lookup plugin dnspython # hvac required for Hashicorp Vault hvac # netaddr required for ansible.utils.ipaddr filter netaddr # To manage Windows systems pywinrm[credssp] ``` ### Steps to Reproduce `site.yaml`: ```yaml --- - name: Test hosts: all gather_facts: false # Not needed for example tasks: - ansible.builtin.import_role: name: test_role # Custom entry point (no main.yaml required in test_role/tasks) tasks_from: entry_point.yaml ... ``` `roles/test_role/tasks/entry_point.yaml`: ```yaml --- # This is not necessary to reproduce the problem, just # illustrating include_tasks works here without `main.yaml`. - name: Include tasks works here ansible.builtin.include_tasks: included_tasks.yaml # Somehow trigger the role's handler - how is not important, # but running the handler is necessary to illustrate the problem. - name: Trigger handler ansible.builtin.debug: changed_when: true # Force handler to always be notified notify: Test handler ... ``` `roles/test_role/tasks/included_tasks.yaml`: ```yaml --- - name: Included task ansible.builtin.debug: msg="Included task" ... ``` `roles/test_role/handlers/main.yaml`: ```yaml --- - name: Test handler ansible.builtin.include_tasks: included_tasks.yaml ... ``` ### Expected Results When handler runs, `included_tasks` file is found in role's `tasks` folder (expected behaviour can be seen by running with Ansible 2.14.3 or if empty `main.yaml` has been added to `test_role/tasks`): ``` $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ### Actual Results ```console With Ansible 2.15.6, error that `included_tasks.yaml` does not exist - in this example, despite it being included successfully in another task list. It is unexpected that `include_tasks`, even when used from a handler, cannot find a tasks file in the the role's `tasks` directory (i.e. where all of a role's tasks live). This used to work fine (and still does if downgrade `ansible-core` to previous version): $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* fatal: [localhost]: FAILED! => {"reason": "Could not find or access '/tmp/test/included_tasks.yaml' on the Ansible Controller."} PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=3 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ``` Note that creating `roles/test_role/main.yaml` causes the same code to begin working with 2.15.6 as well as 2.14.3. Although `main.yaml` is the default entry point, I am not aware of any other Ansible functionality that breaks if it does not exist and only other entry points are used for a specific role, so I think this is a bug. ``` $ touch roles/test_role/tasks/main.yaml $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82241
https://github.com/ansible/ansible/pull/82248
a4b00793be46f703e32ee4c440f303d19d2c652d
d664f13b4a117b324f107b603e9b8e2bb9af50c5
2023-11-18T17:48:36Z
python
2023-11-22T16:42:51Z
lib/ansible/playbook/included_file.py
if not isinstance(parent_include, TaskInclude): parent_include = parent_include._parent continue if isinstance(parent_include, IncludeRole): parent_include_dir = parent_include._role_path else: try: parent_include_dir = os.path.dirname(templar.template(parent_include.args.get('_raw_params'))) except AnsibleError as e: parent_include_dir = '' display.warning( 'Templating the path of the parent %s failed. The path to the ' 'included file may not be found. ' 'The error was: %s.' % (original_task.action, to_text(e)) ) if cumulative_path is not None and not os.path.isabs(cumulative_path): cumulative_path = os.path.join(parent_include_dir, cumulative_path) else: cumulative_path = parent_include_dir include_target = templar.template(include_result['include']) if original_task._role: dirname = 'handlers' if isinstance(original_task, Handler) else 'tasks' new_basedir = os.path.join(original_task._role._role_path, dirname, cumulative_path) candidates = [ loader.path_dwim_relative(original_task._role._role_path, dirname, include_target), loader.path_dwim_relative(new_basedir, dirname, include_target) ] for include_file in candidates: try:
closed
ansible/ansible
https://github.com/ansible/ansible
82,241
handler include_tasks fails if no `main.yaml` in role tasks in Ansible 2.15 - worked in 2.14
### Summary In Ansible 2.14.3, e.g. package available in Debian Bullseye, `include_tasks` in a handler within a role always found the task file from `tasks` in that role, if it existed. When I install the current version using pip (2.15.6 at time of writing) this stops working if `tasks/main.yaml` does not exist in the role - creating an empty `main.yaml` (e.g. `touch roles/role_name/tasks/main.yaml`) is sufficient for `import_tasks` in a handler to start working again. I have manually downgraded to 2.14.3 with pip and verified the same code works with 2.14.3 but not 2.15.6 on the same system, so this is not a difference with the OS package compared to the one pip installs and a bug introduced between those two versions. In my specific use case, I have a role that is designed to be used via several entry points and has no default `main.yaml`. This has been working fine but started erroring in version 2.15.6. It has taken quite a bit of testing to discover what was making it fail (and why other similar roles for which I used the same pattern but did happen to have a `main.yaml`, were still working). ### Issue Type Bug Report ### Component Name ansible.builtin.import_tasks ### Ansible Version ```console $ # Broken version $ ansible --version ansible [core 2.15.6] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True $ # Working version (after "pip install --upgrade ansible-core==2.14.3") $ ansible --version ansible [core 2.14.3] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CONFIG_FILE() = None ``` ### OS / Environment Debian 12.0 Ansible installed in Python 3 VirtualEnv with this `requirements.txt` however should be reproducible with just `ansible-core`: ``` ansible-core # dnspython is required for community.general.dig lookup plugin dnspython # hvac required for Hashicorp Vault hvac # netaddr required for ansible.utils.ipaddr filter netaddr # To manage Windows systems pywinrm[credssp] ``` ### Steps to Reproduce `site.yaml`: ```yaml --- - name: Test hosts: all gather_facts: false # Not needed for example tasks: - ansible.builtin.import_role: name: test_role # Custom entry point (no main.yaml required in test_role/tasks) tasks_from: entry_point.yaml ... ``` `roles/test_role/tasks/entry_point.yaml`: ```yaml --- # This is not necessary to reproduce the problem, just # illustrating include_tasks works here without `main.yaml`. - name: Include tasks works here ansible.builtin.include_tasks: included_tasks.yaml # Somehow trigger the role's handler - how is not important, # but running the handler is necessary to illustrate the problem. - name: Trigger handler ansible.builtin.debug: changed_when: true # Force handler to always be notified notify: Test handler ... ``` `roles/test_role/tasks/included_tasks.yaml`: ```yaml --- - name: Included task ansible.builtin.debug: msg="Included task" ... ``` `roles/test_role/handlers/main.yaml`: ```yaml --- - name: Test handler ansible.builtin.include_tasks: included_tasks.yaml ... ``` ### Expected Results When handler runs, `included_tasks` file is found in role's `tasks` folder (expected behaviour can be seen by running with Ansible 2.14.3 or if empty `main.yaml` has been added to `test_role/tasks`): ``` $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ### Actual Results ```console With Ansible 2.15.6, error that `included_tasks.yaml` does not exist - in this example, despite it being included successfully in another task list. It is unexpected that `include_tasks`, even when used from a handler, cannot find a tasks file in the the role's `tasks` directory (i.e. where all of a role's tasks live). This used to work fine (and still does if downgrade `ansible-core` to previous version): $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* fatal: [localhost]: FAILED! => {"reason": "Could not find or access '/tmp/test/included_tasks.yaml' on the Ansible Controller."} PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=3 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ``` Note that creating `roles/test_role/main.yaml` causes the same code to begin working with 2.15.6 as well as 2.14.3. Although `main.yaml` is the default entry point, I am not aware of any other Ansible functionality that breaks if it does not exist and only other entry points are used for a specific role, so I think this is a bug. ``` $ touch roles/test_role/tasks/main.yaml $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82241
https://github.com/ansible/ansible/pull/82248
a4b00793be46f703e32ee4c440f303d19d2c652d
d664f13b4a117b324f107b603e9b8e2bb9af50c5
2023-11-18T17:48:36Z
python
2023-11-22T16:42:51Z
lib/ansible/playbook/included_file.py
os.stat(include_file) break except OSError: pass else: include_file = loader.path_dwim_relative(loader.get_basedir(), cumulative_path, include_target) if os.path.exists(include_file): break else: parent_include = parent_include._parent if include_file is None: if original_task._role: include_target = templar.template(include_result['include']) include_file = loader.path_dwim_relative( original_task._role._role_path, 'handlers' if isinstance(original_task, Handler) else 'tasks', include_target, is_role=True) else: include_file = loader.path_dwim(include_result['include']) include_file = templar.template(include_file) inc_file = IncludedFile(include_file, include_args, special_vars, original_task) else: role_name = include_args.pop('name', include_args.pop('role', None)) if role_name is not None: role_name = templar.template(role_name) new_task = original_task.copy() new_task.post_validate(templar=templar)
closed
ansible/ansible
https://github.com/ansible/ansible
82,241
handler include_tasks fails if no `main.yaml` in role tasks in Ansible 2.15 - worked in 2.14
### Summary In Ansible 2.14.3, e.g. package available in Debian Bullseye, `include_tasks` in a handler within a role always found the task file from `tasks` in that role, if it existed. When I install the current version using pip (2.15.6 at time of writing) this stops working if `tasks/main.yaml` does not exist in the role - creating an empty `main.yaml` (e.g. `touch roles/role_name/tasks/main.yaml`) is sufficient for `import_tasks` in a handler to start working again. I have manually downgraded to 2.14.3 with pip and verified the same code works with 2.14.3 but not 2.15.6 on the same system, so this is not a difference with the OS package compared to the one pip installs and a bug introduced between those two versions. In my specific use case, I have a role that is designed to be used via several entry points and has no default `main.yaml`. This has been working fine but started erroring in version 2.15.6. It has taken quite a bit of testing to discover what was making it fail (and why other similar roles for which I used the same pattern but did happen to have a `main.yaml`, were still working). ### Issue Type Bug Report ### Component Name ansible.builtin.import_tasks ### Ansible Version ```console $ # Broken version $ ansible --version ansible [core 2.15.6] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True $ # Working version (after "pip install --upgrade ansible-core==2.14.3") $ ansible --version ansible [core 2.14.3] config file = /home/laurence/Projects/ansible-home/ansible.cfg configured module search path = ['/home/laurence/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/laurence/venvs/ansible/lib/python3.9/site-packages/ansible ansible collection location = /home/laurence/.ansible/collections:/usr/share/ansible/collections executable location = /home/laurence/venvs/ansible/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/home/laurence/venvs/ansible/bin/python) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CONFIG_FILE() = None ``` ### OS / Environment Debian 12.0 Ansible installed in Python 3 VirtualEnv with this `requirements.txt` however should be reproducible with just `ansible-core`: ``` ansible-core # dnspython is required for community.general.dig lookup plugin dnspython # hvac required for Hashicorp Vault hvac # netaddr required for ansible.utils.ipaddr filter netaddr # To manage Windows systems pywinrm[credssp] ``` ### Steps to Reproduce `site.yaml`: ```yaml --- - name: Test hosts: all gather_facts: false # Not needed for example tasks: - ansible.builtin.import_role: name: test_role # Custom entry point (no main.yaml required in test_role/tasks) tasks_from: entry_point.yaml ... ``` `roles/test_role/tasks/entry_point.yaml`: ```yaml --- # This is not necessary to reproduce the problem, just # illustrating include_tasks works here without `main.yaml`. - name: Include tasks works here ansible.builtin.include_tasks: included_tasks.yaml # Somehow trigger the role's handler - how is not important, # but running the handler is necessary to illustrate the problem. - name: Trigger handler ansible.builtin.debug: changed_when: true # Force handler to always be notified notify: Test handler ... ``` `roles/test_role/tasks/included_tasks.yaml`: ```yaml --- - name: Included task ansible.builtin.debug: msg="Included task" ... ``` `roles/test_role/handlers/main.yaml`: ```yaml --- - name: Test handler ansible.builtin.include_tasks: included_tasks.yaml ... ``` ### Expected Results When handler runs, `included_tasks` file is found in role's `tasks` folder (expected behaviour can be seen by running with Ansible 2.14.3 or if empty `main.yaml` has been added to `test_role/tasks`): ``` $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ### Actual Results ```console With Ansible 2.15.6, error that `included_tasks.yaml` does not exist - in this example, despite it being included successfully in another task list. It is unexpected that `include_tasks`, even when used from a handler, cannot find a tasks file in the the role's `tasks` directory (i.e. where all of a role's tasks live). This used to work fine (and still does if downgrade `ansible-core` to previous version): $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* fatal: [localhost]: FAILED! => {"reason": "Could not find or access '/tmp/test/included_tasks.yaml' on the Ansible Controller."} PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=3 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ``` Note that creating `roles/test_role/main.yaml` causes the same code to begin working with 2.15.6 as well as 2.14.3. Although `main.yaml` is the default entry point, I am not aware of any other Ansible functionality that breaks if it does not exist and only other entry points are used for a specific role, so I think this is a bug. ``` $ touch roles/test_role/tasks/main.yaml $ ansible-playbook -i localhost, site.yaml PLAY [Test] ******************************************************************************************************************************************************************************************************************** TASK [test_role : Include tasks works here] ************************************************************************************************************************************************************************************ included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost TASK [test_role : Included task] *********************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": "Included task" } TASK [test_role : Trigger handler] ********************************************************************************************************************************************************************************************* changed: [localhost] => { "msg": "Hello world!" } RUNNING HANDLER [test_role : Test handler] ************************************************************************************************************************************************************************************* included: /tmp/test/roles/test_role/tasks/included_tasks.yaml for localhost RUNNING HANDLER [test_role : Included task] ************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "Included task" } PLAY RECAP ********************************************************************************************************************************************************************************************************************* localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82241
https://github.com/ansible/ansible/pull/82248
a4b00793be46f703e32ee4c440f303d19d2c652d
d664f13b4a117b324f107b603e9b8e2bb9af50c5
2023-11-18T17:48:36Z
python
2023-11-22T16:42:51Z
lib/ansible/playbook/included_file.py
new_task._role_name = role_name for from_arg in new_task.FROM_ARGS: if from_arg in include_args: from_key = from_arg.removesuffix('_from') new_task._from_files[from_key] = templar.template(include_args.pop(from_arg)) omit_token = task_vars.get('omit') if omit_token: new_task._from_files = remove_omit(new_task._from_files, omit_token) inc_file = IncludedFile(role_name, include_args, special_vars, new_task, is_role=True) idx = 0 orig_inc_file = inc_file while 1: try: pos = included_files[idx:].index(orig_inc_file) inc_file = included_files[idx + pos] except ValueError: included_files.append(orig_inc_file) inc_file = orig_inc_file try: inc_file.add_host(original_host) inc_file._results.append(res) except ValueError: idx += pos + 1 else: break return included_files
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
from __future__ import annotations DOCUMENTATION = r''' module: user version_added: "0.2" short_description: Manage user accounts description: - Manage user accounts and user attributes. - For Windows targets, use the M(ansible.windows.win_user) module instead. options: name: description: - Name of the user to create, remove or modify.
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
type: str required: true aliases: [ user ] uid: description: - Optionally sets the I(UID) of the user. type: int comment: description: - Optionally sets the description (aka I(GECOS)) of user account. - On macOS, this defaults to the O(name) option. type: str hidden: description: - macOS only, optionally hide the user from the login window and system preferences. - The default will be V(true) if the O(system) option is used. type: bool version_added: "2.6" non_unique: description: - Optionally when used with the -u option, this option allows to change the user ID to a non-unique value. type: bool default: no version_added: "1.1" seuser: description: - Optionally sets the seuser type (user_u) on selinux enabled systems. type: str version_added: "2.1" group:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
description: - Optionally sets the user's primary group (takes a group name). - On macOS, this defaults to V('staff') type: str groups: description: - A list of supplementary groups which the user is also a member of. - By default, the user is removed from all other groups. Configure O(append) to modify this. - When set to an empty string V(''), the user is removed from all groups except the primary group. - Before Ansible 2.3, the only input format allowed was a comma separated string. type: list elements: str append: description: - If V(true), add the user to the groups specified in O(groups). - If V(false), user will only be added to the groups specified in O(groups), removing them from all other groups. type: bool default: no shell: description: - Optionally set the user's shell. - On macOS, before Ansible 2.5, the default shell for non-system users was V(/usr/bin/false). Since Ansible 2.5, the default shell for non-system users on macOS is V(/bin/bash). - On other operating systems, the default shell is determined by the underlying tool invoked by this module. See Notes for a per platform list of invoked tools. type: str home: description:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
- Optionally set the user's home directory. type: path skeleton: description: - Optionally set a home skeleton directory. - Requires O(create_home) option! type: str version_added: "2.0" password: description: - If provided, set the user's password to the provided encrypted hash (Linux) or plain text password (macOS). - B(Linux/Unix/POSIX:) Enter the hashed password as the value. - See L(FAQ entry,https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module) for details on various ways to generate the hash of a password. - To create an account with a locked/disabled password on Linux systems, set this to V('!') or V('*'). - To create an account with a locked/disabled password on OpenBSD, set this to V('*************'). - B(OS X/macOS:) Enter the cleartext password as the value. Be sure to take relevant security precautions. - On macOS, the password specified in the C(password) option will always be set, regardless of whether the user account already exists or not. - When the password is passed as an argument, the C(user) module will always return changed to C(true) for macOS systems. Since macOS no longer provides access to the hashed passwords directly. type: str state: description: - Whether the account should exist or not, taking action if the state is different from what is stated. - See this L(FAQ entry,https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#running-on-macos-as-a-target) for additional requirements when removing users on macOS systems. type: str choices: [ absent, present ] default: present create_home:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
description: - Unless set to V(false), a home directory will be made for the user when the account is created or if the home directory does not exist. - Changed from O(createhome) to O(create_home) in Ansible 2.5. type: bool default: yes aliases: [ createhome ] move_home: description: - "If set to V(true) when used with O(home), attempt to move the user's old home directory to the specified directory if it isn't there already and the old home exists." type: bool default: no system: description: - When creating an account O(state=present), setting this to V(true) makes the user a system account. - This setting cannot be changed on existing users. type: bool default: no force: description: - This only affects O(state=absent), it forces removal of the user and associated directories on supported platforms. - The behavior is the same as C(userdel --force), check the man page for C(userdel) on your system for details and support. - When used with O(generate_ssh_key=yes) this forces an existing key to be overwritten. type: bool default: no remove: description: - This only affects O(state=absent), it attempts to remove directories associated with the user. - The behavior is the same as C(userdel --remove), check the man page for details and support.
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
type: bool default: no login_class: description: - Optionally sets the user's login class, a feature of most BSD OSs. type: str generate_ssh_key: description: - Whether to generate a SSH key for the user in question. - This will B(not) overwrite an existing SSH key unless used with O(force=yes). type: bool default: no version_added: "0.9" ssh_key_bits: description: - Optionally specify number of bits in SSH key to create. - The default value depends on ssh-keygen. type: int version_added: "0.9" ssh_key_type: description: - Optionally specify the type of SSH key to generate. - Available SSH key types will depend on implementation present on target host. type: str default: rsa version_added: "0.9" ssh_key_file: description: - Optionally specify the SSH key filename.
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
- If this is a relative filename then it will be relative to the user's home directory. - This parameter defaults to V(.ssh/id_rsa). type: path version_added: "0.9" ssh_key_comment: description: - Optionally define the comment for the SSH key. type: str default: ansible-generated on $HOSTNAME version_added: "0.9" ssh_key_passphrase: description: - Set a passphrase for the SSH key. - If no passphrase is provided, the SSH key will default to having no passphrase. type: str version_added: "0.9" update_password: description: - V(always) will update passwords if they differ. - V(on_create) will only set the password for newly created users. type: str choices: [ always, on_create ] default: always version_added: "1.3" expires: description: - An expiry time for the user in epoch, it will be ignored on platforms that do not support this. - Currently supported on GNU/Linux, FreeBSD, and DragonFlyBSD. - Since Ansible 2.6 you can remove the expiry time by specifying a negative value. Currently supported on GNU/Linux and FreeBSD.
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
type: float version_added: "1.9" password_lock: description: - Lock the password (C(usermod -L), C(usermod -U), C(pw lock)). - Implementation differs by platform. This option does not always mean the user cannot login using other methods. - This option does not disable the user, only lock the password. - This must be set to V(False) in order to unlock a currently locked password. The absence of this parameter will not unlock a password. - Currently supported on Linux, FreeBSD, DragonFlyBSD, NetBSD, OpenBSD. type: bool version_added: "2.6" local: description: - Forces the use of "local" command alternatives on platforms that implement it. - This is useful in environments that use centralized authentication when you want to manipulate the local users (in other words, it uses C(luseradd) instead of C(useradd)). - This will check C(/etc/passwd) for an existing account before invoking commands. If the local account database exists somewhere other than C(/etc/passwd), this setting will not work properly. - This requires that the above commands as well as C(/etc/passwd) must exist on the target host, otherwise it will be a fatal error. type: bool default: no version_added: "2.4" profile: description: - Sets the profile of the user. - Can set multiple profiles using comma separation. - To delete all the profiles, use O(profile=''). - Currently supported on Illumos/Solaris. Does nothing when used with other platforms. type: str version_added: "2.8"
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
authorization: description: - Sets the authorization of the user. - Can set multiple authorizations using comma separation. - To delete all authorizations, use O(authorization=''). - Currently supported on Illumos/Solaris. Does nothing when used with other platforms. type: str version_added: "2.8" role: description: - Sets the role of the user. - Can set multiple roles using comma separation. - To delete all roles, use O(role=''). - Currently supported on Illumos/Solaris. Does nothing when used with other platforms. type: str version_added: "2.8" password_expire_max: description: - Maximum number of days between password change. - Supported on Linux only. type: int version_added: "2.11" password_expire_min: description: - Minimum number of days between password change. - Supported on Linux only. type: int version_added: "2.11" password_expire_warn: description:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
- Number of days of warning before password expires. - Supported on Linux only. type: int version_added: "2.16" umask: description: - Sets the umask of the user. - Currently supported on Linux. Does nothing when used with other platforms. - Requires O(local) is omitted or V(False). type: str version_added: "2.12" extends_documentation_fragment: action_common_attributes attributes: check_mode: support: full diff_mode: support: none platform: platforms: posix notes: - There are specific requirements per platform on user management utilities. However they generally come pre-installed with the system and Ansible will require they are present at runtime. If they are not, a descriptive error message will be shown. - On SunOS platforms, the shadow file is backed up automatically since this module edits it directly. On other platforms, the shadow file is backed up by the underlying tools used by this module. - On macOS, this module uses C(dscl) to create, modify, and delete accounts. C(dseditgroup) is used to modify group membership. Accounts are hidden from the login window by modifying C(/Library/Preferences/com.apple.loginwindow.plist). - On FreeBSD, this module uses C(pw useradd) and C(chpass) to create, C(pw usermod) and C(chpass) to modify, C(pw userdel) remove, C(pw lock) to lock, and C(pw unlock) to unlock accounts.
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
- On all other platforms, this module uses C(useradd) to create, C(usermod) to modify, and C(userdel) to remove accounts. seealso: - module: ansible.posix.authorized_key - module: ansible.builtin.group - module: ansible.windows.win_user author: - Stephen Fromm (@sfromm) ''' EXAMPLES = r''' - name: Add the user 'johnd' with a specific uid and a primary group of 'admin' ansible.builtin.user: name: johnd comment: John Doe uid: 1040 group: admin - name: Create a user 'johnd' with a home directory ansible.builtin.user: name: johnd create_home: yes - name: Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' to the user's groups ansible.builtin.user: name: james shell: /bin/bash groups: admins,developers append: yes - name: Remove the user 'johnd' ansible.builtin.user: name: johnd state: absent
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
remove: yes - name: Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa ansible.builtin.user: name: jsmith generate_ssh_key: yes ssh_key_bits: 2048 ssh_key_file: .ssh/id_rsa - name: Added a consultant whose account you want to expire ansible.builtin.user: name: james18 shell: /bin/zsh groups: developers expires: 1422403387 - name: Starting at Ansible 2.6, modify user, remove expiry time ansible.builtin.user: name: james18 expires: -1 - name: Set maximum expiration date for password ansible.builtin.user: name: ram19 password_expire_max: 10 - name: Set minimum expiration date for password ansible.builtin.user: name: pushkar15 password_expire_min: 5 - name: Set number of warning days for password expiration ansible.builtin.user: name: jane157 password_expire_warn: 30 '''
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
RETURN = r''' append: description: Whether or not to append the user to groups. returned: When O(state) is V(present) and the user exists type: bool sample: True comment: description: Comment section from passwd file, usually the user name. returned: When user exists type: str sample: Agent Smith create_home: description: Whether or not to create the home directory. returned: When user does not exist and not check mode type: bool sample: True force: description: Whether or not a user account was forcibly deleted. returned: When O(state) is V(absent) and user exists type: bool sample: False group: description: Primary user group ID returned: When user exists type: int sample: 1001 groups: description: List of groups of which the user is a member. returned: When O(groups) is not empty and O(state) is V(present) type: str
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
sample: 'chrony,apache' home: description: "Path to user's home directory." returned: When O(state) is V(present) type: str sample: '/home/asmith' move_home: description: Whether or not to move an existing home directory. returned: When O(state) is V(present) and user exists type: bool sample: False name: description: User account name. returned: always type: str sample: asmith password: description: Masked value of the password. returned: When O(state) is V(present) and O(password) is not empty type: str sample: 'NOT_LOGGING_PASSWORD' remove: description: Whether or not to remove the user account. returned: When O(state) is V(absent) and user exists type: bool sample: True shell: description: User login shell. returned: When O(state) is V(present) type: str
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
sample: '/bin/bash' ssh_fingerprint: description: Fingerprint of generated SSH key. returned: When O(generate_ssh_key) is V(True) type: str sample: '2048 SHA256:aYNHYcyVm87Igh0IMEDMbvW0QDlRQfE0aJugp684ko8 ansible-generated on host (RSA)' ssh_key_file: description: Path to generated SSH private key file. returned: When O(generate_ssh_key) is V(True) type: str sample: /home/asmith/.ssh/id_rsa ssh_public_key: description: Generated SSH public key file. returned: When O(generate_ssh_key) is V(True) type: str sample: > 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC95opt4SPEC06tOYsJQJIuN23BbLMGmYo8ysVZQc4h2DZE9ugbjWWGS1/pweUGjVstgzMkBEeBCByaEf/RJKNecKRPeGd2Bw9DCj/bn5Z6rGfNENKBmo 618mUJBvdlEgea96QGjOwSB7/gmonduC7gsWDMNcOdSE3wJMTim4lddiBx4RgC9yXsJ6Tkz9BHD73MXPpT5ETnse+A3fw3IGVSjaueVnlUyUmOBf7fzmZbhlFVXf2Zi2rFTXqvbdGHKkzpw1U8eB8xFPP7y d5u1u0e6Acju/8aZ/l17IDFiLke5IzlqIMRTEbDwLNeO84YQKWTm9fODHzhYe0yvxqLiK07 ansible-generated on host' stderr: description: Standard error from running commands. returned: When stderr is returned by a command that is run type: str sample: Group wheels does not exist stdout: description: Standard output from running commands. returned: When standard output is returned by the command that is run type: str sample: system:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
description: Whether or not the account is a system account. returned: When O(system) is passed to the module and the account does not exist type: bool sample: True uid: description: User ID of the user account. returned: When O(uid) is passed to the module type: int sample: 1044 ''' import ctypes.util import grp import calendar import os import re import pty import pwd import select import shutil import socket import subprocess import time import math from ansible.module_utils import distro from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.locale import get_best_parsable_locale from ansible.module_utils.common.sys_info import get_platform_subclass import ansible.module_utils.compat.typing as t class StructSpwdType(ctypes.Structure):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
_fields_ = [ ('sp_namp', ctypes.c_char_p), ('sp_pwdp', ctypes.c_char_p), ('sp_lstchg', ctypes.c_long), ('sp_min', ctypes.c_long), ('sp_max', ctypes.c_long), ('sp_warn', ctypes.c_long), ('sp_inact', ctypes.c_long), ('sp_expire', ctypes.c_long), ('sp_flag', ctypes.c_ulong), ] try: _LIBC = ctypes.cdll.LoadLibrary( t.cast( str, ctypes.util.find_library('c') ) ) _LIBC.getspnam.argtypes = (ctypes.c_char_p,) _LIBC.getspnam.restype = ctypes.POINTER(StructSpwdType) HAVE_SPWD = True except AttributeError: HAVE_SPWD = False _HASH_RE = re.compile(r'[^a-zA-Z0-9./=]') def getspnam(b_name): return _LIBC.getspnam(b_name).contents class User(object):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
""" This is a generic User manipulation class that is subclassed based on platform. A subclass may wish to override the following action methods:- - create_user() - remove_user() - modify_user() - ssh_key_gen() - ssh_key_fingerprint() - user_exists() All subclasses MUST define platform and distribution (which may be None). """ platform = 'Generic' distribution = None PASSWORDFILE = '/etc/passwd' SHADOWFILE = '/etc/shadow' SHADOWFILE_EXPIRE_INDEX = 7 LOGIN_DEFS = '/etc/login.defs' DATE_FORMAT = '%Y-%m-%d' def __new__(cls, *args, **kwargs):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
new_cls = get_platform_subclass(User) return super(cls, new_cls).__new__(new_cls) def __init__(self, module): self.module = module self.state = module.params['state'] self.name = module.params['name'] self.uid = module.params['uid'] self.hidden = module.params['hidden'] self.non_unique = module.params['non_unique'] self.seuser = module.params['seuser'] self.group = module.params['group'] self.comment = module.params['comment'] self.shell = module.params['shell'] self.password = module.params['password'] self.force = module.params['force'] self.remove = module.params['remove'] self.create_home = module.params['create_home'] self.move_home = module.params['move_home'] self.skeleton = module.params['skeleton'] self.system = module.params['system'] self.login_class = module.params['login_class'] self.append = module.params['append'] self.sshkeygen = module.params['generate_ssh_key'] self.ssh_bits = module.params['ssh_key_bits'] self.ssh_type = module.params['ssh_key_type'] self.ssh_comment = module.params['ssh_key_comment'] self.ssh_passphrase = module.params['ssh_key_passphrase'] self.update_password = module.params['update_password'] self.home = module.params['home']
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
self.expires = None self.password_lock = module.params['password_lock'] self.groups = None self.local = module.params['local'] self.profile = module.params['profile'] self.authorization = module.params['authorization'] self.role = module.params['role'] self.password_expire_max = module.params['password_expire_max'] self.password_expire_min = module.params['password_expire_min'] self.password_expire_warn = module.params['password_expire_warn'] self.umask = module.params['umask'] if self.umask is not None and self.local: module.fail_json(msg="'umask' can not be used with 'local'") if module.params['groups'] is not None: self.groups = ','.join(module.params['groups']) if module.params['expires'] is not None: try: self.expires = time.gmtime(module.params['expires']) except Exception as e: module.fail_json(msg="Invalid value for 'expires' %s: %s" % (self.expires, to_native(e))) if module.params['ssh_key_file'] is not None: self.ssh_file = module.params['ssh_key_file'] else: self.ssh_file = os.path.join('.ssh', 'id_%s' % self.ssh_type) if self.groups is None and self.append: module.warn("'append' is set, but no 'groups' are specified. Use 'groups' for appending new groups." "This will change to an error in Ansible 2.14.") def check_password_encrypted(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.module.params['password'] and self.platform != 'Darwin': maybe_invalid = False if self.module.params['password'] in set(['*', '!', '*************']): maybe_invalid = False else: if any(char in self.module.params['password'] for char in ':*!'): maybe_invalid = True if '$' not in self.module.params['password']: maybe_invalid = True else: fields = self.module.params['password'].split("$") if len(fields) >= 3: if bool(_HASH_RE.search(fields[-1])): maybe_invalid = True if fields[1] == '1' and len(fields[-1]) != 22: maybe_invalid = True if fields[1] == '5' and len(fields[-1]) != 43: maybe_invalid = True if fields[1] == '6' and len(fields[-1]) != 86: maybe_invalid = True if fields[1] == 'y' and len(fields[-1]) != 43:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
maybe_invalid = True else: maybe_invalid = True if maybe_invalid: self.module.warn("The input password appears not to have been hashed. " "The 'password' argument must be encrypted for this module to work properly.") def execute_command(self, cmd, use_unsafe_shell=False, data=None, obey_checkmode=True): if self.module.check_mode and obey_checkmode: self.module.debug('In check mode, would have run: "%s"' % cmd) return (0, '', '') else: cmd = [str(x) for x in cmd] return self.module.run_command(cmd, use_unsafe_shell=use_unsafe_shell, data=data) def backup_shadow(self): if not self.module.check_mode and self.SHADOWFILE: return self.module.backup_local(self.SHADOWFILE) def remove_user_userdel(self): if self.local: command_name = 'luserdel' else: command_name = 'userdel' cmd = [self.module.get_bin_path(command_name, True)] if self.force and not self.local: cmd.append('-f') if self.remove: cmd.append('-r') cmd.append(self.name) return self.execute_command(cmd) def create_user_useradd(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.local: command_name = 'luseradd' lgroupmod_cmd = self.module.get_bin_path('lgroupmod', True) lchage_cmd = self.module.get_bin_path('lchage', True) else: command_name = 'useradd' cmd = [self.module.get_bin_path(command_name, True)] if self.uid is not None: cmd.append('-u') cmd.append(self.uid) if self.non_unique: cmd.append('-o') if self.seuser is not None: cmd.append('-Z') cmd.append(self.seuser) if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) cmd.append('-g') cmd.append(self.group) elif self.group_exists(self.name): if self.local:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append('-n') else: if os.path.exists('/etc/redhat-release'): dist = distro.version() major_release = int(dist.split('.')[0]) if major_release <= 5: cmd.append('-n') else: cmd.append('-N') elif os.path.exists('/etc/SuSE-release'): dist = distro.version() major_release = int(dist.split('.')[0]) if major_release >= 12: cmd.append('-N') else: cmd.append('-N') if self.groups is not None and len(self.groups): groups = self.get_groups_set() if not self.local: cmd.append('-G') cmd.append(','.join(groups)) if self.comment is not None: cmd.append('-c') cmd.append(self.comment) if self.home is not None:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.create_home: parent = os.path.dirname(self.home) if not os.path.isdir(parent): self.create_homedir(self.home) cmd.append('-d') cmd.append(self.home) if self.shell is not None: cmd.append('-s') cmd.append(self.shell) if self.expires is not None and not self.local: cmd.append('-e') if self.expires < time.gmtime(0): cmd.append('') else: cmd.append(time.strftime(self.DATE_FORMAT, self.expires)) if self.password is not None: cmd.append('-p') if self.password_lock: cmd.append('!%s' % self.password) else: cmd.append(self.password) if self.create_home: if not self.local: cmd.append('-m') if self.skeleton is not None: cmd.append('-k') cmd.append(self.skeleton) if self.umask is not None: cmd.append('-K')
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append('UMASK=' + self.umask) else: cmd.append('-M') if self.system: cmd.append('-r') cmd.append(self.name) (rc, out, err) = self.execute_command(cmd) if not self.local or rc != 0: return (rc, out, err) if self.expires is not None: if self.expires < time.gmtime(0): lexpires = -1 else: lexpires = int(math.floor(self.module.params['expires'])) // 86400 (rc, _out, _err) = self.execute_command([lchage_cmd, '-E', to_native(lexpires), self.name]) out += _out err += _err if rc != 0: return (rc, out, err) if self.groups is None or len(self.groups) == 0: return (rc, out, err) for add_group in groups: (rc, _out, _err) = self.execute_command([lgroupmod_cmd, '-M', self.name, add_group]) out += _out err += _err if rc != 0: return (rc, out, err) return (rc, out, err) def _check_usermod_append(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.local: command_name = 'lusermod' else: command_name = 'usermod' usermod_path = self.module.get_bin_path(command_name, True) if not os.access(usermod_path, os.X_OK): return False cmd = [usermod_path, '--help'] (rc, data1, data2) = self.execute_command(cmd, obey_checkmode=False) helpout = data1 + data2 lines = to_native(helpout).split('\n') for line in lines: if line.strip().startswith('-a, --append'): return True return False def modify_user_usermod(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.local: command_name = 'lusermod' lgroupmod_cmd = self.module.get_bin_path('lgroupmod', True) lgroupmod_add = set() lgroupmod_del = set() lchage_cmd = self.module.get_bin_path('lchage', True) lexpires = None else: command_name = 'usermod' cmd = [self.module.get_bin_path(command_name, True)] info = self.user_info() has_append = self._check_usermod_append() if self.uid is not None and info[2] != int(self.uid): cmd.append('-u') cmd.append(self.uid) if self.non_unique:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append('-o') if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) ginfo = self.group_info(self.group) if info[3] != ginfo[2]: cmd.append('-g') cmd.append(ginfo[2]) if self.groups is not None: current_groups = self.user_group_membership(exclude_primary=False) groups_need_mod = False groups = [] if self.groups == '': if current_groups and not self.append: groups_need_mod = True else: groups = self.get_groups_set(remove_existing=False, names_only=True) group_diff = set(current_groups).symmetric_difference(groups) if group_diff: if self.append: for g in groups: if g in group_diff: if has_append: cmd.append('-a') groups_need_mod = True break else: groups_need_mod = True if groups_need_mod:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.local: if self.append: lgroupmod_add = set(groups).difference(current_groups) lgroupmod_del = set() else: lgroupmod_add = set(groups).difference(current_groups) lgroupmod_del = set(current_groups).difference(groups) else: if self.append and not has_append: cmd.append('-A') cmd.append(','.join(group_diff)) else: cmd.append('-G') cmd.append(','.join(groups)) if self.comment is not None and info[4] != self.comment: cmd.append('-c') cmd.append(self.comment) if self.home is not None and info[5] != self.home: cmd.append('-d') cmd.append(self.home) if self.move_home: cmd.append('-m') if self.shell is not None and info[6] != self.shell: cmd.append('-s') cmd.append(self.shell) if self.expires is not None: current_expires = self.user_password()[1] or '0' current_expires = int(current_expires) if self.expires < time.gmtime(0): if current_expires >= 0:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.local: lexpires = -1 else: cmd.append('-e') cmd.append('') else: current_expire_date = time.gmtime(current_expires * 86400) if current_expires < 0 or current_expire_date[:3] != self.expires[:3]: if self.local: lexpires = int(math.floor(self.module.params['expires'])) // 86400 else: cmd.append('-e') cmd.append(time.strftime(self.DATE_FORMAT, self.expires)) if self.password_lock and not info[1].startswith('!'): cmd.append('-L') elif self.password_lock is False and info[1].startswith('!'): cmd.append('-U') if self.update_password == 'always' and self.password is not None and info[1].lstrip('!') != self.password.lstrip('!'): cmd = [c for c in cmd if c not in ['-U', '-L']] cmd.append('-p') if self.password_lock: cmd.append('!%s' % self.password) else:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append(self.password) (rc, out, err) = (None, '', '') if len(cmd) > 1: cmd.append(self.name) (rc, out, err) = self.execute_command(cmd) if not self.local or not (rc is None or rc == 0): return (rc, out, err) if lexpires is not None: (rc, _out, _err) = self.execute_command([lchage_cmd, '-E', to_native(lexpires), self.name]) out += _out err += _err if rc != 0: return (rc, out, err) if len(lgroupmod_add) == 0 and len(lgroupmod_del) == 0: return (rc, out, err) for add_group in lgroupmod_add: (rc, _out, _err) = self.execute_command([lgroupmod_cmd, '-M', self.name, add_group]) out += _out err += _err if rc != 0: return (rc, out, err) for del_group in lgroupmod_del: (rc, _out, _err) = self.execute_command([lgroupmod_cmd, '-m', self.name, del_group]) out += _out err += _err if rc != 0: return (rc, out, err) return (rc, out, err) def group_exists(self, group):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
try: grp.getgrgid(int(group)) return True except (ValueError, KeyError): try: grp.getgrnam(group) return True except KeyError: return False def group_info(self, group): if not self.group_exists(group): return False try: return list(grp.getgrgid(int(group))) except (ValueError, KeyError): return list(grp.getgrnam(group)) def get_groups_set(self, remove_existing=True, names_only=False):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.groups is None: return None info = self.user_info() groups = set(x.strip() for x in self.groups.split(',') if x) group_names = set() for g in groups.copy(): if not self.group_exists(g): self.module.fail_json(msg="Group %s does not exist" % (g)) group_info = self.group_info(g) if info and remove_existing and group_info[2] == info[3]: groups.remove(g) elif names_only: group_names.add(group_info[0]) if names_only: return group_names return groups def user_group_membership(self, exclude_primary=True): ''' Return a list of groups the user belongs to ''' groups = [] info = self.get_pwd_info() for group in grp.getgrall(): if self.name in group.gr_mem: if not exclude_primary: groups.append(group[0]) else: if info[3] != group.gr_gid: groups.append(group[0]) return groups def user_exists(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.local: if not os.path.exists(self.PASSWORDFILE): self.module.fail_json(msg="'local: true' specified but unable to find local account file {0} to parse.".format(self.PASSWORDFILE)) exists = False name_test = '{0}:'.format(self.name) with open(self.PASSWORDFILE, 'rb') as f: reversed_lines = f.readlines()[::-1] for line in reversed_lines: if line.startswith(to_bytes(name_test)): exists = True break if not exists: self.module.warn( "'local: true' specified and user '{name}' was not found in {file}. " "The local user account may already exist if the local account database exists " "somewhere other than {file}.".format(file=self.PASSWORDFILE, name=self.name)) return exists else: try: if pwd.getpwnam(self.name): return True except KeyError: return False def get_pwd_info(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if not self.user_exists(): return False return list(pwd.getpwnam(self.name)) def user_info(self): if not self.user_exists(): return False info = self.get_pwd_info() if len(info[1]) == 1 or len(info[1]) == 0: info[1] = self.user_password()[0] return info def set_password_expire(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
min_needs_change = self.password_expire_min is not None max_needs_change = self.password_expire_max is not None warn_needs_change = self.password_expire_warn is not None if HAVE_SPWD: try: shadow_info = getspnam(to_bytes(self.name)) except ValueError: return None, '', '' min_needs_change &= self.password_expire_min != shadow_info.sp_min max_needs_change &= self.password_expire_max != shadow_info.sp_max warn_needs_change &= self.password_expire_warn != shadow_info.sp_warn if not (min_needs_change or max_needs_change or warn_needs_change): return (None, '', '') command_name = 'chage' cmd = [self.module.get_bin_path(command_name, True)] if min_needs_change: cmd.extend(["-m", self.password_expire_min]) if max_needs_change: cmd.extend(["-M", self.password_expire_max]) if warn_needs_change: cmd.extend(["-W", self.password_expire_warn]) cmd.append(self.name) return self.execute_command(cmd) def user_password(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
passwd = '' expires = '' if HAVE_SPWD: try: shadow_info = getspnam(to_bytes(self.name)) passwd = to_native(shadow_info.sp_pwdp) expires = shadow_info.sp_expire return passwd, expires except ValueError: return passwd, expires if not self.user_exists(): return passwd, expires elif self.SHADOWFILE: passwd, expires = self.parse_shadow_file() return passwd, expires def parse_shadow_file(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
passwd = '' expires = '' if os.path.exists(self.SHADOWFILE) and os.access(self.SHADOWFILE, os.R_OK): with open(self.SHADOWFILE, 'r') as f: for line in f: if line.startswith('%s:' % self.name): passwd = line.split(':')[1] expires = line.split(':')[self.SHADOWFILE_EXPIRE_INDEX] or -1 return passwd, expires def get_ssh_key_path(self): info = self.user_info() if os.path.isabs(self.ssh_file): ssh_key_file = self.ssh_file else: if not os.path.exists(info[5]) and not self.module.check_mode: raise Exception('User %s home directory does not exist' % self.name) ssh_key_file = os.path.join(info[5], self.ssh_file) return ssh_key_file def ssh_key_gen(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
info = self.user_info() overwrite = None try: ssh_key_file = self.get_ssh_key_path() except Exception as e: return (1, '', to_native(e)) ssh_dir = os.path.dirname(ssh_key_file) if not os.path.exists(ssh_dir): if self.module.check_mode: return (0, '', '') try: os.mkdir(ssh_dir, int('0700', 8)) os.chown(ssh_dir, info[2], info[3]) except OSError as e: return (1, '', 'Failed to create %s: %s' % (ssh_dir, to_native(e))) if os.path.exists(ssh_key_file): if self.force: overwrite = 'y' else: return (None, 'Key already exists, use "force: yes" to overwrite', '') cmd = [self.module.get_bin_path('ssh-keygen', True)] cmd.append('-t') cmd.append(self.ssh_type) if self.ssh_bits > 0: cmd.append('-b')
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append(self.ssh_bits) cmd.append('-C') cmd.append(self.ssh_comment) cmd.append('-f') cmd.append(ssh_key_file) if self.ssh_passphrase is not None: if self.module.check_mode: self.module.debug('In check mode, would have run: "%s"' % cmd) return (0, '', '') master_in_fd, slave_in_fd = pty.openpty() master_out_fd, slave_out_fd = pty.openpty() master_err_fd, slave_err_fd = pty.openpty() env = os.environ.copy() env['LC_ALL'] = get_best_parsable_locale(self.module) try: p = subprocess.Popen([to_bytes(c) for c in cmd], stdin=slave_in_fd, stdout=slave_out_fd, stderr=slave_err_fd, preexec_fn=os.setsid, env=env) out_buffer = b'' err_buffer = b'' while p.poll() is None: r_list = select.select([master_out_fd, master_err_fd], [], [], 1)[0] first_prompt = b'Enter passphrase (empty for no passphrase):' second_prompt = b'Enter same passphrase again' prompt = first_prompt for fd in r_list: if fd == master_out_fd:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
chunk = os.read(master_out_fd, 10240) out_buffer += chunk if prompt in out_buffer: os.write(master_in_fd, to_bytes(self.ssh_passphrase, errors='strict') + b'\r') prompt = second_prompt else: chunk = os.read(master_err_fd, 10240) err_buffer += chunk if prompt in err_buffer: os.write(master_in_fd, to_bytes(self.ssh_passphrase, errors='strict') + b'\r') prompt = second_prompt if b'Overwrite (y/n)?' in out_buffer or b'Overwrite (y/n)?' in err_buffer: return (None, 'Key already exists', '') rc = p.returncode out = to_native(out_buffer) err = to_native(err_buffer) except OSError as e: return (1, '', to_native(e)) else: cmd.append('-N') cmd.append('') (rc, out, err) = self.execute_command(cmd, data=overwrite) if rc == 0 and not self.module.check_mode: os.chown(ssh_key_file, info[2], info[3]) os.chown('%s.pub' % ssh_key_file, info[2], info[3]) return (rc, out, err) def ssh_key_fingerprint(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
ssh_key_file = self.get_ssh_key_path() if not os.path.exists(ssh_key_file): return (1, 'SSH Key file %s does not exist' % ssh_key_file, '') cmd = [self.module.get_bin_path('ssh-keygen', True)] cmd.append('-l') cmd.append('-f') cmd.append(ssh_key_file) return self.execute_command(cmd, obey_checkmode=False) def get_ssh_public_key(self): ssh_public_key_file = '%s.pub' % self.get_ssh_key_path() try: with open(ssh_public_key_file, 'r') as f: ssh_public_key = f.read().strip() except IOError: return None return ssh_public_key def create_user(self): return self.create_user_useradd() def remove_user(self): return self.remove_user_userdel() def modify_user(self): return self.modify_user_usermod() def create_homedir(self, path):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if not os.path.exists(path): if self.skeleton is not None: skeleton = self.skeleton else: skeleton = '/etc/skel' if os.path.exists(skeleton) and skeleton != os.devnull: try: shutil.copytree(skeleton, path, symlinks=True) except OSError as e: self.module.exit_json(failed=True, msg="%s" % to_native(e)) else: try: os.makedirs(path) except OSError as e: self.module.exit_json(failed=True, msg="%s" % to_native(e)) if os.path.exists(self.LOGIN_DEFS): with open(self.LOGIN_DEFS, 'r') as f: for line in f: m = re.match(r'^UMASK\s+(\d+)$', line) if m: umask = int(m.group(1), 8) mode = 0o777 & ~umask try: os.chmod(path, mode) except OSError as e: self.module.exit_json(failed=True, msg="%s" % to_native(e)) def chown_homedir(self, uid, gid, path):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
try: os.chown(path, uid, gid) for root, dirs, files in os.walk(path): for d in dirs: os.chown(os.path.join(root, d), uid, gid) for f in files: os.chown(os.path.join(root, f), uid, gid) except OSError as e: self.module.exit_json(failed=True, msg="%s" % to_native(e)) class FreeBsdUser(User): """ This is a FreeBSD User manipulation class - it uses the pw command to manipulate the user database, followed by the chpass command to change the password. This overrides the following methods from the generic class:- - create_user() - remove_user() - modify_user() """ platform = 'FreeBSD' distribution = None SHADOWFILE = '/etc/master.passwd' SHADOWFILE_EXPIRE_INDEX = 6 DATE_FORMAT = '%d-%b-%Y' def _handle_lock(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
info = self.user_info() if self.password_lock and not info[1].startswith('*LOCKED*'): cmd = [ self.module.get_bin_path('pw', True), 'lock', self.name ] if self.uid is not None and info[2] != int(self.uid): cmd.append('-u') cmd.append(self.uid) return self.execute_command(cmd) elif self.password_lock is False and info[1].startswith('*LOCKED*'): cmd = [ self.module.get_bin_path('pw', True), 'unlock', self.name ] if self.uid is not None and info[2] != int(self.uid): cmd.append('-u') cmd.append(self.uid) return self.execute_command(cmd) return (None, '', '') def remove_user(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd = [ self.module.get_bin_path('pw', True), 'userdel', '-n', self.name ] if self.remove: cmd.append('-r') return self.execute_command(cmd) def create_user(self): cmd = [ self.module.get_bin_path('pw', True), 'useradd', '-n', self.name, ] if self.uid is not None: cmd.append('-u') cmd.append(self.uid) if self.non_unique: cmd.append('-o') if self.comment is not None:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append('-c') cmd.append(self.comment) if self.home is not None: cmd.append('-d') cmd.append(self.home) if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) cmd.append('-g') cmd.append(self.group) if self.groups is not None: groups = self.get_groups_set() cmd.append('-G') cmd.append(','.join(groups)) if self.create_home: cmd.append('-m') if self.skeleton is not None: cmd.append('-k') cmd.append(self.skeleton) if self.umask is not None: cmd.append('-K') cmd.append('UMASK=' + self.umask) if self.shell is not None: cmd.append('-s') cmd.append(self.shell) if self.login_class is not None: cmd.append('-L') cmd.append(self.login_class) if self.expires is not None: cmd.append('-e')
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.expires < time.gmtime(0): cmd.append('0') else: cmd.append(str(calendar.timegm(self.expires))) (rc, out, err) = self.execute_command(cmd) if rc is not None and rc != 0: self.module.fail_json(name=self.name, msg=err, rc=rc) if self.password is not None: cmd = [ self.module.get_bin_path('chpass', True), '-p', self.password, self.name ] _rc, _out, _err = self.execute_command(cmd) if rc is None: rc = _rc out += _out err += _err _rc, _out, _err = self._handle_lock() if rc is None: rc = _rc out += _out err += _err return (rc, out, err) def modify_user(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd = [ self.module.get_bin_path('pw', True), 'usermod', '-n', self.name ] cmd_len = len(cmd) info = self.user_info() if self.uid is not None and info[2] != int(self.uid): cmd.append('-u') cmd.append(self.uid) if self.non_unique: cmd.append('-o') if self.comment is not None and info[4] != self.comment: cmd.append('-c') cmd.append(self.comment) if self.home is not None: if (info[5] != self.home and self.move_home) or (not os.path.exists(self.home) and self.create_home): cmd.append('-m') if info[5] != self.home: cmd.append('-d') cmd.append(self.home) if self.skeleton is not None: cmd.append('-k')
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append(self.skeleton) if self.umask is not None: cmd.append('-K') cmd.append('UMASK=' + self.umask) if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) ginfo = self.group_info(self.group) if info[3] != ginfo[2]: cmd.append('-g') cmd.append(self.group) if self.shell is not None and info[6] != self.shell: cmd.append('-s') cmd.append(self.shell) if self.login_class is not None: user_login_class = None if os.path.exists(self.SHADOWFILE) and os.access(self.SHADOWFILE, os.R_OK): with open(self.SHADOWFILE, 'r') as f: for line in f: if line.startswith('%s:' % self.name): user_login_class = line.split(':')[4] if self.login_class != user_login_class: cmd.append('-L') cmd.append(self.login_class) if self.groups is not None: current_groups = self.user_group_membership() groups = self.get_groups_set(names_only=True) group_diff = set(current_groups).symmetric_difference(groups)
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
groups_need_mod = False if group_diff: if self.append: for g in groups: if g in group_diff: groups_need_mod = True break else: groups_need_mod = True if groups_need_mod: cmd.append('-G') new_groups = groups if self.append: new_groups = groups | set(current_groups) cmd.append(','.join(new_groups)) if self.expires is not None: current_expires = self.user_password()[1] or '0' current_expires = int(current_expires) if self.expires <= time.gmtime(0): if current_expires > 0: cmd.append('-e') cmd.append('0') else: current_expire_date = time.gmtime(current_expires) if current_expires <= 0 or current_expire_date[:3] != self.expires[:3]: cmd.append('-e')
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append(str(calendar.timegm(self.expires))) (rc, out, err) = (None, '', '') if cmd_len != len(cmd): (rc, _out, _err) = self.execute_command(cmd) out += _out err += _err if rc is not None and rc != 0: self.module.fail_json(name=self.name, msg=err, rc=rc) if self.update_password == 'always' and self.password is not None and info[1].lstrip('*LOCKED*') != self.password.lstrip('*LOCKED*'): cmd = [ self.module.get_bin_path('chpass', True), '-p', self.password, self.name ] _rc, _out, _err = self.execute_command(cmd) if rc is None: rc = _rc out += _out err += _err _rc, _out, _err = self._handle_lock() if rc is None: rc = _rc out += _out err += _err return (rc, out, err) class DragonFlyBsdUser(FreeBsdUser):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
""" This is a DragonFlyBSD User manipulation class - it inherits the FreeBsdUser class behaviors, such as using the pw command to manipulate the user database, followed by the chpass command to change the password. """ platform = 'DragonFly' class OpenBSDUser(User):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
""" This is a OpenBSD User manipulation class. Main differences are that OpenBSD:- - has no concept of "system" account. - has no force delete user This overrides the following methods from the generic class:- - create_user() - remove_user() - modify_user() """ platform = 'OpenBSD' distribution = None SHADOWFILE = '/etc/master.passwd' def create_user(self): cmd = [self.module.get_bin_path('useradd', True)] if self.uid is not None: cmd.append('-u') cmd.append(self.uid) if self.non_unique: cmd.append('-o') if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) cmd.append('-g') cmd.append(self.group)
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.groups is not None: groups = self.get_groups_set() cmd.append('-G') cmd.append(','.join(groups)) if self.comment is not None: cmd.append('-c') cmd.append(self.comment) if self.home is not None: cmd.append('-d') cmd.append(self.home) if self.shell is not None: cmd.append('-s') cmd.append(self.shell) if self.login_class is not None: cmd.append('-L') cmd.append(self.login_class) if self.password is not None and self.password != '*': cmd.append('-p') cmd.append(self.password) if self.create_home: cmd.append('-m') if self.skeleton is not None: cmd.append('-k') cmd.append(self.skeleton) if self.umask is not None: cmd.append('-K') cmd.append('UMASK=' + self.umask) cmd.append(self.name) return self.execute_command(cmd) def remove_user_userdel(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd = [self.module.get_bin_path('userdel', True)] if self.remove: cmd.append('-r') cmd.append(self.name) return self.execute_command(cmd) def modify_user(self): cmd = [self.module.get_bin_path('usermod', True)] info = self.user_info() if self.uid is not None and info[2] != int(self.uid): cmd.append('-u') cmd.append(self.uid) if self.non_unique: cmd.append('-o') if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) ginfo = self.group_info(self.group) if info[3] != ginfo[2]: cmd.append('-g') cmd.append(self.group) if self.groups is not None:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
current_groups = self.user_group_membership() groups_need_mod = False groups_option = '-S' groups = [] if self.groups == '': if current_groups and not self.append: groups_need_mod = True else: groups = self.get_groups_set(names_only=True) group_diff = set(current_groups).symmetric_difference(groups) if group_diff: if self.append: for g in groups: if g in group_diff: groups_option = '-G' groups_need_mod = True break else: groups_need_mod = True if groups_need_mod: cmd.append(groups_option) cmd.append(','.join(groups)) if self.comment is not None and info[4] != self.comment: cmd.append('-c') cmd.append(self.comment) if self.home is not None and info[5] != self.home: if self.move_home: cmd.append('-m') cmd.append('-d') cmd.append(self.home)
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if self.shell is not None and info[6] != self.shell: cmd.append('-s') cmd.append(self.shell) if self.login_class is not None: user_login_class = None userinfo_cmd = [self.module.get_bin_path('userinfo', True), self.name] (rc, out, err) = self.execute_command(userinfo_cmd, obey_checkmode=False) for line in out.splitlines(): tokens = line.split() if tokens[0] == 'class' and len(tokens) == 2: user_login_class = tokens[1] if self.login_class != user_login_class: cmd.append('-L') cmd.append(self.login_class) if self.password_lock and not info[1].startswith('*'): cmd.append('-Z') elif self.password_lock is False and info[1].startswith('*'): cmd.append('-U') if self.update_password == 'always' and self.password is not None \ and self.password != '*' and info[1] != self.password: cmd.append('-p') cmd.append(self.password) if len(cmd) == 1: return (None, '', '') cmd.append(self.name) return self.execute_command(cmd) class NetBSDUser(User):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
""" This is a NetBSD User manipulation class. Main differences are that NetBSD:- - has no concept of "system" account. - has no force delete user This overrides the following methods from the generic class:- - create_user() - remove_user() - modify_user() """ platform = 'NetBSD' distribution = None SHADOWFILE = '/etc/master.passwd' def create_user(self): cmd = [self.module.get_bin_path('useradd', True)] if self.uid is not None: cmd.append('-u') cmd.append(self.uid) if self.non_unique: cmd.append('-o') if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) cmd.append('-g') cmd.append(self.group) if self.groups is not None: groups = self.get_groups_set()
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if len(groups) > 16: self.module.fail_json(msg="Too many groups (%d) NetBSD allows for 16 max." % len(groups)) cmd.append('-G') cmd.append(','.join(groups)) if self.comment is not None: cmd.append('-c') cmd.append(self.comment) if self.home is not None: cmd.append('-d') cmd.append(self.home) if self.shell is not None: cmd.append('-s') cmd.append(self.shell) if self.login_class is not None: cmd.append('-L') cmd.append(self.login_class) if self.password is not None: cmd.append('-p') cmd.append(self.password) if self.create_home: cmd.append('-m') if self.skeleton is not None: cmd.append('-k') cmd.append(self.skeleton) if self.umask is not None: cmd.append('-K') cmd.append('UMASK=' + self.umask) cmd.append(self.name) return self.execute_command(cmd) def remove_user_userdel(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd = [self.module.get_bin_path('userdel', True)] if self.remove: cmd.append('-r') cmd.append(self.name) return self.execute_command(cmd) def modify_user(self): cmd = [self.module.get_bin_path('usermod', True)] info = self.user_info() if self.uid is not None and info[2] != int(self.uid): cmd.append('-u') cmd.append(self.uid) if self.non_unique: cmd.append('-o') if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) ginfo = self.group_info(self.group) if info[3] != ginfo[2]: cmd.append('-g') cmd.append(self.group) if self.groups is not None: current_groups = self.user_group_membership() groups_need_mod = False groups = [] if self.groups == '': if current_groups and not self.append: groups_need_mod = True
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
else: groups = self.get_groups_set(names_only=True) group_diff = set(current_groups).symmetric_difference(groups) if group_diff: if self.append: for g in groups: if g in group_diff: groups = set(current_groups).union(groups) groups_need_mod = True break else: groups_need_mod = True if groups_need_mod: if len(groups) > 16: self.module.fail_json(msg="Too many groups (%d) NetBSD allows for 16 max." % len(groups)) cmd.append('-G') cmd.append(','.join(groups)) if self.comment is not None and info[4] != self.comment: cmd.append('-c') cmd.append(self.comment) if self.home is not None and info[5] != self.home: if self.move_home: cmd.append('-m') cmd.append('-d') cmd.append(self.home) if self.shell is not None and info[6] != self.shell: cmd.append('-s') cmd.append(self.shell) if self.login_class is not None: cmd.append('-L')
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append(self.login_class) if self.update_password == 'always' and self.password is not None and info[1] != self.password: cmd.append('-p') cmd.append(self.password) if self.password_lock and not info[1].startswith('*LOCKED*'): cmd.append('-C yes') elif self.password_lock is False and info[1].startswith('*LOCKED*'): cmd.append('-C no') if len(cmd) == 1: return (None, '', '') cmd.append(self.name) return self.execute_command(cmd) class SunOS(User): """ This is a SunOS User manipulation class - The main difference between this class and the generic user class is that Solaris-type distros don't support the concept of a "system" account and we need to edit the /etc/shadow file manually to set a password. (Ugh) This overrides the following methods from the generic class:- - create_user() - remove_user() - modify_user() - user_info() """ platform = 'SunOS' distribution = None SHADOWFILE = '/etc/shadow' USER_ATTR = '/etc/user_attr' def get_password_defaults(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
try: minweeks = '' maxweeks = '' warnweeks = '' with open("/etc/default/passwd", 'r') as f: for line in f: line = line.strip() if (line.startswith('#') or line == ''): continue m = re.match(r'^([^#]*)#(.*)$', line) if m: line = m.group(1) key, value = line.split('=') if key == "MINWEEKS": minweeks = value.rstrip('\n') elif key == "MAXWEEKS": maxweeks = value.rstrip('\n') elif key == "WARNWEEKS": warnweeks = value.rstrip('\n') except Exception as err: self.module.fail_json(msg="failed to read /etc/default/passwd: %s" % to_native(err)) return (minweeks, maxweeks, warnweeks) def remove_user(self): cmd = [self.module.get_bin_path('userdel', True)] if self.remove: cmd.append('-r') cmd.append(self.name) return self.execute_command(cmd) def create_user(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd = [self.module.get_bin_path('useradd', True)] if self.uid is not None: cmd.append('-u') cmd.append(self.uid) if self.non_unique: cmd.append('-o') if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) cmd.append('-g') cmd.append(self.group) if self.groups is not None: groups = self.get_groups_set() cmd.append('-G') cmd.append(','.join(groups)) if self.comment is not None: cmd.append('-c') cmd.append(self.comment) if self.home is not None: cmd.append('-d') cmd.append(self.home) if self.shell is not None: cmd.append('-s') cmd.append(self.shell) if self.create_home: cmd.append('-m') if self.skeleton is not None:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append('-k') cmd.append(self.skeleton) if self.umask is not None: cmd.append('-K') cmd.append('UMASK=' + self.umask) if self.profile is not None: cmd.append('-P') cmd.append(self.profile) if self.authorization is not None: cmd.append('-A') cmd.append(self.authorization) if self.role is not None: cmd.append('-R') cmd.append(self.role) cmd.append(self.name) (rc, out, err) = self.execute_command(cmd) if rc is not None and rc != 0: self.module.fail_json(name=self.name, msg=err, rc=rc) if not self.module.check_mode: if self.password is not None: self.backup_shadow() minweeks, maxweeks, warnweeks = self.get_password_defaults() try: lines = [] with open(self.SHADOWFILE, 'rb') as f: for line in f: line = to_native(line, errors='surrogate_or_strict') fields = line.strip().split(':') if not fields[0] == self.name:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
lines.append(line) continue fields[1] = self.password fields[2] = str(int(time.time() // 86400)) if minweeks: try: fields[3] = str(int(minweeks) * 7) except ValueError: pass if maxweeks: try: fields[4] = str(int(maxweeks) * 7) except ValueError: pass if warnweeks: try: fields[5] = str(int(warnweeks) * 7) except ValueError: pass line = ':'.join(fields) lines.append('%s\n' % line) with open(self.SHADOWFILE, 'w+') as f: f.writelines(lines) except Exception as err: self.module.fail_json(msg="failed to update users password: %s" % to_native(err)) return (rc, out, err) def modify_user_usermod(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd = [self.module.get_bin_path('usermod', True)] cmd_len = len(cmd) info = self.user_info() if self.uid is not None and info[2] != int(self.uid): cmd.append('-u') cmd.append(self.uid) if self.non_unique: cmd.append('-o') if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) ginfo = self.group_info(self.group) if info[3] != ginfo[2]: cmd.append('-g') cmd.append(self.group) if self.groups is not None: current_groups = self.user_group_membership() groups = self.get_groups_set(names_only=True) group_diff = set(current_groups).symmetric_difference(groups) groups_need_mod = False
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if group_diff: if self.append: for g in groups: if g in group_diff: groups_need_mod = True break else: groups_need_mod = True if groups_need_mod: cmd.append('-G') new_groups = groups if self.append: new_groups.update(current_groups) cmd.append(','.join(new_groups)) if self.comment is not None and info[4] != self.comment: cmd.append('-c') cmd.append(self.comment) if self.home is not None and info[5] != self.home: if self.move_home: cmd.append('-m') cmd.append('-d') cmd.append(self.home) if self.shell is not None and info[6] != self.shell: cmd.append('-s') cmd.append(self.shell) if self.profile is not None and info[7] != self.profile: cmd.append('-P') cmd.append(self.profile) if self.authorization is not None and info[8] != self.authorization: cmd.append('-A')
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd.append(self.authorization) if self.role is not None and info[9] != self.role: cmd.append('-R') cmd.append(self.role) if cmd_len != len(cmd): cmd.append(self.name) (rc, out, err) = self.execute_command(cmd) if rc is not None and rc != 0: self.module.fail_json(name=self.name, msg=err, rc=rc) else: (rc, out, err) = (None, '', '') if self.update_password == 'always' and self.password is not None and info[1] != self.password: self.backup_shadow() (rc, out, err) = (0, '', '') if not self.module.check_mode: minweeks, maxweeks, warnweeks = self.get_password_defaults() try: lines = [] with open(self.SHADOWFILE, 'rb') as f: for line in f: line = to_native(line, errors='surrogate_or_strict') fields = line.strip().split(':') if not fields[0] == self.name: lines.append(line) continue fields[1] = self.password fields[2] = str(int(time.time() // 86400)) if minweeks:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
fields[3] = str(int(minweeks) * 7) if maxweeks: fields[4] = str(int(maxweeks) * 7) if warnweeks: fields[5] = str(int(warnweeks) * 7) line = ':'.join(fields) lines.append('%s\n' % line) with open(self.SHADOWFILE, 'w+') as f: f.writelines(lines) rc = 0 except Exception as err: self.module.fail_json(msg="failed to update users password: %s" % to_native(err)) return (rc, out, err) def user_info(self): info = super(SunOS, self).user_info() if info: info += self._user_attr_info() return info def _user_attr_info(self): info = [''] * 3 with open(self.USER_ATTR, 'r') as file_handler: for line in file_handler: lines = line.strip().split('::::') if lines[0] == self.name: tmp = dict(x.split('=') for x in lines[1].split(';')) info[0] = tmp.get('profiles', '') info[1] = tmp.get('auths', '') info[2] = tmp.get('roles', '') return info class DarwinUser(User):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
""" This is a Darwin macOS User manipulation class. Main differences are that Darwin:- - Handles accounts in a database managed by dscl(1) - Has no useradd/groupadd - Does not create home directories - User password must be cleartext - UID must be given - System users must ben under 500 This overrides the following methods from the generic class:- - user_exists() - create_user() - remove_user() - modify_user() """ platform = 'Darwin' distribution = None SHADOWFILE = None dscl_directory = '.' fields = [ ('comment', 'RealName'), ('home', 'NFSHomeDirectory'), ('shell', 'UserShell'), ('uid', 'UniqueID'), ('group', 'PrimaryGroupID'), ('hidden', 'IsHidden'), ] def __init__(self, module):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
super(DarwinUser, self).__init__(module) if self.hidden is None: if self.system: self.hidden = 1 elif self.hidden: self.hidden = 1 else: self.hidden = 0 if self.hidden is not None: self.fields.append(('hidden', 'IsHidden')) def _get_dscl(self): return [self.module.get_bin_path('dscl', True), self.dscl_directory] def _list_user_groups(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd = self._get_dscl() cmd += ['-search', '/Groups', 'GroupMembership', self.name] (rc, out, err) = self.execute_command(cmd, obey_checkmode=False) groups = [] for line in out.splitlines(): if line.startswith(' ') or line.startswith(')'): continue groups.append(line.split()[0]) return groups def _get_user_property(self, property): '''Return user PROPERTY as given my dscl(1) read or None if not found.''' cmd = self._get_dscl() cmd += ['-read', '/Users/%s' % self.name, property] (rc, out, err) = self.execute_command(cmd, obey_checkmode=False) if rc != 0: return None lines = out.splitlines() if len(lines) == 1: return lines[0].split(': ')[1] if len(lines) > 2: return '\n'.join([lines[1].strip()] + lines[2:]) if len(lines) == 2: return lines[1].strip() return None def _get_next_uid(self, system=None):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
''' Return the next available uid. If system=True, then uid should be below of 500, if possible. ''' cmd = self._get_dscl() cmd += ['-list', '/Users', 'UniqueID'] (rc, out, err) = self.execute_command(cmd, obey_checkmode=False) if rc != 0: self.module.fail_json( msg="Unable to get the next available uid", rc=rc, out=out, err=err ) max_uid = 0 max_system_uid = 0 for line in out.splitlines(): current_uid = int(line.split(' ')[-1]) if max_uid < current_uid: max_uid = current_uid if max_system_uid < current_uid and current_uid < 500: max_system_uid = current_uid if system and (0 < max_system_uid < 499): return max_system_uid + 1 return max_uid + 1 def _change_user_password(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
'''Change password for SELF.NAME against SELF.PASSWORD. Please note that password must be cleartext. ''' cmd = self._get_dscl() if self.password: cmd += ['-passwd', '/Users/%s' % self.name, self.password] else: cmd += ['-create', '/Users/%s' % self.name, 'Password', '*'] (rc, out, err) = self.execute_command(cmd) if rc != 0: self.module.fail_json(msg='Error when changing password', err=err, out=out, rc=rc) return (rc, out, err) def _make_group_numerical(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
'''Convert SELF.GROUP to is stringed numerical value suitable for dscl.''' if self.group is None: self.group = 'nogroup' try: self.group = grp.getgrnam(self.group).gr_gid except KeyError: self.module.fail_json(msg='Group "%s" not found. Try to create it first using "group" module.' % self.group) self.group = str(self.group) def __modify_group(self, group, action): '''Add or remove SELF.NAME to or from GROUP depending on ACTION. ACTION can be 'add' or 'remove' otherwise 'remove' is assumed. ''' if action == 'add': option = '-a' else: option = '-d' cmd = ['dseditgroup', '-o', 'edit', option, self.name, '-t', 'user', group] (rc, out, err) = self.execute_command(cmd) if rc != 0: self.module.fail_json(msg='Cannot %s user "%s" to group "%s".' % (action, self.name, group), err=err, out=out, rc=rc) return (rc, out, err) def _modify_group(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
'''Add or remove SELF.NAME to or from GROUP depending on ACTION. ACTION can be 'add' or 'remove' otherwise 'remove' is assumed. ''' rc = 0 out = '' err = '' changed = False current = set(self._list_user_groups()) if self.groups is not None: target = self.get_groups_set(names_only=True) else: target = set([]) if self.append is False: for remove in current - target: (_rc, _out, _err) = self.__modify_group(remove, 'delete') rc += rc out += _out err += _err changed = True for add in target - current: (_rc, _out, _err) = self.__modify_group(add, 'add') rc += _rc out += _out err += _err changed = True return (rc, out, err, changed) def _update_system_user(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
'''Hide or show user on login window according SELF.SYSTEM. Returns 0 if a change has been made, None otherwise.''' plist_file = '/Library/Preferences/com.apple.loginwindow.plist' cmd = ['defaults', 'read', plist_file, 'HiddenUsersList'] (rc, out, err) = self.execute_command(cmd, obey_checkmode=False) hidden_users = [] for x in out.splitlines()[1:-1]: try: x = x.split('"')[1] except IndexError: x = x.strip() hidden_users.append(x) if self.system: if self.name not in hidden_users: cmd = ['defaults', 'write', plist_file, 'HiddenUsersList', '-array-add', self.name] (rc, out, err) = self.execute_command(cmd) if rc != 0:
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
self.module.fail_json(msg='Cannot user "%s" to hidden user list.' % self.name, err=err, out=out, rc=rc) return 0 else: if self.name in hidden_users: del (hidden_users[hidden_users.index(self.name)]) cmd = ['defaults', 'write', plist_file, 'HiddenUsersList', '-array'] + hidden_users (rc, out, err) = self.execute_command(cmd) if rc != 0: self.module.fail_json(msg='Cannot remove user "%s" from hidden user list.' % self.name, err=err, out=out, rc=rc) return 0 def user_exists(self): '''Check is SELF.NAME is a known user on the system.''' cmd = self._get_dscl() cmd += ['-read', '/Users/%s' % self.name, 'UniqueID'] (rc, out, err) = self.execute_command(cmd, obey_checkmode=False) return rc == 0 def remove_user(self): '''Delete SELF.NAME. If SELF.FORCE is true, remove its home directory.''' info = self.user_info() cmd = self._get_dscl() cmd += ['-delete', '/Users/%s' % self.name] (rc, out, err) = self.execute_command(cmd) if rc != 0: self.module.fail_json(msg='Cannot delete user "%s".' % self.name, err=err, out=out, rc=rc) if self.force: if os.path.exists(info[5]): shutil.rmtree(info[5]) out += "Removed %s" % info[5] return (rc, out, err) def create_user(self, command_name='dscl'):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd = self._get_dscl() cmd += ['-create', '/Users/%s' % self.name] (rc, out, err) = self.execute_command(cmd) if rc != 0: self.module.fail_json(msg='Cannot create user "%s".' % self.name, err=err, out=out, rc=rc) if self.comment is None: self.comment = self.name if self.group is None: self.group = 'staff' self._make_group_numerical() if self.uid is None: self.uid = str(self._get_next_uid(self.system)) if self.create_home: if self.home is None: self.home = '/Users/%s' % self.name if not self.module.check_mode: if not os.path.exists(self.home): os.makedirs(self.home) self.chown_homedir(int(self.uid), int(self.group), self.home)
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
if not self.system and self.shell is None: self.shell = '/bin/bash' for field in self.fields: if field[0] in self.__dict__ and self.__dict__[field[0]]: cmd = self._get_dscl() cmd += ['-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]] (rc, _out, _err) = self.execute_command(cmd) if rc != 0: self.module.fail_json(msg='Cannot add property "%s" to user "%s".' % (field[0], self.name), err=err, out=out, rc=rc) out += _out err += _err if rc != 0: return (rc, _out, _err) (rc, _out, _err) = self._change_user_password() out += _out err += _err self._update_system_user() if self.groups: (rc, _out, _err, changed) = self._modify_group() out += _out err += _err return (rc, out, err) def modify_user(self): changed = None out = '' err = '' if self.group: self._make_group_numerical()
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
for field in self.fields: if field[0] in self.__dict__ and self.__dict__[field[0]]: current = self._get_user_property(field[1]) if current is None or current != to_text(self.__dict__[field[0]]): cmd = self._get_dscl() cmd += ['-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]] (rc, _out, _err) = self.execute_command(cmd) if rc != 0: self.module.fail_json( msg='Cannot update property "%s" for user "%s".' % (field[0], self.name), err=err, out=out, rc=rc) changed = rc out += _out err += _err if self.update_password == 'always' and self.password is not None: (rc, _out, _err) = self._change_user_password() out += _out err += _err changed = rc if self.groups: (rc, _out, _err, _changed) = self._modify_group() out += _out err += _err if _changed is True: changed = rc rc = self._update_system_user() if rc == 0: changed = rc return (changed, out, err) class AIX(User):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
""" This is a AIX User manipulation class. This overrides the following methods from the generic class:- - create_user() - remove_user() - modify_user() - parse_shadow_file() """ platform = 'AIX' distribution = None SHADOWFILE = '/etc/security/passwd' def remove_user(self):
closed
ansible/ansible
https://github.com/ansible/ansible
80,267
`ansible.builtin.user`: Removing an already absent local user fails or produces a huge warning
### Summary When I try to ensure, that users are removed from a system, the task succeeds the first time and the next time, it fails as it can not remove the non-existing user from the `/etc/passwd` file. This issue could be potentially solved by adding the argument `local: true` at the task, but this results in a huge warning message for every user, which should get removed and does already not exist anymore: https://github.com/ansible/ansible/blob/ad9867ca5eb8ba27f827d5d5a7999cfb96ae0986/lib/ansible/modules/user.py#L1055-L1059 So either this behaviour is buggy when using `local: false` or the warning from `local: true` should get removed (or only printed when debug is enabled). ### Issue Type Bug Report ### Component Name ansible.builtin.user ### Ansible Version ```console $ ansible --version ansible [core 2.14.3] config file = /home/skraetzig/Git/infrastructure/ansible.cfg configured module search path = ['/home/skraetzig/Git/infrastructure/ansible/library'] ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible ansible collection location = /usr/share/ansible/third-party/collections executable location = /usr/local/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True ANSIBLE_NOCOWS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANSIBLE_PIPELINING(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ANY_ERRORS_FATAL(/home/skraetzig/Git/infrastructure/ansible.cfg) = True COLLECTIONS_PATHS(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/usr/share/ansible/third-party/collections'] CONFIG_FILE() = /home/skraetzig/Git/infrastructure/ansible.cfg DEFAULT_FILTER_PLUGIN_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/filter_plugins'] DEFAULT_FORKS(/home/skraetzig/Git/infrastructure/ansible.cfg) = 50 DEFAULT_LOCAL_TMP(env: ANSIBLE_LOCAL_TEMP) = /tmp/ansible-local-35zs1vlt9t DEFAULT_MODULE_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/library'] DEFAULT_REMOTE_USER(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy DEFAULT_ROLES_PATH(/home/skraetzig/Git/infrastructure/ansible.cfg) = ['/home/skraetzig/Git/infrastructure/ansible/roles', '/home/skraetzig/Git/infrastructure/ansible/actions', '/hom> DIFF_ALWAYS(/home/skraetzig/Git/infrastructure/ansible.cfg) = True DISPLAY_SKIPPED_HOSTS(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True INTERPRETER_PYTHON(/home/skraetzig/Git/infrastructure/ansible.cfg) = /usr/bin/python3 MAX_FILE_SIZE_FOR_DIFF(/home/skraetzig/Git/infrastructure/ansible.cfg) = 1044480 RETRY_FILES_ENABLED(/home/skraetzig/Git/infrastructure/ansible.cfg) = False CALLBACK: ======== default: _______ display_ok_hosts(env: ANSIBLE_DISPLAY_OK_HOSTS) = True display_skipped_hosts(env: ANSIBLE_DISPLAY_SKIPPED_HOSTS) = True CONNECTION: ========== local: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True paramiko_ssh: ____________ remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s psrp: ____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ssh: ___ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True remote_user(/home/skraetzig/Git/infrastructure/ansible.cfg) = deploy ssh_args(env: ANSIBLE_SSH_ARGS) = -C -o ControlMaster=auto -o ControlPersist=60s winrm: _____ pipelining(/home/skraetzig/Git/infrastructure/ansible.cfg) = True ``` ### OS / Environment Debian 10 (Buster) and 11 (Bullseye) ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: remove users ansible.builtin.user: name: "{{ item }}" state: absent remove: true with_items: - user1 - user2 - user3 ``` ### Expected Results The listed users `user1`, `user2`, `user3` get successfully removed from the system, if they exist and if not, the task should be successfull without any warning. ### Actual Results The first rollout works as expected. The users get successfully removed. All other rollouts afterwards are then failing: ```console TASK [users : remove users] **************************************************** failed: [debian] (item=user1) => {"ansible_loop_var": "item", "changed": false, "item": "user1", "msg": "userdel: cannot remove entry 'user1' from /etc/passwd\n", "name": "user1", "rc": 1} ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/80267
https://github.com/ansible/ansible/pull/80291
d664f13b4a117b324f107b603e9b8e2bb9af50c5
e0bf76e3db3e007d039a0086276d35c28b90ff04
2023-03-21T20:34:12Z
python
2023-11-23T14:25:35Z
lib/ansible/modules/user.py
cmd = [self.module.get_bin_path('userdel', True)] if self.remove: cmd.append('-r') cmd.append(self.name) return self.execute_command(cmd) def create_user_useradd(self, command_name='useradd'): cmd = [self.module.get_bin_path(command_name, True)] if self.uid is not None: cmd.append('-u') cmd.append(self.uid) if self.group is not None: if not self.group_exists(self.group): self.module.fail_json(msg="Group %s does not exist" % self.group) cmd.append('-g') cmd.append(self.group) if self.groups is not None and len(self.groups): groups = self.get_groups_set() cmd.append('-G') cmd.append(','.join(groups)) if self.comment is not None: cmd.append('-c') cmd.append(self.comment) if self.home is not None: cmd.append('-d') cmd.append(self.home) if self.shell is not None: cmd.append('-s')