*FIX* [DEPRECATION WARNING]: DEFAULT_SUDO_USER option

The have been several posts asking how to fix the following warning, without a clear answer (IMO).

[DEPRECATION WARNING]: DEFAULT_SUDO_USER option, In favor of Ansible Become, which is a generic framework. See become_user. , use become instead. This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

You need to edit the ansible.cfg file

$ sudo vim /etc/ansible/ansible.cfg

Comment out the "sudo_user" option set in the "[defaults]" section.

[defaults]

....

#sudo_user = root

remove the comment from all lines in the "[privilege_escalation]" section

[privilege_escalation]

become=True

become_method=sudo

become_user=root

become_ask_pass=False

You should no long get the deprecation warning when you run ansible commands.

  • post-author-pic
    Terrence C
    09-30-2018

    That will do it, good timing since it will be removed completely and will just error out in v2.8 when it comes out - thanks for sharing!

  • post-author-pic
    Harald D
    01-02-2019

    Does that use root all the time? Example:


    [ansible@vm-ansible test]$ ansible centos -m copy -a "src=test.txt dest=/tmp/test.txt"

    node01 | SUCCESS => {

    "changed": false,

    "checksum": "6476df3aac780622368173fe6e768a2edc3932c8",

    "dest": "/tmp/test.txt",

    "gid": 0,

    "group": "root",

    "mode": "0644",

    "owner": "root",

    "path": "/tmp/test.txt",

    "secontext": "unconfined_u:object_r:user_home_t:s0",

    "size": 15,

    "state": "file",

    "uid": 0

    }

    [ansible@vm-ansible test]$ ssh node01 "ls -l /tmp/test.txt"

    -rw-r--r--. 1 root root 15 Jan 2 14:29 /tmp/test.txt

Looking For Team Training?

Learn More