My playbook has a task to copy a file from the local box to the remote box and the last task has to use sudo to root. I am not getting it to work.
In my inventory I am trying to use I am just trying to get it to work then I can lock it down with ansible vault. I just need to see it work first.
[logserver]
mylogserver ansible_ssh_user=myuser ansible_become_password=mypassword
In my playbook the last task using the -host param to do the work on the remote box, earlier task copies file to remote server but then I add a remote host to get the work done.
# Cat file and append destination file
- name: cat files to destination file
hosts: mylogserver
gather_facts: no
become_exe: "sudo su - root"
tasks:
- name: cat contents and append to destination file
shell:
cmd: /usr/bin/cat /var/tmp/test_file.txt >> /etc/some/target_file.txt
For example, the inventory
and the playbook
work as expected
Notes:
Configuration of the method, e.g.
become_method: su, is missing. See DEFAULT_BECOME_METHOD. The default is 'sudo'. For details see Using Become PluginsSee details of the plugin from the command line
shell> ansible-doc -t become suUse become_flags to specify options to pass to su, e.g.
become_flags: -lUse become_user to specify the user you 'become' to execute the task, e.g.
become_user: root. This example is redundant. 'root' is the defaultSpecify
become: trueif the task shall use the configured escalation. The default is 'false'. See DEFAULT_BECOMEConfigure sudoers, e.g.
gives
Encrypt the password