Karthik T
Karthik T

Reputation: 31952

Ansible file module throws a error when trying to recursively set ownership on files

The task is

- name: ensure rvm install path is writable by the set owner:group
  file: path='{{ rvm1_install_path }}' state=directory recurse=yes owner='{{ rvm1_user }}' group='{{ rvm1_group }}'

And I get

TASK: [rvm_io.rvm1-ruby | ensure rvm install path is writable by the set owner:group] ***
failed: [54.68.205.15] => {"failed": true, "gid": 111, "group": "jenkins", "item": "", "mode": "0755", "owner": "jenkins", "path": "/var/lib/jenkins/.rvm", "size": 4096, "state": "directory", "uid": 106}
msg: chgrp failed

FATAL: all hosts have already failed -- aborting

The folders exist already.

I am using

sudo: true
sudo_user: jenkins

Since my ssh user is ubuntu.

This is part of my issue with the ansible role provided by rvm, but it feels like this might not be too closely related to RVM.. hence im asking here, but not sure.

Upvotes: 2

Views: 10310

Answers (1)

300D7309EF17
300D7309EF17

Reputation: 24613

Your jenkins user doesn't have permission to create the directory or set permissions. Further, if any files/directories exist and are owned by someone other than jenkins, the jenkins user won't be able to chown them.

That's why chgrp fails. You need superuser permissions, and hopefully the jenkins user is very limited in permissions.

This is probably what you intended:

- name: ensure rvm path exists
  file: path='{{ rvm1_install_path }}' state=directory recurse=yes owner='{{ rvm1_user }}' group='{{ rvm1_group }}'
  sudo: yes
  sudo_user: root
- name: all rvm files should be owned by our user
  file: path='{{ rvm1_install_path }}' recurse=yes owner='{{ rvm1_user }}' group='{{ rvm1_group }}'
  sudo: yes
  sudo_user: root

Upvotes: 6

Related Questions