Ansible 未执行 main.yml

Ansible not executing main.yml

我在 Packer 脚本中使用 Ansible local 配置 Docker 图像。我有一个角色 test,它有一个 main.yml 文件,该文件应该输出一些信息并创建一个目录来查看脚本实际上 运行。但是,main.yml 似乎没有得到 运行。

这是我的 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

当通过 packer build packer.json 运行 时,我从与 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

我曾经通过这种方式 运行 扮演不同的更有用的角色,而且效果很好。我有几个月没有 运行 这个了,现在它停止工作了。知道我做错了什么吗?谢谢!

编辑: 这是我的 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"
      ]
    }
  ]
}

这似乎是由于 Packer 中的一个错误。对于 1.0.4 以外的任何 Packer 版本,一切都按预期工作。我建议降级到 1.0.3 or installing the yet to be released 1.1.0 版本。 我最好的猜测是,这是由一个已知​​的 fixed issue 引起的,即在使用 Ansible 本地供应器时 docker 构建器如何复制目录。