Ansible git clone as root

1.7k views Asked by At

I'm using the following role for Ansible in order to clone a project in my vagrant setup:

- name: Clone Repository
   git: 
     repo: https://login:[email protected]/team/repo.git 
     dest: /home/vagrant/workspace/ 
     accept_hostkey: true

The cloning is working as expected, but the main issue is that the directory workspace and all it's content is now owned by root:

drwxr-xr-x 7 root    root    4096 Jun 10 12:35 workspace

I was thinking that those command were executed by 'vagrant' user as I defined in my playbook:

- hosts: vagrant
  sudo: yes 
  remote_user: vagrant
  roles:
    - git

Can you guys help me with this issue?

Thank you.

2

There are 2 answers

0
Antonis Christofides On BEST ANSWER

remote_user: vagrant means that it will ssh into the host as user vagrant. sudo: yes means that before executing each task it will sudo, by default to root. You need to remove sudo: yes.

1
Bharath Chandra Nannaka On