Ansible AWX - Using extra variables

Demonstration on how to use variables when launching a playbook in AWX.

Overview

In some cases your playbook will require additional variables to run.

This post will detail the usage of extra variables in AWX.

Playbook

The playbook below will create a new AWS EC2 instance.

The playbook will only run if the conditional variable create_ec2 is set to “true”.

    - name: EC2 admin
      hosts: all
      tasks:
        - name: Create EC2 instance
          # start an instance with a public IP address
          ec2_instance:
            name: "{{ instance_name }}"
            key_name: "development-k1"
            vpc_subnet_id: "{{ vpc_subnet_id }}"
            instance_type: "{{ instance_type }}"
            security_group: "{{ security_group }}"
            region: "{{ region }}"
            network:
              assign_public_ip: true
            image_id: "{{ image_id }}"
            tags:
              Environment: Testing
    
          when: create_ec2|bool

Template - extra variables

The template configuration in AWX supports extra variables.

If the use case requires fixed values, this is achieved by setting the key value pairs in the extra variables section.

Ensure the key (variable name) matches the ones set in the playbook.

If the values are dynamic, then check the Prompt on launch which will prompt for variables at playbook run time.

Last updated on 25 Mar 2020
Published on 25 Mar 2020