Red Hat Ansible Automation Platform-2.1-Red Hat Ansible Automation Platform Creator Guide-En-Us
Red Hat Ansible Automation Platform-2.1-Red Hat Ansible Automation Platform Creator Guide-En-Us
2.1
This guide is intended for developers looking to learn how to use Ansible in creating
content for automation.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons
Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is
available at
http://creativecommons.org/licenses/by-sa/3.0/
. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must
provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert,
Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift,
Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries.
Linux ® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.
MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and
other countries.
Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the
official Joyent Node.js open source or commercial project.
The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks
or trademarks/service marks of the OpenStack Foundation, in the United States and other
countries and are used with the OpenStack Foundation's permission. We are not affiliated with,
endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
Abstract
Providing Feedback: If you have a suggestion to improve this documentation, or find an error,
please contact technical support at to create an issue on the Ansible Automation Platform Jira
project using the Docs component.
Table of Contents
Table of Contents
. . . . . . . . . .OPEN
MAKING . . . . . . SOURCE
. . . . . . . . . .MORE
. . . . . . .INCLUSIVE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . .
. . . . . . . . . . . 1.. .PREFACE
CHAPTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . .
.CHAPTER
. . . . . . . . . . 3.
. . UNDERSTANDING
. . . . . . . . . . . . . . . . . . . .ANSIBLE
. . . . . . . . . .CONCEPTS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6. . . . . . . . . . . . .
3.1. PREREQUISITES 6
3.2. ABOUT ANSIBLE PLAYBOOKS 6
3.3. ABOUT ANSIBLE ROLES 6
3.4. ABOUT CONTENT COLLECTIONS 6
3.5. ABOUT EXECUTION ENVIRONMENTS 7
.CHAPTER
. . . . . . . . . . 4.
. . .TOOLS
. . . . . . . .AND
. . . . .COMPONENTS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8. . . . . . . . . . . . .
4.1. ABOUT ANSIBLE BUILDER 8
4.2. USES FOR AUTOMATION CONTENT NAVIGATOR 8
4.3. ABOUT AUTOMATION HUB 8
4.4. ABOUT THE ANSIBLE COMMAND LINE INTERFACE 8
4.5. ADDITIONAL RESOURCES 9
.CHAPTER
. . . . . . . . . . 5.
. . SETTING
. . . . . . . . . . UP
. . . .YOUR
. . . . . . DEVELOPMENT
. . . . . . . . . . . . . . . . . ENVIRONMENT
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
..............
5.1. INSTALLING ANSIBLE BUILDER 10
5.2. INSTALLING AUTOMATION CONTENT NAVIGATOR ON RHEL FROM AN RPM 10
5.3. DOWNLOADING BASE AUTOMATION EXECUTION ENVIRONMENTS 11
. . . . . . . . . . . 6.
CHAPTER . . .CREATING
. . . . . . . . . . . CONTENT
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
..............
6.1. CREATING PLAYBOOKS 12
6.2. CREATING COLLECTIONS 12
6.3. CREATING ROLES 13
6.4. CREATING AUTOMATION EXECUTION ENVIRONMENTS 14
.CHAPTER
. . . . . . . . . . 7.
. . MIGRATING
. . . . . . . . . . . . . EXISTING
. . . . . . . . . . .CONTENT
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
..............
7.1. MIGRATING VIRTUAL ENVS TO AUTOMATION EXECUTION ENVIRONMENTS 16
7.1.1. Listing custom virtual environments 16
7.1.2. Viewing objects associated with a custom virtual environment 16
7.1.3. Selecting the custom virtual environment to export 17
7.2. MIGRATING BETWEEN ANSIBLE CORE VERSIONS 17
7.2.1. Ansible Porting Guides 17
7.2.2. Additional resources 17
.CHAPTER
. . . . . . . . . . 8.
. . .EXECUTING
. . . . . . . . . . . . .YOUR
. . . . . . CONTENT
. . . . . . . . . . . WITH
. . . . . . AUTOMATION
. . . . . . . . . . . . . . . .CONTENT
. . . . . . . . . . .NAVIGATOR
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
..............
8.1. RUNNING ANSIBLE PLAYBOOKS WITH AUTOMATION CONTENT NAVIGATOR 19
8.1.1. Executing a playbook from Automation content navigator 19
8.1.2. Reviewing playbook results with an Automation content navigator artifact file 21
. . . . . . . . . . . 9.
CHAPTER . . .CONCLUSION
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22
..............
1
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
2
MAKING OPEN SOURCE MORE INCLUSIVE
3
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
CHAPTER 1. PREFACE
Using automation execution environments to automate content within the Red Hat Ansible
Automation Platform
You can use Execution Environments as reproducible, portable, consistent and shareable container
images. They control all of the dependencies of an Ansible Automation Platform job’s runtime
environment from system dependencies, Python dependencies, Ansible versions, and Ansible content in
the form of Collections.
4
CHAPTER 2. INTRODUCTION TO CONTENT CREATOR WORKFLOWS AND AUTOMATION EXECUTION ENVIRONMENTS
As automation controller shifts to using automation execution environments, tools like Automation
content navigator and Ansible Builder ensure that you can take advantage of those automation
execution environments locally within your own development system.
Automation content navigator only — can be used today in Ansible Automation Platform 1.2
5
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
3.1. PREREQUISITES
Ansible is installed. For information about installing Ansible, see Installing Ansible in the Ansible
documentation.
Playbooks can be used to manage configurations of and deployments to remote machines, as well as
sequence multi-tier rollouts involving rolling updates. Use playbooks to delegate actions to other hosts,
interacting with monitoring servers and load balancers along the way. Once written, playbooks can be
used repeatedly across your enterprise for automation.
You can find roles for provisioning infrastructure, deploying applications, and all of the tasks you do
every day on Ansible Galaxy. Filter your search by Type and select Role. Once you find a role that you’re
interested in, you can download it by using the ansible-galaxy command that comes bundled with
Ansible:
collection/
├── docs/
├── galaxy.yml
├── meta/
│ └── runtime.yml
├── plugins/
│ ├── modules/
│ │ └── module1.py
│ ├── inventory/
│ ├── lookup/
│ ├── filter/
│ └── .../
├── README.md
6
CHAPTER 3. UNDERSTANDING ANSIBLE CONCEPTS
├── roles/
│ ├── role1/
│ ├── role2/
│ └── .../
├── playbooks/
│ ├── files/
│ ├── vars/
│ ├── templates/
│ ├── playbook1.yml
│ └── tasks/
└── tests/
├── integration/
└── unit/
In Red Hat Ansible Automation Platform, automation hub serves as the source for Ansible Certified
Content Collections.
Ansible Core
Ansible Runner
Ansible Collections
Python libraries
System dependencies
You can define and create an automation execution environment using Ansible Builder.
7
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
Share stored, completed playbook and job run artifacts in JSON format.
Render Ansible module documentation and extract examples you can use in your playbooks.
You cannot execute Ansible commands that are part of Ansible core, such as ansible-playbook, in
containers such as automation execution environments. Use Automation content navigator which
includes a set of the Ansible CLI commands that are compatible with automation execution
environments. Automation content navigator also includes a more detailed output within its text-based
user interface.
At a high level, Automation Hub provides an overview of all partners participating and providing certified,
supported content.
From a central view, users can dive deeper into each partner and check out the collections.
An ad-hoc command for Ansible on the command line follows this structure:
8
CHAPTER 4. TOOLS AND COMPONENTS
To upload content to automation hub, see Uploading content to automation hub in the Ansible
Automation Platform prodcut documentation.
9
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
NOTE
You must have valid subscriptions attached on the host before installing ansible-builder.
Procedure
1. In your terminal, run the following command to activate your Ansible Automation Platform repo:
Prerequisites
Procedure
10
CHAPTER 5. SETTING UP YOUR DEVELOPMENT ENVIRONMENT
Verification
$ ansible-navigator --help
Prerequisites
Procedure
1. Log in to registry.redhat.io
11
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
Name: a brief description of the overall function of the playbook, which assists in keeping it
readable and organized for all users.
Become statements: this optional statement can be set to true/yes to enable privilege
escalation using a become plugin (such as sudo, su, pfexec, doas, pbrun, dzdo, ksu).
Tasks: this is the list actions that get executed against each host in the play.
Example playbook
tasks:
- name: Create a Project
awx.awx.project:
name: Job Template Test Project
state: present
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
Prerequisites
You have Ansible version 2.9 or newer installed in your development environment.
Procedure
1. In your terminal, navigate to where you want your namespace root directory to be. For simplicity,
12
CHAPTER 6. CREATING CONTENT
1. In your terminal, navigate to where you want your namespace root directory to be. For simplicity,
this should be a path in COLLECTIONS_PATH but that is not required.
2. Run the following command, replacing my_namespace and my_collection_name with the
values you choose:
NOTE
The above command will create a directory named from the namespace argument above (if one does
not already exist) and then create a directory under that with the Collection name. Inside of that
directory will be the default or "skeleton" Collection. This is where you can add your roles or plugins and
start working on developing your own Collection.
In relation to execution environments, Collection developers can declare requirements for their content
by providing the appropriate metadata via Ansible Builder.
A file named requirements.txt, which contains information on the Python dependencies and can
sometimes be found at the root level of the Collection
A file named bindep.txt, which contains system-level dependencies and can be sometimes
found in the root level of the Collection
If any of these files are in the build_ignore of the Collection, Ansible Builder will not pick up on
these since this section is used to filter any files or directories that should not be included in the
build artifact
Collection maintainers can verify that ansible-builder recognizes the requirements they expect by using
the introspect command:
Additional resources
For more information on creating collections, see Creating collections in the Ansible Developer
Guide.
13
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
Standalone roles outside of Collections are still supported, but new roles should be created inside of a
Collection to take advantage of all the features Ansible Automation Platform has to offer.
Procedure
The collection now contains a role named my_role inside the roles directory:
~/.ansible/collections/ansible_collections/<my_namespace>/<my_collection_name>
...
└── roles/
└── my_role/
├── .travis.yml
├── README.md
├── defaults/
│ └── main.yml
├── files/
├── handlers/
│ └── main.yml
├── meta/
│ └── main.yml
├── tasks/
│ └── main.yml
├── templates/
├── tests/
│ ├── inventory
│ └── test.yml
└── vars/
└── main.yml
3. A custom role skeleton directory can be supplied using the --role-skeleton argument. This
allows organizations to create standardized templates for new roles to suit their needs.
This will create a role named my_role by copying the contents of ~/role_skeleton into my_role. The
contents of role_skeleton can be any files or folders that are valid inside a role directory.
Additional resources
For more information on creating roles, see Creating roles in the Ansible Galaxy documentation.
An Ansible version
14
CHAPTER 6. CREATING CONTENT
The concept of specifying a set of Collections for an environment is to resolve and install their
dependencies. The Collections themselves are not required to be installed on the machine that you are
generating the automation execution environments on.
An automation execution environments is built from this definition, and results in a container image.
Please read the Ansible Builder documentation to learn the steps involved in creating these images.
15
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
Procedure
$ awx-manage list_custom_venvs
To export the contents of a virtual environment, re-run while supplying the path as an argument:
awx-manage export_custom_venv /path/to/venv
Procedure
inventory_sources:
- id: 15
name: celery
job_templates:
- id: 9
name: Demo Job Template @ 2:40:47 PM
- id: 13
16
CHAPTER 7. MIGRATING EXISTING CONTENT
name: elephant
organizations
- id: 3
name: alternating_bongo_meow
- id: 1
name: Default
projects: []
Procedure
The output from this command will show a pip freeze of what is in the specified virtual environment. This
information can be copied into a requirements.txt file for Ansible Builder to use for creating a new
automation execution environments image
numpy==1.20.2
pandas==1.2.4
python-dateutil==2.8.1
pytz==2021.1
six==1.16.0
NOTE
17
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
Refer to the Ansible 2.10 for behavior changes between Ansible 2.9 and Ansible 2.10.
18
CHAPTER 8. EXECUTING YOUR CONTENT WITH AUTOMATION CONTENT NAVIGATOR
Prerequisites
A playbook.
Procedure
$ ansible-navigator
$ :run
4. Verify or add the inventory and any other command line parameters.
5. Tab to Submit and hit Enter. You should see the tasks executing.
19
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
6. Type the number next to a play to step into the play results, or type :<number> for numbers
above 9.
Notice failed tasks show up in red if you have colors enabled for Automation content navigator.
7. Type the number next to a task to review the task results, or type :<number> for numbers
above 9.
8. Optional: type :doc bring up the documentation for the module or plugin used in the task to aid
in troubleshooting.
ANSIBLE.BUILTIN.PACKAGE_FACTS (MODULE)
0│---
1│doc:
2│ author:
3│ - Matthew Jones (@matburt)
4│ - Brian Coca (@bcoca)
5│ - Adam Miller (@maxamillion)
6│ collection: ansible.builtin
7│ description:
8│ - Return information about installed packages as facts.
<... output omitted ...>
11│ module: package_facts
12│ notes:
13│ - Supports C(check_mode).
14│ options:
15│ manager:
16│ choices:
17│ - auto
18│ - rpm
19│ - apt
20│ - portage
21│ - pkg
22│ - pacman
Additional resources
ansible-playbook.
20
CHAPTER 8. EXECUTING YOUR CONTENT WITH AUTOMATION CONTENT NAVIGATOR
8.1.2. Reviewing playbook results with an Automation content navigator artifact file
Automation content navigator saves the results of the playbook run in a JSON artifact file. You can use
this file to share the playbook results with someone else, save it for security or compliance reasons, or
review and troubleshoot later. You only need the artifact file to review the playbook run. You do not
need access to the playbook itself or inventory access.
Prerequisites
Procedure
1. Review the playbook results that match when the playbook ran.
You can now type the number next to the plays and tasks to step into each to review the results, as you
would after executing the playbook.
Additional resources
ansible-playbook.
21
Red Hat Ansible Automation Platform 2.1 Red Hat Ansible Automation Platform Creator Guide
CHAPTER 9. CONCLUSION
You should now be able to customize an automation execution environments for your particular
automation needs, as well as share and use them via a container registry.
22