On Thu, 28 Mar 2019 at 01:59, R-JRI <ryanjia...@gmail.com> wrote:

> Hi, all
>
> We have an application stop/start script that starts/stops application
> without root privilege and with 'sudo'.
> If I am on the host, I login as the application user and then run the
> script to stop/start application as 'sudo application_stop_start.sh
> stop/start'.
>
> On the ansible server (v2.7), I created a simple test file. The
> application user ID is the same on ansible host and remote node (ssh
> authentication has no problem)
>
>   tasks:
>     - name: run script to stop/start application
>       command: sudo /usr/local/bin/application_stop_start.sh stop
>
> It ran successfully on the remote host with a warning message.
>
> PLAY [Stop application]
> *********************************************************************************************************************************************************************************************************************
> TASK [Gathering Facts]
> **********************************************************************************************************************************************************************************************************************
> ok: [host1]
> TASK [run application_stop_start.sh script to stop application]
> **********************************************************************************************************************************************************************************************
>  [WARNING]: Consider using 'become', 'become_method', and 'become_user'
> rather than running sudo
> changed: [host1]
> PLAY RECAP
> **********************************************************************************************************************************************************************************************************************************
> host1               : ok=2    changed=1    unreachable=0    failed=0
>
> I don't need 'become' and 'become_user' at least since the UID is the
> same.
>

 'become' is used for privilege escalation. Meaning "Whether to
automatically switch user on the managed
host (typically to root) after connecting". Though you have same UIDs on
both control node and managed host, don't forget that the UID on managed
host needs root privileges to run 'application_stop_start.sh' (as you are
running sudo to run that command normally as well).

Tried to use 'become_method = sudo' and remove 'sudo' from 'command:
> /usr/local/bin/application_stop_start.sh stop' and it did not work. Does
> anyone have any suggestions?
>

You need to inform ansible about these two things:

become = true
become_user = root
become_method = sudo

Put this under ansible.cfg of your pwd and it should run fine.

-R.Rao

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAKbF63hNV9%2Bsv_11uD-3n%3DSEfmw%3D7thFnBJa-Nk24SzbhZBbqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to