Dimitri,
- shell: "su - root"
args:
warn: false
- shell: '/scripts/dnscopy.pl -f'
register: (result)
You are running 2 separate shells. First shell runs su - root then exits -
this is not doining anything. Then secon task runs in a new shell, you are
not leveraging the previous "su - root". You are using become: yes, and
that should be sufficient to elevate task's rights, so the second task
should work anyway. Try this:
Remove
- shell: "su - root" task
replace it with:
- shell: "whoami"
register: who
- debug: var=who
to check under which user is your script executing. If it's not 'root'
then you messed up, if it is 'root' but your script still fails, you have a
problem with your script.
Piotr
pon., 3 gru 2018 o 23:22 Dimitri Yioulos <[email protected]> napisaĆ(a):
> OK:
>
> ---
>> - hosts: all
>> gather_facts: false
>> become: yes
>> # become_user: root
>> # become_method: su
>> tasks:
>> - shell: "su - root"
>> args:
>> warn: false
>> - shell: '/scripts/dnscopy.pl -f'
>> register: (result)
>> - debug:
>> var: (result)
>> verbosity: 2
>
>
> *become_user and become_method are commented out in favor of shell: "su -
> root" because using the former causes a timeout error, But that's another
> issue.
>
> Output of play:
>
> TASK [command]
> ***************************************************************************************************************************************************************************
> fatal: [admin1]: FAILED! => {"changed": true, "cmd": "/scripts/dnscopy.pl
> -f", "delta": "0:00:01.425695", "end": "2018-12-03 17:13:56.113927",
> "failed": true, "rc": 2, "start": "2018-12-03 17:13:54.688232", "stderr":
> "Can't exec \"rndc\": No such file or directory at /scripts/dnscopy.pl
> line 296.\nrndc -s dns1 reload failed: No such file or directory at
> /scripts/dnscopy.pl line 296.", "stderr_lines": ["Can't exec \"rndc\": No
> such file or directory at /scripts/dnscopy.pl line 296.", "rndc -s dns1
> reload failed: No such file or directory at /scripts/dnscopy.pl line
> 296."], "stdout": "", "stdout_lines": []}
>
> without the -f switch, the play completes successfully.
>
>
> On Monday, December 3, 2018 at 11:44:08 AM UTC-5, Dimitri Yioulos wrote:
>>
>> Hey, all.
>>
>> I need to run a script residing on the remote machine with a switch, as
>> in "/scripts/myscript -f" (it must be executed by root). I'm using the
>> shell module, but can find no way to add the switch without the play
>> failing. Help would be appreciated.
>>
>> Dimitri
>>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/ef043055-1226-4a41-862f-2a3c66097b4c%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/ef043055-1226-4a41-862f-2a3c66097b4c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CACHJvyM0V_ubpG306Zxd3P4W76ZwDOmLT6WbrnWMpkCdHM5hNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.