2 years ago
#56057
eto3542
How to become a user with root priveleges in ansible
I am setting up a playbook that automatically configures my workstation. This will hopefully allow me to quickly install linux somewhere and automatically have all the resources I need.
One of the steps is installing homebrew and I cannot figure out how to do it.
I have created this playbook
- hosts: localhost
become: yes
become_user: myUser
tasks:
- name: Download homebrew install script from source
get_url:
url: https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
dest: ~/Downloads/install_homebrew.sh
mode: 'u+rwx'
- name: Install homebrew
shell: ~/Downloads/install_homebrew.sh
and run it with ansible-playbook myplaybook.yaml
.
However, when I execute it, there is a permission denied error. Apparently this is because of how the copy
-module works (here). So I thought I'd just run the sudo ansible-playbook myplaybook.yaml
instead. This leads to the exact same permission error. I guess this is because I have become_user: myUser
.
However, when i remove become_user
, I obviously get another error Destination /root/Downloads does not exist
because my destination is coded to the users download-directory.
So how can I execute the playbook as the user myUser
but with root privileges? This would allow me to access the root-stuff but still refer to my home-directory. In theory this should be possible since I can run
sudo ls -a /root && ls ~/
and get both the content of the root-folder and of my home directory. But I don't know how to do this in ansible.
ansible
ansible-2.x
0 Answers
Your Answer