Open claudiol opened 5 years ago
Currently have a solution in the buildah_copy_update branch for this. Not too happy with the solution since it only focuses on the local copy of the file. I've added code to support the following playbook:
buildah_copy:
name: c3897c41ac18 # <=== target container
src: 'local:/tmp/file.conf" # <=== file that exists on current host
dest: 'buildah_host:/tmp/file.conf' # <=== destination file on target container storage
register: result
connection: local <==== As you can see I am making this play local
The current implementation scp's the file from the local machine to the target host. The challenge here is that in order for us to do any 'chown', or 'chmod' on the target host it won't actually work since those are arguments that will be passed to buildah to execute once the file gets to the container.
This is a start. We need more exploring on this. I have looked at the copy: module inside of Ansible to see what we can leverage from that module. At the end of the day the play would look like this:
buildah_copy:
name: c3897c41ac18 # <=== target container that is not used for this play
src: 'local:/tmp/file.conf" # <=== file that exists on current host
dest: 'buildah_host:/tmp/file.conf' # <=== destination file on target container storage
register: result
connection: local <==== As you can see I am making this play local
buildah_copy:
name: c3897c41ac18 # <=== target container
src: '/tmp/file.conf" # <=== file that exists on target buildah host
dest: '/etc/file.conf' # <=== destination file on target container storage
register: result
The above looks very similar to just using the copy: module which is why I am not merging this to our main branch.
Currently all the buildah Ansible modules pass through the src:
buildah add [command options] CONTAINER-NAME-OR-ID [FILE | DIRECTORY | URL] [[...] DESTINATION]
The current buildah_add module is called like so:
hosts: buildah <== target host become: yes
tasks:
The src and dest parameters are currently executed in the target host, which contains the container, and runs the sudo buildah add HelloWorld.txt /tmp/HelloWorld.txt command.
What we would like to do is have a remote_src boolean | Choices: no ← yes parameter in the module that will let us know whether to treat src as a local or remote source.
If remote_src equals no, it will search for src at originating/master machine. If remote_src equals yes it will go to the remote/target machine for the src. Default should be no.
This behavior is similar existing Ansible modules such as copy.
The trick will be that we will have to copy the file to the target host before executing the buildah add command on the target host.