[RHCE] 06 – Run playbooks with Automation content navigator

    06_01 Running Playbooks with Automation Content Navigator

    Setup

    # filepath: /scripts/setup_acn.sh
    # Install ACN in Windows
    pip install ansible-navigator
    

    Basic Configuration

    # filepath: ansible-navigator.yml
    ---
    ansible-navigator:
      ansible:
        inventory:
          entries:
            - /path/to/inventory
      execution-environment:
        image: registry.redhat.io/ansible-automation-platform/ee-supported-rhel8:latest
        pull-policy: missing
      logging:
        level: info
        append: true
        file: /path/to/log/ansible-navigator.log
    

    Command Examples

    # filepath: /scripts/acn_commands.ps1
    # Run playbook
    ansible-navigator run site.yml
    
    # Run with inventory
    ansible-navigator run site.yml -i inventory/prod
    
    # Run with vars
    ansible-navigator run site.yml -e "env=prod"
    
    # Interactive mode
    ansible-navigator
    

    Execution Environment Setup

    # filepath: execution-environment.yml
    ---
    version: 1
    dependencies:
      galaxy: requirements.yml
      python: requirements.txt
      system: bindep.txt
    
    additional_build_steps:
      prepend:
        - RUN pip3 install --upgrade pip
      append:
        - RUN pip3 install requests
    

    Project Structure

    # filepath: /scripts/create_project.sh
    mkdir ansible-project
    cd ansible-project
    touch ansible-navigator.yml
    mkdir inventory
    mkdir playbooks
    mkdir collections
    

    Common Commands

    # filepath: /scripts/common_commands.ps1
    # List inventories
    ansible-navigator inventory -i inventory/
    
    # Show playbook help
    ansible-navigator run --help
    
    # Run playbook with debug
    ansible-navigator run site.yml -vvv
    
    # Use specific environment
    ansible-navigator run site.yml --ee-image custom-ee:latest

    06_02 Using ACN to Find and Use New Modules

    Configuration Setup

    # filepath: ansible-navigator.yml
    ---
    ansible-navigator:
      execution-environment:
        image: registry.redhat.io/ansible-automation-platform/ee-supported-rhel8:latest
        pull-policy: missing
    

    Search Commands

    # filepath: /scripts/search_modules.ps1
    # List all collections
    ansible-navigator collections list
    
    # Search for specific modules
    ansible-navigator doc -l | findstr "aws"
    
    # View module documentation
    ansible-navigator doc aws.ec2.ec2_instance
    

    Implementation Example

    # filepath: playbook_with_new_module.yml
    ---
    - name: Use New Module
      hosts: all
      collections:
        - community.aws
      tasks:
        - name: Create EC2 Instance
          aws.ec2.ec2_instance:
            name: "test-instance"
            instance_type: t2.micro
            image_id: ami-123456
            wait: yes
            region: us-east-1
    

    Collections Requirements

    # filepath: collections/requirements.yml
    ---
    collections:
      - name: community.aws
        version: '>= 3.0.0'
      - name: ansible.posix
        version: '>= 1.0.0'
    

    Module Documentation Review

    # filepath: /scripts/module_info.sh
    # Get detailed module info
    ansible-navigator doc community.aws.ec2_instance
    
    # Show module examples
    ansible-navigator doc community.aws.ec2_instance -s EXAMPLES

    06_03 Using ACN for Inventory and Environment Configuration

    Basic Configuration

    # filepath: ansible-navigator.yml
    ---
    ansible-navigator:
      inventory:
        entries:
          - /path/to/inventory
      execution-environment:
        image: registry.redhat.io/ansible-automation-platform/ee-supported-rhel8:latest
        pull-policy: missing
      ansible:
        config:
          path: ansible.cfg
    

    Inventory Structure

    # filepath: inventory/hosts
    [webservers]
    web[1:3].example.com
    
    [dbservers]
    db[1:2].example.com
    
    [prod:children]
    webservers
    dbservers
    

    Environment Configuration

    # filepath: ansible.cfg
    [defaults]
    remote_user = ansible
    host_key_checking = False
    forks = 5
    
    [privilege_escalation]
    become = True
    become_method = sudo
    

    Verification Commands

    # filepath: verify_setup.sh
    # List inventory
    ansible-navigator inventory --list
    
    # Show settings
    ansible-navigator settings --list
    
    # Test connection
    ansible-navigator run ping.yml
    

    Working Example

    # filepath: test_environment.yml
    ---
    - name: Verify Environment Setup
      hosts: all
      tasks:
        - name: Check connectivity
          ping:
        
        - name: Get system info
          setup:
            gather_subset:
              - hardware
              - network
    

    Remember to authenticate with registry.redhat.io before pulling execution environments.



    Discover more from Altgr Blog

    Subscribe to get the latest posts sent to your email.

    Leave a Reply

    Your email address will not be published. Required fields are marked *