项目作者: nl2go

项目描述 :
Containerized Ansible CLI with additional tools and packages
高级语言: Python
项目地址: git://github.com/nl2go/docker-ansible.git
创建时间: 2019-11-05T17:17:46Z
项目社区:https://github.com/nl2go/docker-ansible

开源协议:MIT License

下载


Travis (.org) branch
Codecov
Code Climate maintainability
Docker Pulls

GitHub tag (latest by date)

Docker Ansible

Containerized Ansible CLI.

Contains additional tools/packages (s. Dockerfile).

Usage

Place the docker-compose.yml into your Ansible project and run

  1. $ docker-compose run ansible

SSH Agent

While using SSH key authentication method to access remote resources, ensure that the encrypted private
key is located at the .ssh/id_rsa path within the user directory.

  • Linux/macOS: $HOME/.ssh/id_rsa
  • Windows: $USERPROFILE/.ssh/id_rsa

After starting the Ansible container the key passphrase will be prompted.

  1. $ docker-compose run ansible
  2. Starting SSH Agent.
  3. Enter passphrase for /root/.ssh/id_rsa:

Ansible Vault

Ansible Vault allows to keep sensitive data like
passwords or keys encrypted. It supports encryption of whole files as well as single variables.

To clearly separate
and restrict access to different inventories/environments multiple Ansible Vault passwords are indispensable.

When operating Ansible playbooks frequently, typing the Vault password on every execution can be cumbersome, especially
with multiple environments in place.

While offering a possibility to reference password files, Ansible Vault does not provide a convenient feature to create or
manage those, apart from the fact that an official integration into a password manager like
Gnome-Keyring doesn’t exist.

To overcome the limitations of the status quo a convenient method to manage multiple Ansible Vault password
files is provided.

Create Encrypted Password Files

Initially an encrypted password file for every inventory/environment must be created using a personal master and environment
related Ansible Vault password. This is a one time operation per inventory/environment. Add .vault-password to the
gitignore patterns to prevent accidental check-ins.

  1. $ cd inventories/prod
  2. $ ansible-encrypt-vault-password
  3. Enter the master password for .vault-password files:
  4. Enter the vault password for prod inventory:
  5. Created /ansible/inventories/prod/.vault-password.

As a result master password encrypted inventories/prod/.vault-password file that contains the environment Ansible Vault
password is created.

Load Encrypted Password Files

The encrypted password files are loaded when a new container is started.

  1. $ docker-compose run ansible
  2. ...
  3. Decrypting Ansible Vault passwords.
  4. Enter decryption password for .vault-password files:
  5. Decrypting /ansible/inventories/prod/.vault-password.

Alternatively encrypted password files may be reloaded within existing container.

  1. $ cd /ansible
  2. $ ansible-vault-init
  3. Decrypting Ansible Vault passwords.
  4. Enter decryption password for .vault-password files:
  5. Decrypting /ansible/inventories/prod/.vault-password.

Encrypt Secrets

Secret values are encrypted per inventory (e.g. inventory prod, secret value foo).

  1. $ ansible-vault encrypt_string --encrypt-vault-id 'prod' 'foo'
  2. !vault |
  3. $ANSIBLE_VAULT;1.2;AES256;production-de
  4. 33636332626264316661363731393861333764313361326262313664336435366666306664636434
  5. 3339643439333138303035373866363265326132653363380a303937343963303530666337396561
  6. 31626334633162323731323539393330366633386338393439613332373362383137383930616362
  7. 3066383536323139610a616434643664613435356365356330636435633666353864626439626335
  8. 6664

Ansible Galaxy

Bigger Ansible projects frequently utilize Ansible Galaxy Roles that can be installed using a requirements.yml file.
Roles installation can be triggered from the container.

  1. $ cd /ansible
  2. ansible-galaxy-init
  3. Skipping Ansible Galaxy roles installation. No "/ansible/roles/requirements.yml" file present.

It’s a tiny wrapper for ansible-galaxy install -r /ansible/roles/requirements.yml that ensures that the requirements.yml
is placed into the right location expected by Ansible Tower.

Development

You can run the locally build image with:

  1. docker-compose run ansible

To rebuild the image run:

  1. docker-compose build

Maintainers

License

See the LICENSE.md file for details