Source: Csdn

Ansible: Chapter 7 RH294 RHEL Automation with Ansible

ONLY FOR SELF STUDY, NO COMMERCIAL USAGE!!! Contents ***ONLY FOR SELF STUDY, NO COMMERCIAL USAGE!!!*** Chapter 7. Simplifying Playbooks with Roles and Ansible Content Collections Describing Role Structure Examining the Ansible Role Structure Defining Variables and Defaults Using Ansible Roles in a Play Including and Importing Roles as Tasks Import Roles Include Roles Using a Roles Section in a Play Special Tasks Sections References Creating Roles The Role Creation Process Creating the Role Directory Structure Defining the Role Content Recommended Practices for Role Content Development Changing a Role's Behavior with Variables Defining Role Dependencies References Example Deploying Roles from External Content Sources External Content Sources Introducing Ansible Galaxy The Ansible Galaxy Command Line Tool Installing Roles Using a Requirements File Finding Community-managed Roles in Ansible Galaxy Browsing Ansible Galaxy for Roles Searching for Roles from the Command Line Downloading Roles from Ansible Galaxy Managing Downloaded Roles References Example Getting Roles and Modules from Content Collections Ansible Content Collections Namespaces for Ansible Content Collections Selecting Sources of Ansible Content Collections Installing Ansible Content Collections Installing Ansible Content Collections with a Requirements File Configuring Ansible Content Collection Sources Using Resources from Ansible Content Collections References Example Reusing Content with System Roles System Roles Simplified Configuration Management Support for System Roles Installing the System Roles Ansible Content Collection Example: Time Synchronization Role Example: SELinux Role Calling the SELinux Role Configuring the SELinux Role Using System Roles with Ansible Core Only Installing the System Roles RPM Package Accessing Documentation for System Roles Running Playbooks Without Automation Content Navigator References Example Chapter 7 Example ***ONLY FOR SELF STUDY, NO COMMERCIAL USAGE!!!*** Chapter 7. Simplifying Playbooks with Roles and Ansible Content Collections Describing Role Structure Examining the Ansible Role Structure Defining Variables and Defaults Using Ansible Roles in a Play Including and Importing Roles as Tasks Import Roles Include Roles Using a Roles Section in a Play Special Tasks Sections References Creating Roles The Role Creation Process Creating the Role Directory Structure Defining the Role Content Recommended Practices for Role Content Development Changing a Role's Behavior with Variables Defining Role Dependencies References Example Deploying Roles from External Content Sources External Content Sources Introducing Ansible Galaxy The Ansible Galaxy Command Line Tool Installing Roles Using a Requirements File Finding Community-managed Roles in Ansible Galaxy Browsing Ansible Galaxy for Roles Searching for Roles from the Command Line Downloading Roles from Ansible Galaxy Managing Downloaded Roles References Example Getting Roles and Modules from Content Collections Ansible Content Collections Namespaces for Ansible Content Collections Selecting Sources of Ansible Content Collections Installing Ansible Content Collections Installing Ansible Content Collections with a Requirements File Configuring Ansible Content Collection Sources Using Resources from Ansible Content Collections References Example Reusing Content with System Roles System Roles Simplified Configuration Management Support for System Roles Installing the System Roles Ansible Content Collection Example: Time Synchronization Role Example: SELinux Role Calling the SELinux Role Configuring the SELinux Role Using System Roles with Ansible Core Only Installing the System Roles RPM Package Accessing Documentation for System Roles Running Playbooks Without Automation Content Navigator References Example Chapter 7 Example Describing Role Structure Examining the Ansible Role Structure Defining Variables and Defaults Using Ansible Roles in a Play Including and Importing Roles as Tasks Import Roles Include Roles Using a Roles Section in a Play Special Tasks Sections References Creating Roles The Role Creation Process Creating the Role Directory Structure Defining the Role Content Recommended Practices for Role Content Development Changing a Role's Behavior with Variables Defining Role Dependencies References Example Deploying Roles from External Content Sources External Content Sources Introducing Ansible Galaxy The Ansible Galaxy Command Line Tool Installing Roles Using a Requirements File Finding Community-managed Roles in Ansible Galaxy Browsing Ansible Galaxy for Roles Searching for Roles from the Command Line Downloading Roles from Ansible Galaxy Managing Downloaded Roles References Example Getting Roles and Modules from Content Collections Ansible Content Collections Namespaces for Ansible Content Collections Selecting Sources of Ansible Content Collections Installing Ansible Content Collections Installing Ansible Content Collections with a Requirements File Configuring Ansible Content Collection Sources Using Resources from Ansible Content Collections References Example Reusing Content with System Roles System Roles Simplified Configuration Management Support for System Roles Installing the System Roles Ansible Content Collection Example: Time Synchronization Role Example: SELinux Role Calling the SELinux Role Configuring the SELinux Role Using System Roles with Ansible Core Only Installing the System Roles RPM Package Accessing Documentation for System Roles Running Playbooks Without Automation Content Navigator References Example Chapter 7 Example Examining the Ansible Role Structure Defining Variables and Defaults Using Ansible Roles in a Play Including and Importing Roles as Tasks Import Roles Include Roles Using a Roles Section in a Play Special Tasks Sections References Including and Importing Roles as Tasks Import Roles Include Roles Using a Roles Section in a Play Special Tasks Sections Import Roles Include Roles The Role Creation Process Creating the Role Directory Structure Defining the Role Content Recommended Practices for Role Content Development Changing a Role's Behavior with Variables Defining Role Dependencies References Example External Content Sources Introducing Ansible Galaxy The Ansible Galaxy Command Line Tool Installing Roles Using a Requirements File Finding Community-managed Roles in Ansible Galaxy Browsing Ansible Galaxy for Roles Searching for Roles from the Command Line Downloading Roles from Ansible Galaxy Managing Downloaded Roles References Example Installing Roles Using a Requirements File Browsing Ansible Galaxy for Roles Searching for Roles from the Command Line Downloading Roles from Ansible Galaxy Ansible Content Collections Namespaces for Ansible Content Collections Selecting Sources of Ansible Content Collections Installing Ansible Content Collections Installing Ansible Content Collections with a Requirements File Configuring Ansible Content Collection Sources Using Resources from Ansible Content Collections References Example System Roles Simplified Configuration Management Support for System Roles Installing the System Roles Ansible Content Collection Example: Time Synchronization Role Example: SELinux Role Calling the SELinux Role Configuring the SELinux Role Using System Roles with Ansible Core Only Installing the System Roles RPM Package Accessing Documentation for System Roles Running Playbooks Without Automation Content Navigator References Example Simplified Configuration Management Support for System Roles Calling the SELinux Role Configuring the SELinux Role Installing the System Roles RPM Package Accessing Documentation for System Roles Running Playbooks Without Automation Content Navigator Chapter 7. Simplifying Playbooks with Roles and Ansible Content Collections Describing Role Structure Ansible roles make it easier to reuse Ansible code generically. You can package all the tasks, variables, files, templates, and other resources needed to provision infrastructure or deploy applications in a standardized directory structure. Copy a role from project to project by copying the directory, then call the role within a play. Ansible roles have the following benefits: Roles group content together, enabling easy sharing of code with others. Roles can define the essential elements of a system type, such as a web server, database server, or Git repository. Roles make larger projects more manageable. Roles can be developed in parallel by different users. In addition to writing, using, reusing, and sharing your own roles, you can obtain roles from other sources. You can find roles by using distribution packages, such as Ansible Content Collections. Or, you can download roles from the Red Hat automation hub, a private automation hub, and from the community's Ansible Galaxy website. Red Hat Enterprise Linux includes some roles in the rhel-system-roles package. You learn more about rhel-system-roles later in this chapter. An Ansible role is defined by a standardized structure of subdirectories and files. The top-level directory defines the name of the role itself. Files are organized into subdirectories that are named according to each file's purpose in the role, such as tasks and handlers . The files and templates subdirectories contain files referenced by tasks in other playbooks and task files. The following tree command displays the directory structure of the user.example role. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Table 7.1. Ansible Role Subdirectories Not every role has all of these directories. Role variables are defined by creating a vars/main.yml file with key-value pairs in the role directory hierarchy. These variables are referenced in role task files like any other variable: { { VAR_NAME }} . These variables have a high precedence and can not be overridden by inventory variables. These variables are used by the internal functioning of the role. Default variables enable you to set default values for variabl

Read full article »
Est. Annual Revenue
$25-100M
Est. Employees
250-500
Paul Cormier's photo - President & CEO of Ansible

President & CEO

Paul Cormier

CEO Approval Rating

69/100

Read more