Skip to content

Instantly share code, notes, and snippets.

@bngsudheer
Created March 4, 2018 06:04
Show Gist options
  • Save bngsudheer/351214ea2ffdbde571b4a7c4bd9fdc33 to your computer and use it in GitHub Desktop.
Save bngsudheer/351214ea2ffdbde571b4a7c4bd9fdc33 to your computer and use it in GitHub Desktop.
How To Run A Docker Container Using Ansible On localhost
---
- hosts: all
tasks:
- name: Create a data container
docker_container:
name: my-test-container
image: python:2.7
command: /bin/sleep 600
---
all:
hosts:
127.0.0.1:
ansible_connection: local
ansible_python_interpreter: /home/sudheer/workspace/pvenvs/ansibleenv/bin/python
# /home/sudheer/workspace/pvenvs/ansibleenv/bin/python is the python virtualenv where docker-py is installed
# docker-py==1.10.6
ansible-playbook -i inventory.yml d-play.yml
PLAY [all] ********************************************************************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [127.0.0.1]
TASK [Create a data container] ************************************************************************************************************************************************************************************
ok: [127.0.0.1]
PLAY RECAP ********************************************************************************************************************************************************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment