On 15. sep. 2016 17:10, Charles Moga wrote:
> Hello,
> I hope someone can answer this. I have a bunch of commands (shell scripts )
> in a specific directory I need to run as root user. So I do:
>
> - name: Becoming root
> command: sudo su -
>
> - name: Changing directory
> command: cd "{{ command_directory }}"
>
> - name: Sourcing commands
> command: source mycommand.sh
You can't use Ansible like this.
This is three individual tasks, so the "sudo su -" would run but does
not have any impact on the next command.
And the cd will not change the path for the next command.
I highly recommend reading a Ansible book and/or reading this
https://docs.ansible.com/ansible/playbooks_intro.html
to get a basic understanding of how Ansible work.
To run tings as sudo or su you need to use become
https://docs.ansible.com/ansible/become.html
Ansible can't stack sudo and su, like "sudo su -". You need to pick one
of them.
--
Kai Stian Olstad