2

I'm getting 'msg: Failed to lock apt for exclusive operation' when trying to install some dependencies in a playbook using apt, with the vagrant user. I'm suspecting it tells me this because it can't authenticate the vagrant user while running the task.

This is the role declaration I'm using.

- name: ruby installer
  hosts: all
  sudo: True
  sudo_user: vagrant
  roles:
  - ruby

And this is the task that fails:

    - name: Install ruby building dependencies
      apt: name={{ item }} 
           state=installed 
           update_cache=yes

      with_items:
      - dependency

When removing "update_cache=yes" and re-running the playbook I'm getting: E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

Obviously when running it with root it works perfectly fine, but I need it to run under a different user other then root because of some ruby (rvm, rbenv specific) tasks.

How do I properly authenticate the vagrant user when running my playbook? Can someone point me in the right direction?

5

I ended up with this role declaration:

- name: ruby installer
  hosts: all
  sudo: True
  user: vagrant
  roles:
  - ruby

And this task for installing the dependencies:

- name: Install ruby building dependencies
  apt: name={{ item }} 
       state=installed 
       update_cache=yes
  sudo_user: root

  with_items:
  -dependency

It now uses root for the apt task and vagrant for the other ruby tasks in the playbook.

0

apt installs system-level packages and as such, using apt requires root-equivalent privileges.

If you need to perform further application deployment steps as a different user, you will need to pull those steps out of your deb package installation process.

1
  • Can you be more specific? How do I pull those steps out of the deb package installation process? Is there a way to 'sudo' the vagrant user in Ansible, and avoid using the root user? Thanks. – Hyperfocus Jan 15 '14 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.