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 the shell module with sudo.

---
- name: main play
  hosts: localhost
  tasks:
  - 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.

---
- name: main play
  hosts: localhost
  tasks:
  - 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, do not use these parameters.

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

---
- name: main play
  hosts: localhost
  tasks:
  - shell: sudo example.sh
    args:
      warn: false
...

 

Because it the latest versions of Ansible, the shell module no longer includes args warn false which will 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 2dff43 in the box below so that we can be sure you are a human.