-1

I am using Ansible local inside a Packer script to configure a Docker image. I have a role test that has a main.yml file that's supposed to output some information and create a directory to see that the script actually ran. However, the main.yml doesn't seem to get run.

Here is my playbook.yml:

---
- name: apply configuration
  hosts: all
  remote_user: root
  roles:
   - test

test/tasks/main.yml:

---
- name: Test output
  shell: echo 'testing output from test'
- name: Make test directory
  file: path=/test state=directory owner=root

When running this via packer build packer.json I get the following output from the portion related to Ansible:

docker: Executing Ansible: cd /tmp/packer-provisioner-ansible-local/59a33ccb-bd9f-3b49-65b0-4cc20783f193 && ANSIBLE_FORCE_COLOR=1 PYTHONUNBUFFERED=1 ansible-playbook /tmp/packer-provisioner-ansible-local/59a33ccb-bd9f-3b49-65b0-4cc20783f193/playbook.yml --extra-vars "packer_build_name=docker packer_builder_type=docker packer_http_addr="  -c local -i /tmp/packer-provisioner-ansible-local/59a33ccb-bd9f-3b49-65b0-4cc20783f193/packer-provisioner-ansible-local037775056
docker:
docker: PLAY [apply configuration] *****************************************************
docker:
docker: TASK [setup] *******************************************************************
docker: ok: [127.0.0.1]
docker:
docker: PLAY RECAP *********************************************************************
docker: 127.0.0.1                  : ok=1    changed=0    unreachable=0    failed=0

I used to run a different more useful role this way and it worked fine. I hadn't run this for a few months and now it stopped working. Any ideas what I am doing wrong? Thank you!

EDIT: here is my packer.json:

{
  "builders": [
    {
      "type": "docker",
      "image": "ubuntu:latest",
      "commit": true,
      "run_command": [ "-d", "-i", "-t", "--name", "{{user `ansible_host`}}", "{{.Image}}", "/bin/bash" ]
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "inline": [
        "apt-get -y update",
        "apt-get -y install ansible"
      ]
    },
    {
      "type": "ansible-local",
      "playbook_file": "ansible/playbook.yml",
      "playbook_dir": "ansible",
      "role_paths": [
          "ansible/roles/test"
      ]
    }
  ]
}
ajmurmann
  • 1,605
  • 3
  • 16
  • 24
  • 1
    Please post an [MCVE](https://stackoverflow.com/help/mcve). – techraf Aug 28 '17 at 00:04
  • What output did you get and what command did you run? – whites11 Aug 28 '17 at 06:20
  • @techraf @whites: All I have that's related to Ansible itself was already there in my post above including the command Packer runs Ansible with. However, I added my packer.json file above and clarified that I am running via the standard `packer build packer.json`. No flags or anything. If more output from the Packer run is needed I can post it, but it's all just pulling docker images and apt-get install stuff from installing Ansible. No warning or anything unusual there. – ajmurmann Aug 29 '17 at 00:40
  • 1
    How do you expect anyone to verify the example you posted? (V of MCVE) I, for example, created a role with the code you included and the tasks in `main.yml` execute properly. Yesterday as well as today. Shall I also wait a few months? Because you included that - vital, I presume - information for some reason. – techraf Aug 29 '17 at 00:48
  • @techraf You already have all the code I have, what else am I supposed to provide for the MCVE? If it works on your machine that's already super helpful piece of information and I wonder if something changed with the Ubuntu image Docker pulls or the Ansible version on there. Which is why it was relevant that this used to work a few months ago. Thank you! – ajmurmann Aug 29 '17 at 00:58
  • Sorry to disappoint you, but the only thing that proves is that you posted too little information to reproduce the problem. Read the article linked in my first comment and follow the suggestions. – techraf Aug 29 '17 at 01:01
  • @ajmurmann a similar setup is not working for me as well. What are the versions of you packer, ansible and docker? The playbook runs okay but the roles are not getting executed for some reason. If you found any solution, help would be much appreciated. – Pratik Saha Aug 30 '17 at 08:08
  • 1
    I am using ansible 1.9, Docker version 17.06.1-ce, build 874a737 on Ubuntu 16.04, and packer latest stable. – Pratik Saha Aug 30 '17 at 08:14
  • @PratikJoy I am using packer 1.0.4, but since I posted dug deeper and found that it works with 0.12.0. My guess right now is that a breaking change introduced in 0.12.3 broke my setup. See the change at https://github.com/hashicorp/packer/blob/master/CHANGELOG.md#0123-march-1-2017 and discussion here: https://github.com/hashicorp/packer/issues/4680 My initial assumption was that because of this the role dir is incorrect. However, if the path is wrong you actually get an exception and not just a no-op. I am pretty sure I can get back to this on the weekend and post a fix. – ajmurmann Aug 31 '17 at 14:21
  • @PratikJoy Did my answer below resolve your issue as well? – ajmurmann Sep 04 '17 at 17:44
  • @ajmurmann I will try and let you know. – Pratik Saha Sep 05 '17 at 05:11

1 Answers1

0

This seems to be due to a bug in Packer. Everything works as expected with any Packer version other than 1.0.4. I recommend either downgrading to 1.0.3 or installing the yet to be released 1.1.0 version. My best guess is that this is being caused by a known and fixed issue about how directories get copied by the docker builder when using Ansible local provisioner.

ajmurmann
  • 1,605
  • 3
  • 16
  • 24