GithubHelp home page GithubHelp logo

walokra / docker-ansible-playbook Goto Github PK

View Code? Open in Web Editor NEW
96.0 7.0 85.0 8 KB

Docker Image of Ansible for executing ansible-playbook command against an externally mounted set of Ansible playbooks

Shell 100.00%
docker docker-image ansible hacktoberfest

docker-ansible-playbook's Introduction

Ansible Playbook Docker Image

Docker Image of Ansible for executing ansible-playbook command against an externally mounted set of Ansible playbooks. Based on philm/ansible_playbook

Build

docker build -t walokra/ansible-playbook .

Test

$ docker run --name ansible-playbook --rm walokra/ansible-playbook --version

ansible-playbook 2.3.0.0
  config file =
  configured module search path = [u'/opt/ansible/library']
  python version = 2.7.13 (default, Apr 20 2017, 12:13:37) [GCC 6.3.0]

Running Ansible Playbook

docker run --rm -it -v PATH_TO_LOCAL_PLAYBOOKS_DIR:/ansible/playbooks walokra/ansible-playbook PLAYBOOK_FILE

For example, assuming your project's structure follows best practices, the command to run ansible-playbook from the top-level directory would look like:

docker run --rm -it -v $(pwd):/ansible/playbooks walokra/ansible-playbook site.yml

Ansible playbook variables can simply be added after the playbook name.

Ansible Helper wrapper

Shell script named ansible_helper that wraps a Docker image containing Ansible:

docker run --rm -it \
  -v ~/.ssh/id_rsa:/root/.ssh/id_rsa \
  -v ~/.ssh/id_rsa.pub:/root/.ssh/id_rsa.pub \
  -v $(pwd):/ansible/playbooks \
  -v /var/log/ansible/ansible.log \
  walokra/ansible-playbook "$@"

Point the above script to any inventory file so that we can execute any Ansible command on any host, e.g.

./ansible_helper play playbooks/create_user.yml -i inventory/staging -e 'some_var=some_value'

SSH Keys

If Ansible is interacting with external machines, you'll need to mount an SSH key pair for the duration of the play:

docker run --rm -it \
    -v ~/.ssh/id_rsa:/root/.ssh/id_rsa \
    -v ~/.ssh/id_rsa.pub:/root/.ssh/id_rsa.pub \
    -v $(pwd):/ansible/playbooks \
    walokra/ansible-playbook site.yml

Ansible Vault

If you've encrypted any data using Ansible Vault, you can decrypt during a play by either passing --ask-vault-pass after the playbook name, or pointing to a password file. For the latter, you can mount an external file:

docker run --rm -it -v $(pwd):/ansible/playbooks \
    -v ~/.vault_pass.txt:/root/.vault_pass.txt \
    walokra/ansible-playbook \
    site.yml --vault-password-file /root/.vault_pass.txt

Note: the Ansible Vault executable is embedded in this image. To use it, specify a different entrypoint:

docker run --rm -it -v $(pwd):/ansible/playbooks --entrypoint ansible-vault \
  walokra/ansible-playbook encrypt FILENAME

docker-ansible-playbook's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-ansible-playbook's Issues

Playbook cannot be found

I am trying to modify your script to run with my playbook.

I did as per your instructions and get:

D20151052:playbooks gms$  docker run --name ansible-playbook --rm gms/ansible-playbook --version
ansible-playbook 2.3.0.0
  config file =
  configured module search path = [u'/ansible/library']
  python version = 2.7.13 (default, Apr 20 2017, 12:13:37) [GCC 6.3.0]

Then, when I try to execute my playbook, test_ctakes.yml in its directory:

D20151052:playbooks gms$ pwd
/Users/gms/development/ansible/playbooks
D20151052:playbooks gms$ ls -la
total 32
drwxr-xr-x  6 gms  staff   204 Feb 19 15:29 .
drwxr-xr-x  4 gms  staff   136 Feb 19 15:29 ..
-rw-r--r--@ 1 gms  staff  6148 Feb 19 15:29 .DS_Store
drwxr-xr-x  7 gms  staff   238 Feb 19 15:15 docker-ansible-playbook
-rw-r--r--  1 gms  staff    17 Feb 15 15:38 hosts
-rw-r--r--  1 gms  staff  1173 Feb 16 17:25 test_ctakes.yml

as

docker run --rm -it -v /Users/gms/development/ansible/playbook gms/ansible-playbook test_ctakes.yml

I get an error: ERROR! the playbook: test_ctakes.yml could not be found... I did downgrade my version of sensible to 2.3.0.0, as per your directions.

Any idea why this is not working? My playbook works just fine with ansible-playbook on its own.

TIA!

remote host unreachable

Hi Walokra,
i getting below issue. host un reachable. even if you mount valume how remote host will know docker image ssh key. my understand we need to public key to remote host before executing playbook. could you please guide me.

TASK [Gathering Facts] ************************************************************************************************************************************************************
fatal: [1xxxx.xxx.xxx.xx]: UNREACHABLE! => {"changed": false, "msg": "SSH Error: data could not be sent to remote host "1xxx.xx.xx.xx". Make sure this host can be reached over ssh", "unreachable": true}

accessing ansible.log file and mounting directory

Hello Walokra.
i see in the ansible_helper file that there is a ansible.log file.
how do i access it after running a playbook. is it stored on my local host or inside the container?
is there a way to save it into the current directory?

I have a playbook that generates a output file. how do i get this saved into my local directory?

Does this support SSH private keys with a passphrase?

In my experience you also need to pass in -v "$SSH_AUTH_SOCK":"/root/$(basename $SSH_AUTH_SOCK)" -e SSH_AUTH_SOCK="/root/$(basename $SSH_AUTH_SOCK)" in order to be able to use protected keys. Judging from other issues around use on MacOS this probably isn't available without some extra work to handle Windows/Linux/MacOS use cases, though it is fairly straightforward for Linux.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.