Professional Documents
Culture Documents
Ansible Rhel Workshop
Ansible Rhel Workshop
1
What you will learn
2
Introduction
Topics Covered:
3
Red Hat Ansible Platform technical deck
4
Red Hat Ansible Platform technical deck
5
Why the Red Hat Ansible Automation Platform?
6
Why the Red Hat Ansible Automation Platform?
Do this...
Orchestrate Manage configurations Deploy applications Provision / deprovision Deliver continuously Secure and comply
On these...
7
Red Hat Ansible Platform technical deck
Consistent governance
Cloud
Edge Datacenter
Line of business
8
What makes a platform?
Fueled by an
open source community
9
Automation and IT modernization
Source:
Gardner, Chris, Glenn O'Donnell, Robert Perdonii, and Diane Lynch. "The Forrester Wave™: Infrastructure Automation Platforms, Q3 2020." Forrester, 10 Aug. 2020.
DISCLAIMER: The Forrester Wave™ is copyrighted by Forrester Research, Inc. Forrester and Forrester Wave™ are trademarks of Forrester Research, Inc. The Forrester Wave™ is a graphical representation of
Forrester’s call on a market and is plotted using a detailed spreadsheet with exposed scores, weightings, and comments. Forrester does not endorse any vendor, product, or service depicted in the Forrester
Section 1
The Ansible Basics
11
Exercise 1.1
Topics Covered:
12
Red Hat Ansible Platform technical deck: Create
Create
The automation lifecycle
Discover
Automation hub
13
Red Hat Ansible Platform technical deck: Create
Ansible playbooks
---
- name: install and start apache
hosts: web
become: yes
tasks:
- name: httpd package is present
yum:
name: httpd
state: latest
14
Red Hat Ansible Platform technical deck: Create
15
Red Hat Ansible Platform technical deck: Create
Ansible plays
What am I automating?
16
Red Hat Ansible Platform technical deck: Create
Ansible modules
The “tools in the toolkit”
Language
Usually Python, or Powershell for Windows
setups. But can be of any language.
17
Red Hat Ansible Platform technical deck: Create
Ansible plugins
The “extra bits”
Example become plugin:
---
What are they? - name: install and start apache
hosts: web
Plugins are pieces of code that augment become: yes
Ansible’s core functionality. Ansible uses a
Example filter plugins:
plugin architecture to enable a rich, flexible,
{{ some_variable | to_nice_json }}
and expandable feature set. {{ some_variable | to_nice_yaml }}
18
Red Hat Ansible Platform technical deck: Create
Ansible Inventory
The systems that a playbook runs against
[web]
webserver1.example.com
webserver2.example.com
What are they?
[db]
List of systems in your infrastructure that
dbserver1.example.com
automation is executed against
[switches]
leaf01.internal.com
leaf02.internal.com
19
Red Hat Ansible Platform technical deck: Create
Ansible roles
Reusable automation actions
---
What are they? - name: install and start apache
hosts: web
Group your tasks and variables of your
roles:
automation in a reusable structure. Write roles - common
once, and share them with others who have - webservers
similar challenges in front of them.
20
Red Hat Ansible Platform technical deck: Create
Collections
Simplified and consistent content delivery
21
Red Hat Ansible Platform technical deck: Create
Collections
deploy-nginx.yml
nginx_core ---
├── MANIFEST.json - name: Install NGINX Plus
├── playbooks hosts: all
│ ├── deploy-nginx.yml tasks:
│ └── ... - name: Install NGINX
├── plugins include_role:
├── README.md name: nginxinc.nginx
└── roles vars:
├── nginx nginx_type: plus
│ ├── defaults
│ ├── files - name: Install NGINX App Protect
│ │ └── … include_role:
│ ├── tasks name: nginxinc.nginx_app_protect
│ └── templates vars:
│ └── ... nginx_app_protect_setup_license: false
├── nginx_app_protect nginx_app_protect_remove_license: false
└── nginx_config nginx_app_protect_install_signatures: false
22
Why the Red Hat Ansible Automation Platform?
90+
Infrastructure Cloud Network Security
certified platforms
23
How Ansible Automation Works
Module code is
executed locally on the
Network Devices /
control node API Endpoints
Ansible Automation Platform
Local Execution
Linux / Windows
Module code is copied
to the managed node,
Hosts
Ansible Automation Platform
executed, then
removed Remote Execution
Exercise 1.1
25
26
Lab Time
Complete exercise 1.1 now in your lab environment
Exercise 1.2
Topics Covered:
● Ansible inventories
28
Inventory
29
Red Hat Ansible Platform technical deck: Create
Ansible Inventory
[myservers]
The Basics 10.42.0.2
10.42.0.6
An example of a static Ansible inventory 10.42.0.7
10.42.0.8
including systems with IP addresses as
10.42.0.100
well as fully qualified domain name host.example.com
(FQDN)
30
Ansible Inventory - The Basics
[app1srv]
appserver01 ansible_host=10.42.0.2
appserver02 ansible_host=10.42.0.3
[web]
node-[1:30]
[web:vars]
apache_listen_port=8080
apache_root_path=/var/www/mywebdocs/
[all:vars]
ansible_user=kev
ansible_ssh_private_key_file=/home/kev/.ssh/id_rsa
31
Ansible Inventory - Variables
[app1srv]
appserver01 ansible_host=10.42.0.2
appserver02 ansible_host=10.42.0.3
[web]
node-[1:30]
[web:vars]
apache_listen_port=8080
apache_root_path=/var/www/mywebdocs/
[all:vars]
ansible_user=ender
ansible_ssh_private_key_file=/home/ender/.ssh/id_rsa
32
Red Hat Ansible Platform technical deck: Create
33
Red Hat Ansible Platform technical deck: Create
> ANSIBLE.BUILTIN.USER
Aside from listing a full list of all the modules, you
(/usr/lib/python3.8/site-packages/ansible/m
can use ansible-navigator to provide details about odules/user.py)
a specific module.
Manage user accounts and user attributes.
In this example, we are getting information about For Windows targets, use the
the user module. [ansible.windows.win_user] module
instead.
34
Lab Time
Complete exercise 1.2 now in your lab environment
Exercise 1.3
Topics Covered:
● Playbooks basics
● Running a playbook
36
Red Hat Ansible Platform technical deck: Create
Ansible playbooks
---
- name: install and start apache
hosts: web
become: yes
tasks:
- name: httpd package is present
yum:
name: httpd
37
Red Hat Ansible Platform technical deck: Create
Ansible playbooks
---
- name: install and start apache
hosts: web
become: yes
tasks:
- name: httpd package is present
A task
yum:
name: httpd
state: latest
38
Red Hat Ansible Platform technical deck: Create
Ansible playbooks
---
- name: install and start apache
hosts: web
become: yes
tasks:
- name: httpd package is present
A module yum:
name: httpd
state: latest
39
Ansible Colors
Running Playbooks
The most important colors of Ansible
40
Red Hat Ansible Platform technical deck: Create
What is ansible-navigator?
ansible-navigator command line utility and $ ansible-navigator run playbook.yml
text-based user interface (TUI) for running
and developing Ansible automation content.
41
Red Hat Ansible Platform technical deck: Create
ansible-navigator
Bye ansible-playbook, Hello ansible-navigator
42
ansible-navigator
Mapping to previous Ansible commands
46
Red Hat Ansible Platform technical deck: Create
Ansible playbooks
---
- name: variable playbook test
hosts: localhost
vars:
var_one: awesome
var_two: ansible is
var_three: "{{ var_two }} {{ var_one }}"
tasks:
- name: print out var_three
debug:
msg: "{{ var_three }}"
47
Red Hat Ansible Platform technical deck: Create
Ansible playbooks
---
- name: variable playbook test
hosts: localhost
vars:
var_one: awesome
var_two: ansible is
var_three: "{{ var_two }} {{ var_one }}"
tasks:
- name: print out var_three
debug:
msg: "{{ var_three }}"
ansible is awesome
48
Ansible Facts
tasks:
▸ Just like variables, really... - name: Collect all facts of host
setup:
▸ … but: coming from the host itself! gather_subset:
▸ Check them out with the setup module - 'all'
49
Red Hat Ansible Platform technical deck: Create
Ansible playbooks
---
- name: facts playbook
hosts: localhost
tasks:
- name: Collect all facts of host
setup:
gather_subset:
- ‘all’
50
Red Hat Ansible Platform technical deck: Create
PLAY NAME OK CHANGED UNREACHABLE FAILED SKIPPED IGNORED IN PROGRESS TASK COUNT PROGRESS
0│facts playbook 2 0 0 0 0 0 0 2 COMPLETE
51
Lab Time
Complete exercise 1.4 now in your lab environment
Exercise 1.5
Topics Covered:
● Conditionals
● Handlers
● Loops
53
Conditionals via VARS
vars:
my_mood: happy
Example of using a variable labeled my_mood and
using it as a conditional on a particular task. tasks:
- name: task, based on my_mood var
debug:
msg: "Yay! I am {{ my_mood }}!"
when: my_mood == "happy"
54
Red Hat Ansible Platform technical deck: Create
Ansible Conditionals
---
- name: variable playbook test
hosts: localhost
vars:
my_mood: happy
tasks:
- name: task, based on my_mood var
debug:
msg: "Yay! I am {{ my_mood }}!"
when: my_mood == "happy"
Alternatively
- name: task, based on my_mood var
debug:
msg: "Ask at your own risk. I’m {{ my_mood }}!"
when: my_mood == "grumpy"
55
Red Hat Ansible Platform technical deck: Create
---
- name: variable playbook test
hosts: localhost
tasks:
- name: Install apache
apt:
name: apache2
state: latest
when: ansible_distribution == 'Debian' or
ansible_distribution == 'Ubuntu'
56
Red Hat Ansible Platform technical deck: Create
---
- name: variable playbook test
hosts: localhost
tasks:
- name: Ensure httpd package is present
yum:
name: httpd
state: latest
register: http_results
57
Red Hat Ansible Platform technical deck: Create
---
- name: variable playbook test
hosts: localhost
tasks:
- name: Ensure httpd package is present
yum:
name: httpd
state: latest
notify: restart_httpd
handlers:
- name: restart_httpd
service:
name: httpd
state: restart
58
Red Hat Ansible Platform technical deck: Create
tasks:
- name: Ensure httpd package is present
yum:
name: httpd If either task
state: latest
notify: restart_httpd
notifies a
- name: Standardized index.html file
changed result,
copy: the handler will be
notified ONCE.
content: "This is my index.html file for {{ ansible_host }}"
dest: /var/www/html/index.html
notify: restart_httpd
59
Red Hat Ansible Platform technical deck: Create
tasks:
- name: Ensure httpd package is present
yum:
name: httpd If both of these
state: latest
notify: restart_httpd
tasks notifies of a
- name: Standardized index.html file
changed result,
copy: the handler will be
notified ONCE.
content: "This is my index.html file for {{ ansible_host }}"
dest: /var/www/html/index.html
notify: restart_httpd
60
Red Hat Ansible Platform technical deck: Create
tasks:
- name: Ensure httpd package is present
yum:
name: httpd If neither task
state: latest
notify: restart_httpd
notifies a
- name: Standardized index.html file
changed result,
copy: the handler
does not run.
content: "This is my index.html file for {{ ansible_host }}"
dest: /var/www/html/index.html
notify: restart_httpd
61
Ansible Variables & Loops
---
- name: Ensure users
hosts: node1
become: yes
tasks:
- name: Ensure user is present
user:
name: dev_user
state: present
62
Ansible Variables & Loops
---
- name: Ensure users
hosts: node1
become: yes
tasks:
- name: Ensure user is present
user:
name: “{{item}}”
state: present
loop:
- dev_user
- qa_user
- prod_user
63
Lab Time
Complete exercise 1.5 now in your lab environment
Exercise 1.6
Topics Covered:
● Templates
65
Ansible Variables & Templates
tasks:
- name: Verify correct config file is present
template:
src: templates/httpd.conf.j2
dest: /etc/httpd/conf/httpd.conf
66
Ansible Variables & Templates
- name: Ensure apache is installed and started
hosts: web
become: yes
vars:
http_port: 80
http_docroot: /var/www/mysite.com
tasks:
- name: Verify correct config file is present
template:
src: templates/httpd.conf.j2 ## Excerpt from httpd.conf.j2
dest: /etc/httpd/conf/httpd.conf
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
# Listen 80 ## original line
Listen {{ http_port }}
# DocumentRoot: The directory out of which you will serve your
# documents.
# DocumentRoot "/var/www/html"
DocumentRoot {{ http_docroot }}
67
Lab Time
Complete exercise 1.6 now in your lab environment
Exercise 1.7
Topics Covered:
● Galaxy
69
Role Structure user/
├── defaults
▸ Defaults: default variables with lowest │ └── main.yml
precedence (e.g. port) ├── handlers
│ └── main.yml
▸ Handlers: contains all handlers ├── meta
│ └── main.yml
▸ Meta: role metadata including ├── README.md
dependencies to other roles ├── tasks
│ └── main.yml
▸ Tasks: plays or tasks
├── templates
Tip: It’s common to include tasks in
├── tests
main.yml with “when” (e.g. OS == xyz)
│ ├── inventory
│ └── test.yml
▸ Templates: templates to deploy
└── vars
└── main.yml
▸ Tests: place for playbook tests
70
▸ Vars: variables (e.g. override port)
Ansible Galaxy
71
Lab Time
Complete exercise 1.7 now in your lab environment
Exercise 1.8
Topics Covered:
time permits
73
Lab Time
Complete exercise 1.8 now in your lab environment
Section 2
Automation Controller
75
Exercise 2.1
Topics Covered:
76
What makes a platform?
Fueled by an
open source community
77
Automation controller
Push button RESTful API RBAC
An intuitive user interface experience With an API first mentality every feature Allow restricting playbook access to
makes it easy for novice users to and function of controller can be API authorized users. One team can use
execute playbooks you allow them driven. Allow seamless integration with playbooks in check mode (read-only)
access to. other tools like ServiceNow and while others have full administrative
Infoblox. abilities.
Credential
Anatomy of an Automation Job
Playbook
Credential Inventory
Anatomy of an Automation Job
Playbook
Credential Inventory
Automation
controller
Lab Time
Complete exercise 2.1 now in your lab environment
Exercise 2.2
Topics Covered:
● Inventories
● Credentials
85
Inventory
Inventory is a collection of hosts (nodes) with
associated data and groupings that Automation
Controller can connect to and manage.
▸ Hosts (nodes)
▸ Groups
▸ Inventory-specific data (variables)
▸ Static or dynamic sources
Credentials
Credentials are utilized by Automation Controller
for authentication with various external
resources:
● Projects
● Job Templates
89
Project
A project is a logical collection of Ansible
Playbooks, represented in Ansible
Automation Controller.
● Surveys
97
Surveys
Controller surveys allow you to configure
how a job runs via a series of questions,
making it simple to customize your jobs in
a user-friendly way.
103
Red Hat Ansible Platform technical deck: Consume
104
User Management
● An organization is a logical collection of users,
teams, projects, inventories and more. All entities
belong to an organization.
● Workflows
107
Red Hat Ansible Platform technical deck: Operate
Workflows
Combine automation to create
something bigger
108
Red Hat Ansible Platform technical deck: Operate
109
Red Hat Ansible Platform technical deck: Operate
110
Red Hat Ansible Platform technical deck: Operate
Workflow Visualizer
111
Visualizing a Workflow
Workflows can branch out, or converge in.
● Wrap-up
114
Lab Time
Complete exercise 2.7 now in your lab environment
Next steps
Where to go next
Learn more
▸ Workshops
▸ Documents
▸ Youtube
▸ Twitter
Get started
▸ Evals
▸ cloud.redhat.com
Get serious
▸ Red Hat Automation Adoption Journey
▸ Red Hat Training
▸ Red Hat Consulting
116
linkedin.com/company/red-hat
facebook.com/ansibleautomation
twitter.com/ansible
github.com/ansible
117