Ansible-Navigator: The Basics

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.

Playbook run status output

To get the same output as you would get from running 'ansible-playbook' run the following command

ansible-navigator run helloworld.yml -m stdout        
-m is for mode

Linting Code

Linting is also available within ansible-navigator. To lint a playbook simply run

ansible-navigator lint helloworld.yml        
Linted playbook using ansible-navigator

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        
Listed local EE's

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.

EE downloaded from quay.io

More information and commands can be found within the Ansible Navigator documentation found at https://ansible.readthedocs.io/projects/navigator/

David R.

Network Engineer at Honeywell | VMWare NSX SME | Cisco ACI SME | Nexus | Data Center 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.

要查看或添加评论,请登录

Stephen Paynter的更多文章

  • Creating a Docker GitLab Runner

    Creating a Docker GitLab Runner

    Ever wondered how to set up your own GitLab Runner using Docker. Let's dive in! Step 1: Prerequisites Before we begin…

    3 条评论
  • Automating Exchange Shell With Ansible Via Powershell.

    Automating Exchange Shell With Ansible Via Powershell.

    Lets take a look at how I've been automating Exchange Shell via Powershell using Ansible. I have Exchange Shell…

    2 条评论
  • CRIB SHEET: Installing Ansible AWX with Kubernetes On Ubuntu 20.04.

    CRIB SHEET: Installing Ansible AWX with Kubernetes On Ubuntu 20.04.

    As of writing (September 2023) this is the quickest and lightest way I've found of installing Ansible AWX on a fresh…

    2 条评论
  • What is Git Bundle?

    What is Git Bundle?

    Git Bundle is a feature in Git that allows developers to package repositories into a single file for easy sharing. This…

    2 条评论
  • The Devnet Diaries : Flask

    The Devnet Diaries : Flask

    Creating an API with Flask is a relatively simple process that can be accomplished in just a few steps. Flask is a…

    3 条评论
  • Python Classes, a simplified look.

    Python Classes, a simplified look.

    By what you wrote, you are missing a critical piece of understanding: the difference between a class and an object…

    1 条评论
  • Running the Cisco CWS DevNet Expert Image

    Running the Cisco CWS DevNet Expert Image

    I've had some fun over the last few days trying to get the Devnet Expert Candidate Workstation image running. Here's…

    6 条评论
  • Ansible AWX on Docker

    Ansible AWX on Docker

    A step by step installation process for Ansible AWX on Ubuntu 20.4 on Docker.

    10 条评论
  • Installing Ansible AWX on Ubuntu 20.4 With Kubernetes KS3

    Installing Ansible AWX on Ubuntu 20.4 With Kubernetes KS3

    A workflow to get you up and running with Ansible AWX. Minimum requirements , Ubuntu 20.

    15 条评论
  • Cisco 300-435 ENAUTO Crib Sheet 4

    Cisco 300-435 ENAUTO Crib Sheet 4

    Part 4 in a series of crib notes I'm using to study for the Cisco ENAUTO DevNet exam. Its been a while since I posted…

    1 条评论

社区洞察

其他会员也浏览了