Skip to content

gadiener/ansible

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dockerized Ansible command line tools

Use Ansible command line tools inside Docker in CI or Local Environment.

Supported tags and respective Dockerfile links

How to use it

Docker run

  • ansible: Define and run a single task ‘playbook’ against a set of hosts.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible all -m ping
  • ansible-playbook: Runs Ansible playbooks, executing the defined tasks on the targeted hosts.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-playbook site.yml
  • ansible-vault: Encryption/decryption utility for Ansible data files.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-vault encrypt_string
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-galaxy login
  • ansible-console: A REPL that allows for running ad-hoc tasks against a chosen inventory.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-console
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-config dump
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-doc file
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-inventory --host localhost
  • ansible-pull: Pulls playbooks from a VCS repo and executes them for the local host.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-pull -U [email protected]:gadiener/unknown-ansible-repository.git site.yml

⁉️ This command is useless in the Docker context but you can still do it 😄

Add shell aliases

To install the aliases script you can use the following commands:

curl -o /usr/local/bin/ansible-aliases https://raw.githubusercontent.com/gadiener/ansible/master/ansible-aliases.sh
chmod +x /usr/local/bin/ansible-aliases

Then you can use the script.

$ ansible-aliases -h

Usage: ansible-aliases [OPTIONS]

>> Install dockerized Ansible tools aliases

Options:
   -k, --key string         The path of the SSH key to use
   -w, --workspace string   The path of the workspace to use (default $(pwd))
   -t, --tag string         The Docker tag to use
   -e, --env string         Set environment variables
       --remove             Uninstall Ansible aliases
ansible-aliases -k $SSH_KEY_PATH -e 'ANSIBLE_HOST_KEY_CHECKING=False'

After installing the aliases, the shell must be restarted.

To remove aliases you can use the following commands:

ansible-aliases --remove
rm /usr/local/bin/ansible-aliases

Configuration

Environment variables

The SSH_KEY variable must contains che SSH key used by Ansible to connect to the cluster.

SSH_KEY=$(cat ~/.ssh/id_rsa)

Volumes

To share your tasks or playbook's files you can bind a volume to /workspace.

You can bind a volume to /etc/ansible to share your local conficuration with Ansible in docker.

⛔️ WARNING: Do not add a volume in ~/.ssh/:/home/ansible/.ssh/ without the read-only flag. With the environment variable SSH_KEY set you'll lose your private key!

Use it in GitLab CI

@todo: I'm waiting for your pull request 😉

Contributing

How to get involved:

  1. Star the project!
  2. Answer questions that come through GitHub issues
  3. Report a bug that you find

This project follows the GitFlow branching model. The master branch always reflects a production-ready state while the latest development is taking place in the develop branch.

Each time you want to work on a fix or a new feature, create a new branch based on the develop branch: git checkout -b BRANCH_NAME develop. Only pull requests to the develop branch will be merged.

Pull requests are highly appreciated.

Solve a problem. Features are great, but even better is cleaning-up and fixing issues in the code that you discover.

Versioning

This project is maintained by using the Semantic Versioning Specification (SemVer).

Contributors

Gabriele Diener @gadiener

Flavio De Stefano @kopiro

Copyright and license

Copyright 2018 Gabriele Diener under the MIT license.