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.
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.
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.
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.
While executing the playbook with
--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.
The views expressed and the content shared in all published articles on this website are solely those of the respective authors, and they do not necessarily reflect the views of the author’s employer or the techbeatly platform. We strive to ensure the accuracy and validity of the content published on our website. However, we cannot guarantee the absolute correctness or completeness of the information provided. It is the responsibility of the readers and users of this website to verify the accuracy and appropriateness of any information or opinions expressed within the articles. If you come across any content that you believe to be incorrect or invalid, please contact us immediately so that we can address the issue promptly.