Skip to content

brtlvrs/ansible-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brtlvrs Ansible-Helper project

version 3.0.0 MIT license Copyright (c) 2020 Bart Lievers blog github dockerhub

This repository contains my approach for building, maintaining an running an ansible docker container. This is based on this blog.

Ansible-Helper container

An Ansible-Helper container is a docker image containing al the bits & bytes to run ansible, to be used to run interactivly with docker.

Goal

Besides getting expierence with Ansible, Docker, git etc... using the docker interactive run features to run ansible in a box without installing it in the host OS.

In this way you can use a certian version of ansible, without having it installed in your host OS and having issues with dependancies when updating packages.

History

version Ansible
version
History
3.0 3.0.0 Updated to ansible 3.0.0
2.10 2.10.0 following Ansible community version scheme
0.4 2.10.0 updated to Ansible 2.10.0 and alpine 3.12
0.3 2.9.0 updated python to v3
0.2 2.9.0 moved from ansible playbook, to scripts for building ansible image
0.0.1 2.9.0 start

Preruiqisites

On the host the following needs to be installed.

  • docker
  • docker-py

build image

To build the ansible-helper image execute the following

./install

This will build the docker image ansible:2.9.0 and copy bash scripts to /usr/local/bin The image is also available at dockerhub. The wrapper scripts are copied inside the image. See the readme.md inside the scripts folder.

Usage

To run ansible helper use the following commands

cmd explenation
ah ansible helper cmdlet, use the ansible cmdlets as arguments.
ah-playbook run ansible-playbook cmdlet. Alternative to 'ah ansible-playbook'

how it works

Both ah and ah-playbook will run the following

docker_img="ansible:latest"

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 \
  $docker_img "$@"

This will run a docker container interactively with the ansible:latest image. It will mount the id_rsa files, making it possible to connect to the local host. And mounts the local folder under /ansible/playbooks. ah-playbook command ends withansible-playbook "$@" instead of only "$@"

See the example folder for an example of an ansible structure you can use.

About

running ansible from within a docker container

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published