Module user WARNING:Found existing ssh key

The module user

- ansible.builtin.user:
    name: root
    generate_ssh_key: true

warns about existing SSH key

[WARNING]: Found existing ssh key private file "/root/.ssh/id_rsa", no force, so skipping ssh-keygen generation

I understand that in some cases, this warning is justified. However, how can I eliminate it if the only concern is idempotency?

Assuming you don’t want to use the parameter force: true, which would generate a [WARNING] message anyway

TASK [ansible.builtin.user] ***********************************************
[WARNING]: Overwriting existing ssh key private file "/root/.ssh/id_rsa"
[WARNING]: Overwriting existing ssh key public file "/root/.ssh/id_rsa.pub"
changed: [localhost]

and you also don’t want to patch the user.py module itself at

if os.path.exists(ssh_key_file):
...

I think the only option left is to disable in Ansible Configuration Settings the ACTION_WARNINGS

By default, Ansible will issue a WARNING when received from a task action (module or action plugin). These warnings can be silenced by adjusting this setting to False.

by setting in example

grep 'defaults\|warnings' ansible.cfg
[defaults]
deprecation_warnings    = False
action_warnings         = False

and then resulting into an output of

TASK [ansible.builtin.user] ******************
ok: [localhost]

PLAY RECAP ***********************************
localhost                  : ok=1    changed=0
1 Like

Thank you. It seems it’s not possible to disable this particular warning only.

Right, that’s the case if you don’t want to introduce a parameter warn: true in the user module source as it was once available in the command and shell module and which got deprecated and removed, probably for complexity reasons.

Shall I write a sample patch and post it here?