Giter Club home page Giter Club logo

docker-ansible's Introduction

docker-ansible : using ansible without installing it

This docker allows you to use ansible on your computer without installing it.

This allows you to :

  • share your ssh agent with the ansible docker
  • share your AWS CLI configuration
  • Use a specifc version without installation
  • Use AWS and Junos componants: aws cli, junos-eznc, Juniper.junos ansible module

Just add these aliases to your ~/.{bash|zsh|...}_aliases in order to use ansible as it where installed on your computer.

export DOCKER_ANSIBLE_VERSION=2.5
base_ansible() {
        docker run -it --rm \
            --env ANSIBLE_REMOTE_USER=${USER} \
            --env AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} \
            --env AWS_PROFILE=${AWS_PROFILE} \
            --volume $SSH_AUTH_SOCK:/ssh-agent \
            --env SSH_AUTH_SOCK=/ssh-agent \
            -v ${PWD}:project \
            -v ${HOME}/.aws/:/root/.aws/ \
            -v ${HOME}/.ssh/known_hosts:/root/.ssh/known_hosts \
            -w ${PWD} \
            inetsix/docker-ansible:${DOCKER_ANSIBLE_VERSION} $@
}

alias ansible-update='docker pull inetsix/docker-ansible:${DOCKER_ANSIBLE_VERSION}'
alias ansible-shell='base_ansible bash'
alias ansible='base_ansible ansible'
alias ansible-playbook='base_ansible ansible-playbook'
alias ansible-vault='base_ansible ansible-vault'
alias ansible-galaxy='base_ansible ansible-galaxy'

Usage

Simply use your aliases, and you can override ansible default version when required

$ docker-ansible --version 
ansible 2.0.2.0
  config file = /tmp/ansible.cfg
  configured module search path = Default w/o overrides

$ DOCKER_ANSIBLE_VERSION=2.5 docker-ansible --version 
ansible 2.5.2
  config file = /Users/titom73/Scripting/ansible.projects/ansible.training.phase2/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Apr 27 2018, 09:37:08) [GCC 4.9.2]

Export AWS CLI parameters

Assuming you have configured your AWS CLI, you may export your parameters with the following variables:

On your local shell:

export AWS_DEFAULT_REGION='eu-west-2'
export AWS_PROFILE='your_was_profile'

Then, these variables are exposed to your docker instance by using --env keyword. If they are not set, then, nothing is export to your container.

Overwrite ansible commands

If for some reasons, you need to use your installed ansible version, just use \\ in front of any ansible command like below:

$ \ansible --version
ansible 2.5.1
  config file = /Users/titom73/Scripting/ansible.projects/ansible.training.phase2/ansible.cfg
  configured module search path = [u'/Users/titom73/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Mar 22 2018, 15:04:47) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

$ ansible --version
ansible 2.5.2
  config file = /Users/titom73/Scripting/ansible.projects/ansible.training.phase2/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Apr 27 2018, 09:37:08) [GCC 4.9.2]

docker-ansible's People

Contributors

titom73 avatar

Watchers

 avatar  avatar

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.