Ansible Service

Prev Next

This topic demonstrates the basic procedures for creating and executing an Ansible playbook service in Itential Automation Gateway (IAG).

Prerequisites

Before you begin, ensure you have:

Create an Ansible service

Use the iagctl create service ansible-playbook command to create the Ansible Playbook service.

Note

For more information on create commands, see iagctl create.

The following example creates an Ansible playbook service in IAG called simple-ansible that uses a previously configured repository called gateway-resources. Specify the source repository in your create command using the --repository flag.

iagctl create service ansible-playbook simple-ansible --repository gateway-resources --working-dir ansibleplaybooks --playbook hello-world.yml

The gateway-resources repository has the following structure:

├── README.md
├── ansibleplaybooks
│   ├── hello-world.yml
│   ├── requirements.txt
│   └── requirements.yml
├── pythonscripts
└── opentofuplans

Notice that the Ansible Playbook exists in a directory called ansibleplaybooks, which is specified in the create command using the --working-dir flag.

Inside the ansibleplaybook directory there is a playbook called hello-world.yml. You can specify the playbook in your create command using the --playbook flag.

Verify the Ansible playbook service

You can view details about the Ansible playbook service you created by running the iagctl describe service command. For more information, see iagctl describe.

iagctl describe service simple-ansible
Output:

Successfully created the Ansible playbook(s)
Name:        simple-ansible
Repo Name:   gateway-resources
Working Dir: ansibleplaybooks
Playbook(s): hello-world.yml
Decorator:   
Description: 
Tags:        
Runtime Arguments:

Execute an Ansible playbook

You can execute an Ansible playbook in IAG using the run service ansible-playbook command.

Depending on what the playbook does, you can pass variables at runtime.

The hello-world.yml playbook that you created includes a variable for caller:

---
- name: A Simple Hello World Example
  hosts: localhost
  gather_facts: no
  tasks:
    - name: Just Say Hello
      debug:
        msg: "Hello Mr. gateway this is from '{{ caller }}'"⏎

Pass the variable using the --set flag. If you don't pass the variable, an error occurs.

iagctl run service ansible-playbook simple-ansible --set caller=documentation
Output:

Start Time:   2024-01-01T12:00:00Z
End Time:     2024-01-01T12:00:01Z
Elapsed Time: 1.372672s
Return Code: 0
Stdout:      
PLAY [A Simple Hello World Example] ********************************************

TASK [Just Say Hello] **********************************************************
ok: [localhost] => {
    "msg": "Hello Mr. gateway this is from 'documentation'"
}

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   


Stderr: [WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'

You can add additional variables using the --set syntax when running any service.

For example:

iagctl run service ansible-playbook simple-ansible --set caller=documentation --set another=one --set howabout=another
Note

You can restrict the inputs that an Ansible playbook accepts using decorators. For more information, see Using decorators.

Learn more

For more information on the following related operations, see the Command Reference.

  • iagctl create service ansible-playbook

  • iagctl run service ansible-playbook

  • iagctl get services

  • iagctl describe service

  • iagctl delete service