mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #16038 from larsks/docs/become-examples
docs: add some examples to the documentation for become
This commit is contained in:
commit
261b0af15a
1 changed files with 17 additions and 0 deletions
|
@ -31,6 +31,20 @@ become_user
|
||||||
become_method
|
become_method
|
||||||
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'
|
||||||
|
|
||||||
|
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
|
||||||
|
service:
|
||||||
|
name: httpd
|
||||||
|
state: running
|
||||||
|
become: true
|
||||||
|
|
||||||
|
To run a command as the ``apache`` user::
|
||||||
|
|
||||||
|
- name: Run a command as the apache uesr
|
||||||
|
command: somecommand
|
||||||
|
become: true
|
||||||
|
become_user: apache
|
||||||
|
|
||||||
Connection variables
|
Connection variables
|
||||||
--------------------
|
--------------------
|
||||||
|
@ -48,6 +62,9 @@ ansible_become_user
|
||||||
ansible_become_pass
|
ansible_become_pass
|
||||||
allows you to set the privilege escalation password
|
allows you to set the privilege escalation password
|
||||||
|
|
||||||
|
For example, if you want to run all tasks as ``root`` on a server named ``webserver``, but you can only connect as the ``manager`` user, you could use an inventory entry like this::
|
||||||
|
|
||||||
|
webserver ansible_user=manager ansible_become=true
|
||||||
|
|
||||||
New command line options
|
New command line options
|
||||||
------------------------
|
------------------------
|
||||||
|
|
Loading…
Reference in a new issue