Ansible Windows
Ansible Windows
1
Ansible Windows automation
workshop
Introduction to automating Microsoft Windows with Ansible
Automation Platform 2
2
Ansible Windows automation workshop
3
Red Hat Ansible Platform technical deck
4
Red Hat Ansible Platform technical deck
5
Red Hat Ansible Platform technical deck
Consistent governance
Cloud
Edge Datacenter
Line of business
6
®
Why the Red Hat
®
Ansible Automation
Platform?
7
Why the Red Hat Ansible Automation Platform?
8
Why the Red Hat Ansible Automation Platform?
Orchestrate Manage configurations Deploy applications Provision / deprovision Deliver continuously Secure and comply
On these...
9
Why the Red Hat Ansible Automation Platform?
100+
Infrastructure Cloud Network Security
certified platforms
10
What makes a platform?
11
What makes a platform?
Ansible automation
Providing scalable, secure implementation for describing,
building, and managing the deployment of enterprise IT
applications across diverse enterprise architectures.
12
What makes a platform?
13
What makes a platform?
Fueled by an
open source community
14
Red Hat Ansible Platform technical deck
Create
15
Red Hat Ansible Platform technical deck: Create
Create
The automation lifecycle
Discover
Automation hub
16
Red Hat Ansible Platform technical deck: Create
Ansible playbooks
---
- name: start IIS/stop firewall
hosts: windows-web
become: yes
tasks:
- name: IIS is running
win_service:
name: W3Svc
state: running
17
Red Hat Ansible Platform technical deck: Create
18
Red Hat Ansible Platform technical deck: Create
Ansible plays
What am I automating?
19
Red Hat Ansible Platform technical deck: Create
Ansible modules
The “tools in the toolkit”
Language
Powershell for Windows, python for linux.
Can be of any language.
20
Red Hat Ansible Platform technical deck: Create
Ansible plugins
The “extra bits”
Example become plugin:
---
What are they? - name: start IIS
hosts: windows-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 }}
21
Red Hat Ansible Platform technical deck: Create
Ansible roles
Reusable automation actions
---
What are they? - name: install and start IIS
hosts: windows-web
Group your tasks and variables of your
roles:
automation in a reusable structure. Write - common
roles once, and share them with others who - webservers
22
Red Hat Ansible Platform technical deck: Create
Collections
Simplified and consistent content delivery
23
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
24
Automation Controller
25
Red Hat Ansible Platform technical deck: Operate
Operate
The automation lifecycle
Operators
Manage Automation controller
26
Red Hat Ansible Platform technical deck: Operate
A playbook run
Where it all starts
27
Red Hat Ansible Platform technical deck: Operate
Credentials
Workflows
Centralized Logging
API & & Audit Trail
Webhooks
Automation
controller
Red Hat Ansible Platform technical deck: Operate
Execution of content
Running at the core
29
Red Hat Ansible Platform technical deck: Operate
∙ Nodes
∙ Groups
∙ Can be static or dynamic
∙ Smart inventories possible
Workflows
Combine automation to create
something bigger
31
Red Hat Ansible Platform technical deck: Consume
32
Red Hat Ansible Platform technical deck: Operate
API
Integration of automation into
larger workflows
33
Lab Time
Exercise 1 - Configure Automation Controller
This lab is all about exploring the environment and configuring Automation
Controller to import project code from source control
35
Ad-hoc Commands
This lab guides you through executing ad-hoc commands from Automation
Controller
41
Variables
Ansible can work with metadata from various sources and
manage their context in the form of variables.
● Command line parameters
● Plays and tasks
● Files
● Inventory
● Discovered facts
● Roles
Discovered facts
Facts are bits of information derived from examining a host
systems that are stored as variables for later use in a play.
$ ansible localhost -m setup
localhost | success >> {
"ansible_facts": {
"ansible_default_ipv4": {
"address": "192.168.1.37",
"alias": "wlan0",
"gateway": "192.168.1.1",
"interface": "wlan0",
"macaddress": "c4:85:08:3b:a9:16",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "192.168.1.0",
"type": "ether"
},
Variable Precedence
The order in which the same variable from different sources
will override each other.
1. command line values (eg “-u user”) 12. play vars
2. role defaults [1] 13. play vars_prompt
3. inventory file or script group vars [2] 14. play vars_files
4. inventory group_vars/all [3] 15. role vars (defined in role/vars/main.yml)
5. playbook group_vars/all [3] 16. block vars (only for tasks in block)
6. inventory group_vars/* [3] 17. task vars (only for the task)
7. playbook group_vars/* [3] 18. include_vars
8. inventory file or script host vars [2] 19. set_facts / registered vars
9. inventory host_vars/* [3] 20. role (and include_role) params
10. playbook host_vars/* [3] 21. include params
11. host facts / cached set_facts [4] 22. extra vars (always win precedence)
Tasks
tasks:
- name: Ensure IIS Server is present
win_feature:
name: Web-Server
state: present
Handlers are special tasks that run at the end of a play if notified
by another task when a change occurs.
handlers:
- name: Restart IIS
win_service:
name: IIS Admin Service
state: restarted
Plays and playbooks
Plays are ordered sets of tasks to execute against host selections
from your inventory. A playbook is a file containing one or more
plays.
Plays and playbooks
---
- name: Ensure IIS is installed and started
hosts: web
become: yes
vars:
service_name: IIS Admin Service
tasks:
- name: Ensure IIS Server is present
win_feature:
name: Web-Server
state: present
tasks:
- name: Ensure IIS Server is present
win_feature:
name: Web-Server
state: present
tasks:
- name: Ensure IIS Server is present
win_feature:
name: Web-Server
state: present
tasks:
- name: Ensure IIS Server is present
win_feature:
name: Web-Server
state: present
tasks:
- name: Ensure IIS Server is present
win_feature:
name: Web-Server
state: present
tasks:
- name: Ensure IIS Server is present
win_feature:
name: Web-Server
state: present
In this lab you’ll author your first This lab guides you through creating
playbook a job template from an existing
project
57
Doing more with playbooks
Here are some more essential playbook features that you can
apply:
● Templates
● Loops
● Conditionals
● Tags
● Blocks
Doing more with playbooks: Templates
65
Roles
site.yml
roles/ iis/
common/ files/
files/ templates/
templates/ tasks/
tasks/ handlers/
handlers/ vars/
vars/ defaults/
defaults/ meta/
meta/
Roles
Project with Embedded Roles Example
# site.yml
---
- name: Execute common and iis role
hosts: web
roles:
- common
- iis
Roles
http://galaxy.ansible.com
In this lab you will convert your existing automation into roles that can be
reused as a part of larger automated workflows
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
71
Thank you linkedin.com/company/red-hat
youtube.com/user/RedHatVideos
72