I have an ansible playbook that uses become to gain root access on the remote hosts using
become: yes
I also have some pre_tasks that have to run local commands at the ansible host in before.
How can I force this local tasks to be executed with the default user (the user that runs ansible-playbook)?
Here is my playbook (it is meant to perform a local copy operation as default user as a pre task):
---
- hosts: all
vars:
proprietary_files: "/some/files/not/managed/by/vcs"
filesToWorkOnLater: "config_files"
pre_tasks:
- name: "Copy from {{proprietary_files}} to {{filesToWorkOnLater}}"
local_action:
module: copy
src: "{{proprietary_files}}/"
dest: "{{filesToWorkOnLater}}/"
become: yes
roles:
...
...
At the moment I'am getting complains from my local machine like
sudo: a password is required
Using command with delegate_to and become: no instead of local_action works:
---
- hosts: all
vars:
proprietary_files: "/some/files/not/managed/by/vcs"
filesToWorkOnLater: "config_files"
pre_tasks:
- name: "Copy from {{proprietary_files}} to {{filesToWorkOnLater}}"
command: cp -r {{proprietary_files}}/ {{filesToWorkOnLater}}/
delegate_to: localhost
become: no
become: yes
roles:
...
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With