2

I have an ansible playbook which installs docker. It looks like this:

---
- hosts: local
  connection: local
  become: yes
  become_user: root
  tasks:
    - name: add docker's key
      apt_key:
        keyserver: hkp://p80.pool.sks-keyservers.net:80
        id: 58118E89F3A912897C070ADBF76221572C52609D

    - name: add deb repo
      file: path=/etc/apt/sources.list.d/docker.list state=touch

    - name: register apt sources
      lineinfile: dest="/etc/apt/sources.list.d/docker.list" line="{{item}}"
      with_items:
      - "deb https://apt.dockerproject.org/repo ubuntu-trusty main"

    - name: install docker-engine
      apt: name=docker-engine state=present update-cache=yes force=yes

The problem is that when I run this playbook on my localhost I get an error:

fatal: [127.0.0.1]: FAILED! => {"changed": false, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}

So what parts of this playbook may cause such an error and how can I change them?

Cassie
  • 2,941
  • 8
  • 44
  • 92

1 Answers1

16

Try to use --ask-become-pass with your command line. You should then be prompted for the password.

vmonteco
  • 14,136
  • 15
  • 55
  • 86
  • I have tried that. But I am not sure that it is a good solution for long-term – Cassie Dec 04 '17 at 14:51
  • @Cassie Well the other solution implying a password would be to somehow store the password which wouldn't necessarly be better. Perhaps you'd be able to find some trick to store the password in a vault file but you'd need to enter an other password to unlock the vault file anyway. If you expected a different workflow than password use you should describe it in your question. – vmonteco Dec 04 '17 at 15:03
  • Ok, thanks for the help! – Cassie Dec 04 '17 at 15:04
  • I think long-term best practice is now store password in the vault. --ask-become-pass is now deprecated, too. – realtebo Jul 31 '18 at 23:08