Ansible
Ansible is an open-source automation tool for IT tasks such as configuration management, application deployment, and orchestration. Ansible uses simple YAML-based playbooks to define tasks, making it easy to automate complex processes.
Supported Versions
env0 supports all standard Ansible versions from
3.0.0
and above.
Environment Deployment
In order to manage your Ansible runs in env0, you must follow these steps:
- Create an Ansible Template first
- Optionally - Create
env0.yml
file in the target repository to run any custom command (ansible or otherwise). This is also needed to run commands during the destroy process - Connect your cloud account
- Create an environment
Execution Steps
Beyond the common steps such as Clone, Loading variables, Deploy/Destroy, etc., Ansible environments offers the following execution steps:
- Ansible Galaxy -
ansible-galaxy install -r requirements.yml
- Ansible Check Playbook -
ansible-playbook --check --diff
Note
Using check_mode: false will cause Ansible code to be deployed prematurely.
It can cause regular Deployments still pending approval, Plans, and Drift Detection to deploy Ansible code. - Ansible Playbook -
ansible-playbook
Destroying Ansible Environments
Please note that env0 does not execute any Ansible commands for destroying Ansible environments.
It serves solely to attach custom flows.
Another thing to note - is that when Destroying Ansible Environments, there's no approval flow, unless you set Approval Policies.
Additional Controls
Setting a custom Playbook file
By default, env0 will run the ansible-playbook
commands with playbook.yml
or playbook.yaml
(whichever is present).
If you want to set a custom playbook file name, you can set the ENV0_ANSIBLE_PLAYBOOK
variable with whichever value you desire.
Setting custom flags
To set any ansible-playbook
flag, you can set an ANSIBLE_CLI_flagName
environment variable.
The flagName is always preceded by a --
, like so:
--flagName
If a value is set to the variable, it will be appended to the flag with a space after the flag name, like so:
--flagName value
For example:
ANSIBLE_CLI_become
would add the--become
flag.ANSIBLE_CLI_inventory
, and setting its value tohosts
would add the--inventory hosts
flag.
Setting extra variables
To set any extra variable for ansible-playbook
, you can set an ANSIBLE_VAR_varName
variable.
Any variable you add here will be parsed and added to the --extra-vars
flag.
For example, setting a ANSIBLE_VAR_myVar
with a value my-value
, would add the --extra-vars 'myVar="my-value"'
flag.
Multiple variables are supported, so setting ANSIBLE_VAR_firstVar
=value-one
and ANSIBLE_VAR_secondVar
=value-two
, would add --extra-vars 'firstVar="value-one" secondVar="value-two"'
.
Skipping Ansible Check Step
In some cases, Ansible checks might fail but for a good reason, and in those cases you might want to skip those checks during the deployment.
For this use case, you can set an environment variable named ENV0_SKIP_ANSIBLE_CHECK
and set the value to be true
- This will cause the deployment to skip that step and mark the step as Skipped
and continue to the next steps in the deployment flow.
Using the Lean Docker Image with Ansible
If you wish to use our lean docker image along with Ansible, make sure Python is installed
Updated 18 days ago