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

Let's consider the following task.

- shell: "sudo"


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

# command_warnings = False


. . . using 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. This recommendation is strongly suggested. Refer to Ansible - become parameter to understand become.

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

- shell: "sudo"
    warn: false


Or, you could set comment_warnings to false in ansible.cfg, like this. However, this is probably to permissive, as any command that would generate a warning would no longer generate a warning.

command_warnings = False



Be aware that if warn: false is used, then you will not be able to register output to a variable (e.g. register: out) nor would you be able to use the when parameter to evaluate the output since no output would be registered.

For example, let's say you try something like this. This should return some sort of error since 'out.rc' would be undefined due to warn: false.

- shell: "sudo"
    warn: false
  register: out
  failed_when: out.rc not in [ 0, 1 ]


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

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


Web design by yours truely - me, myself, and I   |   |