Open justinmayer opened 6 years ago
What is the exact ansible-container
command you are running, and from which directory are you running it? It sounds like you might need to be using the --src-mount-path
option of build
.
Exact command: ansible-container build
Running command from: project_root/deploy
@treyd: Does that help narrow down potential causes of this problem?
@justinmayer
I have similar setup, and I do resolve that in the following way:
on my makefile I have specified path to my "real code root"
# path to service
CODE_PATH=$(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/../../
and on build I am passing it via --src-mount-path
build: p-env/bin/ansible-container
@echo ansible-container --vars-files vars_$(IMAGE_BASE).yml --debug --project-name $(ROLE_NAME) build --roles-path ./roles/ --src-mount-path $(CODE_PATH) -- -vvv
@p-env/bin/ansible-container --debug --project-name $(ROLE_NAME) build --no-container-cache --roles-path ./roles/ --src-mount-path $(CODE_PATH) -- -vvv
Step of copiing sources to container from that location - it is synchronize
module now.
- name: Copy source into container
synchronize:
src: "/src/{{application_artifact_path}}"
dest: "/app"
@justinmayer I think you need to use --src-mount-path
(e.g. --src-mount-path project_root
) and refer to the parent directory you want to have access to in your roles. The src directory is a bind-mount into the conductor, and so from within the conductor you can't get access to its parents.
@justinmayer is issue still actual ?
I can confirm still seeing this.
No matter what I do, I'm unable to copy
or synchronize
files:
remote_src=yes
)In essence, I cannot get either copy
or synchronize
to work with ansible-container
. So I'm wondering how this is typically done.
I can provide more details if you have any specific questions, since I have setup to test/confirm with.
Mentioned part for sure works. Compare approaches below with the one you are using.
https://github.com/softasap/sa-container-bootstrap/tree/master/box-example/alpine-35 fallback to packer: https://github.com/softasap/sa-container-bootstrap/tree/master/box-example-packer/alpine-35
If source is out of context , you can use --src-mount-path switch
ansible-container --vars-files vars_$(IMAGE_BASE).yml --debug --project-name $(ROLE_NAME) build --roles-path ./roles/ --src-mount-path $(CODE_PATH) -- -vvv
Play part for example above might look like
- name: Copy source into container
synchronize:
src: "/src/src"
dest: "/app"
- name: Copy migrations into container
synchronize:
src: "/src/migrations"
dest: "/app"
- name: Copy requirements.txt into container
synchronize:
src: "/src/requirements.txt"
dest: "/app"
- name: Copy start.sh into container
synchronize:
src: "/src/start.sh"
dest: "/app"
- name: Install Python dependencies
pip:
requirements: /app/requirements.txt
executable: "{{container_pip}}"
- name: RUNIT | Creating /etc/service/payment
file: path="/etc/service/app" state="directory"
- name: RUNIT | Template /etc/service/payment/run
template: src="{{role_dir}}/templates/application.runit.j2" dest="/etc/service/app/run" mode="u=rwx,g=rx,o=rx"
I've searched existing issues, including the tangentially-related #393, but I've yet to find a solution.
ISSUE TYPE
container.yml
OS / ENVIRONMENT
SUMMARY
We store Ansible-related configuration at in a sub-directory of the project root — not in the project root itself. So
ansible.cfg
,container.yml
, roles, etc. are all stored inproject_root/deploy
.Given this set-up, I cannot figure out how to get the project code synchronized/copied into the container.
STEPS TO REPRODUCE
The following task, for example, only synchronizes the sub-directory (
project_root/deploy
) and not the desiredproject_root
parent directory:No matter what local source path values I try for
src:
— includingsrc: /Users/justin/Projects/foo
, the full absolute path to the project root — a "directory not found" error is returned (even though the specified paths definitely exist):EXPECTED RESULTS
I expected to be able to find some way to synchronize/copy the parent folder of the current working directory into the container.
ACTUAL RESULTS
I cannot find any way to synchronize/copy the parent folder of the current working directory into the container.