I'm trying to use my existing docker playbooks to provision a docker container using ubuntu 18.04 for local development.
I'm having trouble running playbooks on the container as it does not come with python installed, so from my understanding ansible cannot run.
Is there a way i can install python on the container so that my playbooks can run?
NB I know that ansible-container exists but i would like to use my existing playbooks which use become_user and that doesn't work as stated on the build instructions
You'll need to add your Docker container to the ansible inventory before you can target it in your playbooks. Something like this would work:
---
- hosts: localhost
gather_facts: false
tasks:
- name: create container
docker_container:
name: ansible-test
image: ubuntu:bionic
command: bash
detach: true
interactive: true
tty: true
- name: add docker container to inventory
add_host:
name: ansible-test
ansible_connection: docker
- hosts: ansible-test
gather_facts: false
tasks:
- name: update apt cache
delegate_to: ansible-test
raw: apt -y update
- name: install python
delegate_to: ansible-test
raw: apt -y install python-minimal
- name: demonstrate that normal ansible modules work
file:
path: /etc/testdir
state: directory
Note that while that works, it's not a terribly good model: you don't generally want to perform configuration tasks in your containers at run time; you want to configure your images at build time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With