red hat, ansible
You will find here notes and links to official docs with additional information on products and technologies that descrbed on RedHat Cources.
THIS DOCUMENT DOES NOT REPRINT ANY COPYRIGHTED CONTENT FROM REDHAT TRAINING. You will find here only public accessible outline.
Course description: DO294 Automation with Ansible
Describe Ansible concepts and install Red Hat Ansible Engine.
https://www.ansible.com/
https://www.ansible.com/about-us
https://www.ansible.com/blog
The Origins of Ansible
Ansible project founder Michael DeHaan.
First version is 20 february 2012.
In 2015 Red Hat Acquired Ansible Inc.
https://www.redhat.com/en/about/press-releases/red-hat-acquire-it-automation-and-devops-leader-ansible
https://www.redhat.com/en/blog/why-red-hat-acquired-ansible
Getting Ansible from Red Hat.
Red Hat Ansible Engine
Red Hat Ansible Engine Life Cycle
Ansible Docs: Ansible Getting Started
Learn Ansible using Interactive Browser-Based Scenarios By Katacoda
Ansible Docs: Installation Guide
Python is a requirement for linux control node and managed nodes
Red Hat Blogs: What, no Python in Red Hat Enterprise Linux 8?
Python Developer Guide: The "python" Command on Unix-Like Systems
Red Hat Blogs: Python in RHEL 8
Sunsetting Python 2. PSF support end date: 1 January 2020
Porting Python 2 Code to Python 3
Python 3 support on Red Hat Enterprise Linux (RHEL) 7
"Python 2.7 package in RHEL 8 support end at June 2024"
RedHat KB: How is Python 2 supported in RHEL after 2020?
Optional (and not required for ansible) way to enable python command
RedHat KB: How do I Download and Install Red Hat Ansible Engine?
RedHat KB: Ansible deprecated in the Extras channel
Getting Red Hat Developer Subscription: What RHEL users need to know
Register FREE Red Hat developer Subscription
Renew your FREE Red Hat Developer subscription
How about managing Windows machines with ansible?
Red Hat Course:: DO417 Microsoft Windows Automation with Red Hat Ansible
Red Hat Summit 2018 Video: Manage Windows like Linux with Ansible
Managing network devices with ansible.
Ansible Docs: Ansible for Network Automation
Red Hat Course: DO457 Ansible for Network Automation
Configure Ansible to manage hosts and run ad hoc Ansible commands.
Ansible Docs: Inventory Introduction
Ansible Docs: How to build your inventory
Ansible Docs: ansible-inventory command
Ansible Docs: Configuring Ansible
Ansible Docs: Ansible Configuration settings precedence rules
example of ansible.cfg with describing comments
Ansible Docs: Utility that show actual and default configuration options: ansible-config
Write a simple Ansible playbook and run it to automate tasks on multiple managed hosts.
Ansible Docs: Working With Playbooks
Acceptable boolean values:
Red Hat Ansible: Yes and No, True and False
TEST OUTCOME | VARIABLE VALUE |
---|---|
True | Any positive number >0: 1,2 .. |
Non-empty string: "1", "True","False",'Nonsence' | |
Boolean value (unquoted): True,true | |
Ansible-specific (case-agnostic): Yes,yes | |
–––––––––––––- | –––––––––––––––––––––––– |
False | Any number <=0: 0,-1 .. |
Empty string: "", '' | |
Boolean value (unquoted): False,false | |
Ansible-specific (case-agnostic): No,no |
GitHub Project: Ansible playbook syntax highlight plugin for vim
GitHub Project: Ansible Examples of playbook
Example of playbook
Ansible Docs: debug – Print statements during execution
GitHub Project: Best practices checker for Ansible
How to install python package with pip on RHEL and not to break anything.
Example guide with ansible-lint.
virtualenv is a tool to create isolated Python environments
Ansible Docs: Playbook Keywords
Write playbooks that use variables to simplify management of the playbook and facts to reference information about managed hosts.
Ansible Docs: Variable precedence: Where should I put a variable?
Ansible Docs: Variables and Vaults
Best Practices to use Ansible Secret
For general maintenance, it is often easier to use grep, or similar tools, to find variables in your Ansible setup. Since vaults obscure these variables, it is best to work with a layer of indirection. When running a playbook, Ansible finds the variables in the unencrypted file and all sensitive variables come from the encrypted file.
A best practice approach for this is to start with a group_vars/ subdirectory named after the group. Inside of this subdirectory, create two files named vars and vault. Inside of the vars file, define all of the variables needed, including any sensitive ones. Next, copy all of the sensitive variables over to the vault file and prefix these variables with vault_. You should adjust the variables in the vars file to point to the matching vault_ variables using jinja2 syntax, and ensure that the vault file is vault encrypted.
Ansible Docs: Special Variables. Magic, facts and connection variables
set_facts usage real life example
https://cheat.readthedocs.io/en/latest/ansible/
Manage task control, handlers, and task errors in Ansible playbooks.
Ansible Docs: Registering Variables with loop
Ansible Docs: Handlers: Running Operations On Change
Deploy, manage, and adjust files on hosts managed by Ansible.
Ansible file managing modules:
Ansible Doc: Template module
Jinja2 is a full-featured template engine for Python.
How I Used Complex Jinja2 Filters in Ansible
Write playbooks that are optimized for larger, more complex projects.
Patterns: targeting hosts and groups
Description | Pattern(s) | Targets |
---|---|---|
All hosts | all (or *) | |
One host | host1 | |
Multiple hosts | host1:host2 (or host1,host2) | |
One group | webservers | |
Multiple groups | webservers:dbservers | all hosts in webservers plus all hosts in dbservers |
Excluding groups | webservers:!atlanta | all hosts in webservers except those in atlanta |
Intersection of groups | webservers:&staging | any hosts in webservers that are also in staging |
Ansible Docs: Working with dynamic inventory
Ansible Github Project: dynamic inventory scripts
Ansible Docs: Controlling playbook execution: strategies and more
Ansible strategies:
linear - Executes tasks in a linear fashion (default strategy)
free – Executes tasks without waiting for all hosts
debug – Executes tasks in interactive debug session
host_pinned – Executes tasks on each host without interruption
Mitogen for Ansible is a completely redesigned UNIX connection layer and module runtime for Ansible. Requiring minimal configuration changes, it updates Ansible’s slow and wasteful shell-centic implementation with pure-Python equivalents, invoked via highly efficient remote procedure calls to persistent interpreters tunnelled over SSH. No changes are required to target hosts.
Playbook Example: Continuous Delivery and Rolling Upgrades
Medium post: Difference between Forks and Serial in Ansible
Ansible Docs: Delegation
If you want to perform a task on one host with reference to other hosts, use the delegate_to keyword on a task
Ansible Docs: Including and Importing
include_tasks include_role | import_tasks import_playbook import_role | |
---|---|---|
behavoir | dynamic | static |
when happen | include when running play | importing when initially parsed before any play run |
tasks shows ansible-playbook –list-tasks | no | yes |
ansible-playbook –syntax-check throw errors (when it exist in included or imported content) | no | yes |
time when ansile-playbook – throws syntax error (when it exist in included or imported content) | during play | before any run |
Can i use ansible-playbook –start-at-task to start playbook with those types of task? | no | yes |
Use Ansible roles to develop playbooks more quickly and to reuse Ansible code.
RedHat KB: Red Hat Enterprise Linux (RHEL) System Roles
Github Project: Linux System Roles
Automation Hub. Discover, publish, and manage your Ansible Collections
Red Hat Ansible Blog: Getting Started With Automation Hub
Red Hat Ansible Blog: Hands on with Ansible collections
default vs vars in Ansible roles. Where to put variable on role?
Variable precedence: Where should I put a variable?
Ansible Galaxy is Ansible’s official hub for sharing Ansible content
Ansible Doc: Galaxy User Guide
Ansible Docs: Using collections (only available in Ansible 2.9+)
Collections are a distribution format for Ansible content that can include playbooks, roles, modules, and plugins. You can install and use collections through Ansible Galaxy.
Ansible Galaxy: geerlingguy.docker role
Red Hat Enterprise Linux Presents… automation with RHEL System Roles
Troubleshoot playbooks and managed hosts.
Visual Studio Code editor with syntax highlighting and many many other features.
VSCode extension: YAML Language Support by Red Hat
VSCode extension: Ansible
VSCode extension: Remote - SSH
debug – Print statements during execution
Debugging modules
Playbook Debugger
Molecule project is designed to aid in the development and testing of Ansible roles
ARA Records Ansible playbooks and makes them easier to understand and troubleshoot
Ansible Docs: Testing Strategies
Automate common Linux system administration tasks with Ansible.
What about DNS, DHCP, Print, Mail, batabase, file and http servers?
RH358 Red Hat Services Management and Automation
Is there some Ansible best practices exist?
Ansible Docs: Playbook Best Practices
Red Hat Course: DO447 Advanced Automation: Ansible Best Practices
Red Hat Summit 2016 Video: Ansible best practices for startups to enterprises
Top Support Policies for Red Hat Ansible Automation
Is there some other useful resources exist?
Red Hat Blog: Introducing Ansible Automation Platform 2.0 Early Access
Представляем Ansible Automation Platform 2
What's new in Ansible Automation Platform 2: automation controller
Ansible Lab Catalog: Access a catalog of Ansible product labs by accessing this site
Experience self-paced interactive hands-on labs with Ansible Automation Platform
Training Course for Ansible Automation Platform
Ansible Automation Platform Self-Paced Labs
These interactive learning scenarios provide you with a pre-configured Ansible Automation Platform environment to experiment, learn, and see how the platform can help you solve real-world problems. The environment runs entirely in your browser, enabling you to learn more about our technology at your pace and time.