Following you comment: no I cannot reproduce your problem. Since you did not provide the rest of your files (inventory, etc...) and I cannot guess where is your problem, here is a quick proof by example using the php:7.0-apache
image.
- The inventory (
inventories/docker_test/hosts.yml
)
---
all:
hosts:
docker_test:
ansible_connection: docker
- Launching the test container
docker run -d --rm --name docker_test php:7.0-apache
---
- hosts: docker_test
gather_facts: false
tasks:
# Your image does not have python which is mandatory for ansible
# Please note this is for demo only. You should get python installed
# by extending the image through a Dockerfile and build it.
- name: Dirty low-level command to get python installed
raw: apt-get update && apt-get install -y python3
- name: Gather facts now we can
setup:
- name: Copy a dummy file
copy:
dest: /etc/apache2/sites-available/dummy.conf
content: "# I'm a dummy file"
$ ansible-playbook -i inventories/docker_test/ playbook.yml
PLAY [docker_test] ********************************************************************************************************************************************************************************************************
TASK [Dirty low-level command to get python installed] ********************************************************************************************************************************************************************
changed: [docker_test]
TASK [Gather facts now we can] ********************************************************************************************************************************************************************************************
[WARNING]: Platform linux on host docker_test is using the discovered Python interpreter at /usr/bin/python3.5, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
ok: [docker_test]
TASK [Copy a dummy file] **************************************************************************************************************************************************************************************************
changed: [docker_test]
PLAY RECAP ****************************************************************************************************************************************************************************************************************
docker_test : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
remote_user
?ansible_connection=docker
is used and the inventory is correctly configured. Getting to know if using this is normal or not depends on what you actually want to do with it at the end. ansible-container is an other story, not part of OP's question as far as I can tell.remote_user: root
, which didn't change anything. The problem persists. Can you reproduce the problem? The docker container I am using isphp:7.0-apache
.