Working on the test suite, I tried to replace a call to sudo to a
call to su, and found out that I can't change user to 'nobody'
without changing the option become_flags in ansible.cfg
As this would be dependent on the user and the task, it make more sense
to push the setting there.
pull/17306/head
Michael Scherer9 years agocommitted byToshio Kuratomi
(at play or task level) overrides the default method set in ansible.cfg, set to `sudo`/`su`/`pbrun`/`pfexec`/`doas`/`dzdo`
(at play or task level) overrides the default method set in ansible.cfg, set to `sudo`/`su`/`pbrun`/`pfexec`/`doas`/`dzdo`
become_flags
(at play or task level) permit to use specific flags for the tasks or role. One common use is to change user to nobody when the shell is set to no login
For example, to manage a system service (which requires ``root`` privileges) when connected as a non-``root`` user (this takes advantage of the fact that the default value of ``become_user`` is ``root``)::
For example, to manage a system service (which requires ``root`` privileges) when connected as a non-``root`` user (this takes advantage of the fact that the default value of ``become_user`` is ``root``)::
- name: Ensure the httpd service is running
- name: Ensure the httpd service is running
@ -46,6 +49,15 @@ To run a command as the ``apache`` user::
become: true
become: true
become_user: apache
become_user: apache
To do something as the ``nobody`` user when the shell is nologin::
- name: Run a command as nobody
command: somecommand
become: true
become_method: su
become_user: nobody
become_flags: '-s /bin/sh'
Connection variables
Connection variables
--------------------
--------------------
Each allows you to set an option per group and/or host, these are normally defined in inventory but can be used as normal variables.
Each allows you to set an option per group and/or host, these are normally defined in inventory but can be used as normal variables.