Bootstrap FreeKB - Ansible - warnings parameter (warn: true, warn: false)
Ansible - warnings parameter (warn: true, warn: false)

Updated:   |  Ansible articles

Let's say you are using shell with sudo.

---
- hosts: localhost
  tasks:
  - ansible.builtin.shell: sudo example.sh
...

 

Assuming the following option is commented out in ansible.cfg or set to true . . .

# command_warnings = False

 

sudo will return the following warning. 

[WARNING]: Consider using 'become', 'become_method', and 'become_user' rather than running sudo

 

As the warning suggest, you should consider using the become parameters instead of sudo. Refer to Ansible - become parameter to understand become.

---
- hosts: localhost
  tasks:
  - ansible.builtin.shell: example.sh
    become: yes
    become_user: root
...

 

If you can't go with become, then you can temporarily set the ANSIBLE_COMMAND_WARNINGS variable to false. Be aware that you would have to reset this variable each time you establish an SSH session onto the system that you use to run Ansible.

export ANSIBLE_COMMAND_WARNINGS=false

 

Or you can add the following to ansible.cfg.

command_warnings = False

 

While it might be tempting to include args warn false, I strongly suggest that you do not use these parameters as you are then just ignoring something problematic.

If you want to continue to use sudo, you can then disable this warning by setting warn to false, like this.

---
- hosts: localhost
  tasks:
  - ansible.builtin.shell: sudo example.sh
    args:
      warn: false
...

 

Be aware that based on the version of Ansible you are using, the shell module maybe no longer includes args warn which should cause the following fatal error to be returned.

TASK [shell]
Fatal: [localhost]: FAILED! => {"changed": false, "msg": “Unsupported parameters for (ansible.legacy.command) module: warn"

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 4c9a9a in the box below so that we can be sure you are a human.