Docker builder: Ansible "copy" fails: Unable to find src in expected paths

1,126 views
Skip to first unread message

Chris Stevens

unread,
Mar 7, 2017, 3:51:03 PM3/7/17
to Packer
I am using the ansible (remote) provisioner with the docker builder and latest packer (0.12.3).

In this simple case, I am trying to copy the files for my application to the document root of an nginx base image:
- name: Copy files to the release path
  copy:
    src:  ../app
    dest: "{{ deploy_path }}"

It fails with:

    docker: TASK [Copy files to the release path] ******************************************

    docker: fatal: [default]: FAILED! => {"changed": false, "failed": true, "msg": "Unable to find '../app' in expected paths."}



Whereas this attempt to template a single file from approximately the same source tree *does* work:
- name: Ensure the nginx configuration is installed
  template:
    src:  ../nginx/nginx.conf
    dest: /etc/nginx/nginx.conf

Ansible "copy" of a single file from the same source tree also works.

The packer definition looks like this:
  "builders": [{
    "type": "docker",
    "image": "nginx:1.11.10-alpine",
    "commit": true,
    "run_command": [
        "-d", "-i", "-t", "--name", "{{user `ansible_host`}}",
        "{{.Image}}", "/bin/sh"
    ]
  }],
  "provisioners": [
    {
      "type": "shell",
      "inline": [
        "apk --update --no-cache add python"
      ]
    },
    {
      "type": "ansible",
      "ansible_env_vars": [
        "ANSIBLE_ROLES_PATH={{user `ansible_roles_path` }}"
      ],
      "user": "root",
      "playbook_file": "./provision/packer/nginx.yml",
      "extra_arguments": [
        "-e", "ansible_host={{user `ansible_host`}}",
        "-e", "ansible_connection={{user `ansible_connection`}}"
      ]
    }
  ],

I've also tried a similar packer build with a php:7.0.16-fpm-alpine base image. Same fail and success outcomes for the ansible "copy" vs ansible "template" steps shown previously.

Has anybody encountered this before?
Could this be an "scp" vs "sftp" thing?
Could this be an issue because the images are based on Alpine?

Alvaro Miranda Aguilera

unread,
Mar 7, 2017, 4:33:14 PM3/7/17
to packe...@googlegroups.com
per ansible documentation it seems copy module copy files only.

have a look at this



--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/e38f8861-5f85-4ca0-b0f1-7b530fdd42b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Chris Stevens

unread,
Mar 7, 2017, 4:43:18 PM3/7/17
to Packer
Thanks for the link, but I'm not sure that's the issue.

I use ansible copy outside of packer and docker already.

The module docs talk about recursive copies based on what the "src" is set to:
http://docs.ansible.com/ansible/copy_module.html

To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.



--
Alvaro

Chris Stevens

unread,
Mar 7, 2017, 4:49:42 PM3/7/17
to Packer
I'm temporarily using the packer "file" provisioner, but want to keep all of the tasks centralized within Ansible.

My issue sounds similar to this thread:
https://groups.google.com/d/msg/packer-tool/KKvIQzQSuec/84etjDG6AQAJ

In that thread, there is a comment about the sftp server not existing within the distro:

In my case with Alpine, there is no sftp server.

However, it looks like scp support was added to the ansible provisioner in 2016 and made the default:

Alvaro Miranda Aguilera

unread,
Mar 7, 2017, 4:53:12 PM3/7/17
to packe...@googlegroups.com
I see

thanks for the explanation. missed that.



--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/480ee4dc-0b01-451b-bcd9-292d9fd3c9a4%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Rickard von Essen

unread,
Mar 7, 2017, 7:49:18 PM3/7/17
to packe...@googlegroups.com
Could you provide the values for your user vars and the output when you run ansible with -vvvv.

Chris Stevens

unread,
Mar 8, 2017, 10:35:12 AM3/8/17
to Packer
Hi Rickard,

Thanks for your help!

I created the following gist:

The gist has a very simplistic application with a few files.

One of the problems with the copy operation appears to be that I needed a trailing slash on the "deploy_path" variable. Without it, the build would fail almost immediately at that step. With it, the build represented by the gist completes within a few seconds.

When the same playbook and packer file are run against my real "app" directory with thousands of files, I can see the ansible copy module iterating over those files. Hence the "hangs indefinitely" notes. It likely will finish, but it looks like I'm bumping against the limits of the copy module as noted in the ansible docs.

Unless you see anything that I should be doing differently, I think I'll have to let Packer copy the files into the running container during the build.

My plan is to run the builder from a workstation or CI system where the code is already checked out from git to the ansible control host.

- Chris

Chris Stevens

unread,
Mar 8, 2017, 12:54:06 PM3/8/17
to Packer
Additional question since I'm new to the docker builder:

Should the "run_command" overwrite the CMD from the base image?

It seems like it is.

The nginx alpine base image Dockerfile sets:
CMD ["nginx", "-g", "daemon off;"]

When I run a container from the packer-built image, it exits immediately and "/bin/sh" shows as the COMMAND in "docker ps -a"

When I add a "changes" item to the docker builder with the CMD I need, it works:
"CMD [\"nginx\", \"-g\", \"daemon off;\"]",

I was expecting the existing CMD from the Dockerfile to remain and the "run_command" only control the container during the build step.
Reply all
Reply to author
Forward
0 new messages