Monthly Archives: Giugno 2025

Come usare Ansible Navigator ed Execution Environment su RHEL 9 per prepararti all’RHCE EX294

Introduzione

Se stai studiando per l’esame RHCE EX294 su RHEL 9, una delle novità principali è l’uso di Ansible Navigator insieme agli Execution Environment (EE). In questo articolo vedremo come:

  • Installare Ansible Navigator su RHEL 9
  • Configurare un Execution Environment Docker
  • Eseguire un playbook sicuro al 100%
  • Fornire riferimenti a documentazione ufficiale e approfondimenti

Installazione

sudo dnf install ansible-core podman
pip3 install --user ansible-navigator

Se vuoi usare Docker invece di Podman:

# ~/.ansible-navigator.yml
execution-environment:
  enabled: true
  container-engine: docker
  image: quay.io/ansible/creator-ee:latest

Playbook compatibile con EE

- name: Playbook test compatibile con Execution Environment
  hosts: localhost
  gather_facts: false
  become: false

  vars:
    test_file: "/tmp/esempio.txt"
    file_content: "Questo è un file generato da Ansible nel container."
    pacchetto_demo: "nano"

  tasks:
    - name: Scrittura file su /tmp
      copy:
        dest: "{{ test_file }}"
        content: "{{ file_content }}"
        mode: '0644'

    - name: Installazione pacchetto simulata
      block:
        - name: Verifica comando di installazione
          shell: "echo installazione di {{ pacchetto_demo }} simulata"
          register: risultato

        - name: Mostra risultato simulato
          debug:
            var: risultato.stdout

      rescue:
        - name: Log errori (mai eseguito)
          debug:
            msg: "Errore durante installazione"

      always:
        - name: Log finale
          debug:
            msg: "Blocco terminato"

    - name: Creazione file JSON simulato
      copy:
        dest: /tmp/dati.json
        content: |
          {
            "utente": "demo",
            "ambiente": "execution-environment",
            "successo": true
          }
        mode: '0644'

Inventory

all:
  hosts:
    localhost:
      ansible_connection: local

Comando di esecuzione

ansible-navigator run site.yml \
  --eei quay.io/ansible/creator-ee:latest \
  --ce docker \
  --mode stdout \
  -i inventory.yml

Verifica finale

cat /tmp/esempio.txt
cat /tmp/dati.json

Risorse utili