Ansible environment in a container. Default Container engine is podman.
sudo curl https://raw.githubusercontent.com/drerik/ansible-environment/main/ansible-environment | sudo tee /usr/local/bin/ansible-environment
sudo chmod 755 /usr/local/bin/ansible-environmentConfiguration can be set globaly by creating a bash source file. The script will look for the following files in this order and source them:
~/.ansible-environment: Global config for all your all ansible environments~/.ansible-environment-$PWD: Local config per envirionment. Add your environement specifics for that project. $PWD is your projects work folder..ansible-environment: Project specific config. If your inventory is located inside the project structure, you can defineANSIBLE_INVENTORYhere.
These two environments variables can be set here.
ANSIBLE_INVENTORY: Path to ansible inventoryANSIBLE_ENVIRONMENT_EXTRAS: Extra container parameters ( volumes, environnment variables etc. )
Example:
export ANSIBLE_INVENTORY=$HOME/projects/ansible/inventory
export ANSIBLE_ENVIRONMENT_EXTRAS=""Mount you ssh key into the ansible-environment
export ANSIBLE_ENVIRONMENT_EXTRAS="$ANSIBLE_ENVIRONMENT_EXTRAS -v $HOME/.ssh/id_rsa.pub:/root/.ssh/id_rsa.pub:roMount your local ansible collection (" $HOME/Workspace/ansible/ansible-collections ") into your ansible-environment.
export ANSIBLE_ENVIRONMENT_EXTRAS="$ANSIBLE_ENVIRONMENT_EXTRAS -v $HOME/Workspace/ansible/ansible-collections:/workspace/collections/ansible_collections -e ANSIBLE_COLLECTIONS_PATHS=/workspace/collections"You can create your own ansible-environment image by extending the original ghcr.io/drerik/ansible-environment:main image, then in your .ansible-envrionment export the ANSIBLE_ENVIRONMENT_IMAGE variable with your own image
export ANSIBLE_ENVIRONMENT_IMAGE=ghcr.io/drerik/ansible-environment:mainTo change the container engine to docker, you can configure the CONTAINER_RUNTIME environment variable
export CONTAINER_RUNTIME=dockerIf you need to run docker with sudo, you can set the CONTAINER_RUNTIME like this:
export CONTAINER_RUNTIME=sudo dockerecho -n "the plaintext to encrypt" | ansible-vault encrypt_string --stdin-name "ansible_password"