Ansible-Navigator: The Basics
Im now solely using Ansible-Navigator to run Ansible Playbooks within my home lab. All my runtimes are done within Execution Environments, version controlled as definition files in Github and stored as images in quay.io.
I no longer use the command 'ansible-playbook'.
Lets take a basic look at how I use Navigator and how I can choose different execution environments to run code in.
Installation.
First check you have python3-testresources installed, if not.
sudo apt install python3-testresources
Then install navigator
pip install ansible-navigator
Running Playbooks
Lets say I want to run the following playbook - helloworld.yml
---
- name: Hello World
gather_facts: no
hosts: localhost
tasks:
- debug:
msg: "Hello World"
With Ansible-Navigator I run the playbook using the following command
ansible-navigator run helloworld.yml
However this will only produce the Ansible summary output of the playbook status.
To get the same output as you would get from running 'ansible-playbook' run the following command
领英推荐
ansible-navigator run helloworld.yml -m stdout
Linting Code
Linting is also available within ansible-navigator. To lint a playbook simply run
ansible-navigator lint helloworld.yml
Running a Playbook in an EE
I have an EE which is used for Windows Ad and Azure automation. It's called ee_gold_win. I have the definition files stored within Gitlab, built the EE using Ansible-builder and pushed the container up to quay.io.
The image is local also to my machine and can be listed using
podman ps -l
To run the same playbook within this execution environment, simply use the following command.
ansible-navigator run helloworld.yml -m stdout --execution-environment-image ee_gold_win
As I logged into quay.io before building my image, the latest container image is pulled prior to job run and the playbook is successfully ran.
More information and commands can be found within the Ansible Navigator documentation found at https://ansible.readthedocs.io/projects/navigator/
Network Engineer at Honeywell | VMWare NSX SME | Cisco ACI SME | Nexus | Data Center Engineer
1 年David Andrade Olvera
Software Engineer
1 年Personally I am partial to using the ansible-runner python module to execute my ansible playbooks as part of a python script. Handy for using python to initialize variables, inventory and any other necessities before ansible execution, and handling the output generated after.