ansible-navigator
is the new command line utility (CLI) introduced in Ansible Automation Platform 2, for running and developing Ansible automation content. ansible-navigator can be used to execute a playbook as follows.
With ansible-navigator
it is possible to test the Ansible playbooks inside the execution environment containers which will help to get the same result when you execute on Ansible Controller or Ansible Automation Platform. But when you have a dependency on credentials, then it is not a direct method to simulate the containerized playbook execution.
For example, I have a playbook to automate some of the VMWare operations and in the Ansible controller, I have created a VMWare vCenter credential and configured it in the job template. But when I want to test the same playbook using ansible-navigator
, I need to find a way to pass the VMWare credential to the playbook. I can achieve this using temporary variables (with Ansible Vault of course) for the credential but again I need to change the same before pushing to the Ansible controller as I have credentail already configured there.
In my case, I know the VMWare vCenter credential is exposing the following variables for the playbook to pick up.
VMWARE_HOST
VMWARE_USER
VMWARE_PASSWORD
So, when I run the playbook using ansible-navigator
, I just need to ensure that, the environment variables are passed to the execution environment; let’s see how to do that.
Export the environment variables
First, I have exported the environment variables as follows.
$ export VMWARE_HOST=vcenter.example.com
$ export VMWARE_USER=ansible-service-user
$ export VMWARE_PASSWORD=mycomplexpassword
Remember, this is in our local workstation where you run ansible-navigator
and not inside the execution environment container yet.
Pass environment variable to the execution environment
While executing the playbook with ansible-navigator
, use --penv
to pass the environment variable as follows.
$ ansible-navigator run vmware-vm-provisioning.yaml -m stdout --penv VMWARE_HOST --penv VMWARE_USER --penv VMWARE_PASSWORD
That’s it, the playbook can now pickup the environment variables inside the container and use it during execution.
Also check the Ansible Navigator cheatsheet.