SlideShare a Scribd company logo
What is Ansible ?
Ansible is an IT automation tool. It can configure
systems, deploy software, and orchestrate more
advanced IT tasks such as continuous deployments or
zero downtime rolling updates.
Ansible Architecture
Install Ansible
To install Ansible in Debian based Linux, you can follow
the following steps:
#Add Ansible repository
$ sudo apt-add-repository ppa:ansible/ansible
#Run the update command
$ sudo apt-get update
#Install Ansible package
$ sudo apt-get install ansible
Control Node and Manage Node Configuration
Manage Node configuration
For Ansible to communicate to a Windows host and use Windows
modules, the Windows host must meet the following requirements:
•Ansible’s supported Windows versions generally match those under
current and extended support from Microsoft. Supported desktop OSs
include Windows 7, 8.1, and 10, and supported server OSs are Windows
Server 2008, 2008 R2, 2012, 2012 R2, 2016, and 2019.
•Ansible requires PowerShell 3.0 or newer and at least .NET 4.0 to be
installed on the Windows host.
•A WinRM listener should be created and activated. More details for this
can be found below.
# Download the below power shell script.
ConfigureRemotingForAnsible.ps1
#Run the power shell script
$ ./ConfigureremotingForAnsible.ps1
# Ensure the Power shell remote login is enabled or not
$ Enable-PSRemoting -Force
# Get version
$ ansible --version
Control Node configuration
For Ansible to communicate to a Windows host and use Windows
modules, the Control host must meet the following requirements:
• A WinRM must be installed and activated .
• pywinrm with support for basic, certificate, and NTLM auth, simply
activated.
#To install pywinrm with support for basic, certificate, and NTLM auth, simply
$ Pip install pywinrm
# for Debian/Ubuntu/etc:
$ sudo apt-get install python-dev libkrb5-dev
$ pip install pywinrm
# for RHEL/CentOS/etc:
$ sudo yum install gcc krb5-devel krb5-workstation
$ pip install pywinrm
Ansible Control Node to communicate with Windows nodes must meet the below requirements
Configuration in Hosts file
Inventory Files & Hosts Pattern
The inventory file of Ansible lists all the platforms you want to automate across. Ansible at
a single instance can work on multiple hosts in the infrastructure. It is also possible to have
multiple inventory files at the same time.
•The host inventory file can contain hostnames either individually or in groups
•Host Groups can be created by giving a group name within square brackets
•Group members can then be listed under, till there is a line break
#Set up hosts by editing the hosts' file in the Ansible
directory
$ sudo vim /etc/ansible/hosts
#To check the connection to hosts #Change your
directory to /etc/Ansible
$ cd /etc/ansible
#Ansible’s win_ping module allows you to check
whether Ansible is connecting to hosts
$ ansible –m win_ping <hosts>
#To check on servers individually
$ ansible –m win_ping server name
#To check a particular server group
$ ansible -m win_ping servergroupname
Follow the below steps to set hosts and
then check their connection:
Set & Check win Hosts Connection Inventory Example
Example inventory file, which you can refer to
understand the various parameters.
Ad-hoc Commands
Ad-Hoc commands are quick commands which are used to perform the actions, that won’t be saved for later.
Frequently used commands
# To check ping status.
$ ansible [host_group_name_in_inventory_file] -i hosts -m win_ping
# Gathering Hostnames
$ ansible [host_group_name_in_inventory_file] -i hosts -m setup | grep
ansible_Hostname
# Start the service
$ ansible [host_group_name_in_inventory_file] -m win_service –a
"name=ser _name“
# check specific file is exist or not
$ ansible [host_group_name] -m win_file –a “path=c:filename” ,
“state=touch”
Service commands
# Start the service in all the servers
$ ansible [host_group] -m win_service –a "name=ser _name
state=started“
# Retart the service in the servers
$ ansible [host_group] -m win_service –a "name=ser _name
state=restarted“
# Stop the service in servers
$ ansible [host_group] -m win_service –a "name=ser _name
state=stopped“
# Pause the service in servers
$ ansible [host_group] -m win_service –a "name=ser _name
state=pause“
File commands
# Create a Directory
$ ansible [host_group] -i hosts -m win_file –a “path=c:directory name
state=directory”
# deleting a directory
$ ansible [host_group] -i hosts -m win_file –a “path=c:directory name
state=absent”
# download a file or image using url
$ ansible [host_group] -m win_get_url -a
"url=https://www.somewebsite.com/ansible.jpg dest=c:fileansible.jpg"
Updating Windows
# Install only security updates as a scheduled task for Server
win_updates:
category_names: SecurityUpdates
use_scheduled_task: yes
# Install only particular updates based on the KB numbers
win_updates:
category_name: - SecurityUpdates
whitelist:
- KB*******
- KB*******
Sample play book
---
- name: Getting started First play book
hosts: win
tasks:
- name: Create directory structure
win_file:
path: C:Tempshellscripts
state: directory
- name: copy a shell script
win_copy:
src: /etc/ansible/localuser.ps1
dest: c:Tempshellscripts
- name: run the powershell script
win_shell: c:Tempshellscriptslocaluser.ps1 >> c:script.txt
- name: create a user using ansible module
win_user:
name: Level3
password: Pass@123
state: present
groups:
- administrators
- users
- name: DNS updation
win_dns_client:
adapter_names: "*"
ipv4_addresses:
- 192.168.3.16
- 192.168.3.19
log_path: c:dna_log.txt
Writing & Running play book
# writing a play book
$ vim play_book name.yaml
(or)
$ vim play_book.yml
# Run a play book
$ ansible-playbook –m Module name –a arguments –i inventory
# Run a play book interactively
$ ansible –playbook_name –step
# Run a play book at a particular task
$ ansible-playbook playbook-name.yml --start-at-task=“task_name”
Ansible windows cheat sheet
Anil Kumar .K
Note: please download the ConfigureRemotingforansible.ps1 from https://raw.githubusercontent.com/ANILVM/powershell/master/ConfigureRemotingForAnsible.ps1

More Related Content

PPTX
Managing windows Nodes like Linux Nodes by Ansible
PPTX
Advance discussion on Ansible - Rahul Inti
PDF
Ansible + WordPress - WordCamp Toronto 2016
PPTX
Basics of Ansible - Sahil Davawala
PPTX
Introduction to Ansible
PPTX
Ansible presentation
PDF
Automation with ansible
ODP
ansible why ?
Managing windows Nodes like Linux Nodes by Ansible
Advance discussion on Ansible - Rahul Inti
Ansible + WordPress - WordCamp Toronto 2016
Basics of Ansible - Sahil Davawala
Introduction to Ansible
Ansible presentation
Automation with ansible
ansible why ?

What's hot (20)

PDF
Ansible Introduction - Ansible Brno #1 - David Karban
PDF
Ansible roles done right
PPTX
Ansible - Crash course
PDF
IT Automation with Ansible
PDF
Ansible is the simplest way to automate. MoldCamp, 2015
PPTX
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
PPTX
Introduction to ansible
PDF
Jenkins and ansible reference
PDF
Using Ansible for Deploying to Cloud Environments
PDF
A quick intro to Ansible
PDF
Introducing Ansible
PDF
Ansible Meetup Hamburg / Quickstart
PDF
Ansible best practices
PPTX
Ansible 101, Gennadiy Mykhailiuta
PPT
Ansible presentation
PPTX
Best practices for ansible
PDF
Configuration Management in Ansible
PDF
A tour of Ansible
PDF
Phoenix Servers with Docker and Nginx
Ansible Introduction - Ansible Brno #1 - David Karban
Ansible roles done right
Ansible - Crash course
IT Automation with Ansible
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Introduction to ansible
Jenkins and ansible reference
Using Ansible for Deploying to Cloud Environments
A quick intro to Ansible
Introducing Ansible
Ansible Meetup Hamburg / Quickstart
Ansible best practices
Ansible 101, Gennadiy Mykhailiuta
Ansible presentation
Best practices for ansible
Configuration Management in Ansible
A tour of Ansible
Phoenix Servers with Docker and Nginx
Ad

Similar to Ansible windows cheat sheet by anil.k (20)

PPTX
Intro to-ansible-sep7-meetup
PDF
Ansible Automation to Rule Them All
PPTX
SESSION Ansible how to deploy and push resources
PDF
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
PDF
Ansible_Basics_ppt.pdf
PDF
Ansible Tutorial.pdf
PDF
Ansible - Hands on Training
PPTX
Ansible for beginners
PDF
ansible_rhel.pdf
PPTX
Ansible
PDF
Ansible101
PDF
Ansible
PPTX
ansible : Infrastructure automation,idempotent and more
PPTX
Ansible as configuration management tool for devops
PDF
Ansible automation tool with modules
PDF
Managing MySQL with Ansible
PPTX
Ansible day 1.ppt
PPTX
Ansible day 1.ppt
PPTX
Hands on ansible
PDF
Hands On Introduction To Ansible Configuration Management With Ansible Comple...
Intro to-ansible-sep7-meetup
Ansible Automation to Rule Them All
SESSION Ansible how to deploy and push resources
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
Ansible_Basics_ppt.pdf
Ansible Tutorial.pdf
Ansible - Hands on Training
Ansible for beginners
ansible_rhel.pdf
Ansible
Ansible101
Ansible
ansible : Infrastructure automation,idempotent and more
Ansible as configuration management tool for devops
Ansible automation tool with modules
Managing MySQL with Ansible
Ansible day 1.ppt
Ansible day 1.ppt
Hands on ansible
Hands On Introduction To Ansible Configuration Management With Ansible Comple...
Ad

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
RMMM.pdf make it easy to upload and study
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cell Structure & Organelles in detailed.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Institutional Correction lecture only . . .
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Computing-Curriculum for Schools in Ghana
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
human mycosis Human fungal infections are called human mycosis..pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
RMMM.pdf make it easy to upload and study
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cell Structure & Organelles in detailed.
Final Presentation General Medicine 03-08-2024.pptx
Institutional Correction lecture only . . .
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Chinmaya Tiranga quiz Grand Finale.pdf
A systematic review of self-coping strategies used by university students to ...
Supply Chain Operations Speaking Notes -ICLT Program
Computing-Curriculum for Schools in Ghana
Abdominal Access Techniques with Prof. Dr. R K Mishra
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Microbial diseases, their pathogenesis and prophylaxis
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Chapter 2 Heredity, Prenatal Development, and Birth.pdf

Ansible windows cheat sheet by anil.k

  • 1. What is Ansible ? Ansible is an IT automation tool. It can configure systems, deploy software, and orchestrate more advanced IT tasks such as continuous deployments or zero downtime rolling updates. Ansible Architecture Install Ansible To install Ansible in Debian based Linux, you can follow the following steps: #Add Ansible repository $ sudo apt-add-repository ppa:ansible/ansible #Run the update command $ sudo apt-get update #Install Ansible package $ sudo apt-get install ansible Control Node and Manage Node Configuration Manage Node configuration For Ansible to communicate to a Windows host and use Windows modules, the Windows host must meet the following requirements: •Ansible’s supported Windows versions generally match those under current and extended support from Microsoft. Supported desktop OSs include Windows 7, 8.1, and 10, and supported server OSs are Windows Server 2008, 2008 R2, 2012, 2012 R2, 2016, and 2019. •Ansible requires PowerShell 3.0 or newer and at least .NET 4.0 to be installed on the Windows host. •A WinRM listener should be created and activated. More details for this can be found below. # Download the below power shell script. ConfigureRemotingForAnsible.ps1 #Run the power shell script $ ./ConfigureremotingForAnsible.ps1 # Ensure the Power shell remote login is enabled or not $ Enable-PSRemoting -Force # Get version $ ansible --version Control Node configuration For Ansible to communicate to a Windows host and use Windows modules, the Control host must meet the following requirements: • A WinRM must be installed and activated . • pywinrm with support for basic, certificate, and NTLM auth, simply activated. #To install pywinrm with support for basic, certificate, and NTLM auth, simply $ Pip install pywinrm # for Debian/Ubuntu/etc: $ sudo apt-get install python-dev libkrb5-dev $ pip install pywinrm # for RHEL/CentOS/etc: $ sudo yum install gcc krb5-devel krb5-workstation $ pip install pywinrm Ansible Control Node to communicate with Windows nodes must meet the below requirements Configuration in Hosts file Inventory Files & Hosts Pattern The inventory file of Ansible lists all the platforms you want to automate across. Ansible at a single instance can work on multiple hosts in the infrastructure. It is also possible to have multiple inventory files at the same time. •The host inventory file can contain hostnames either individually or in groups •Host Groups can be created by giving a group name within square brackets •Group members can then be listed under, till there is a line break #Set up hosts by editing the hosts' file in the Ansible directory $ sudo vim /etc/ansible/hosts #To check the connection to hosts #Change your directory to /etc/Ansible $ cd /etc/ansible #Ansible’s win_ping module allows you to check whether Ansible is connecting to hosts $ ansible –m win_ping <hosts> #To check on servers individually $ ansible –m win_ping server name #To check a particular server group $ ansible -m win_ping servergroupname Follow the below steps to set hosts and then check their connection: Set & Check win Hosts Connection Inventory Example Example inventory file, which you can refer to understand the various parameters. Ad-hoc Commands Ad-Hoc commands are quick commands which are used to perform the actions, that won’t be saved for later. Frequently used commands # To check ping status. $ ansible [host_group_name_in_inventory_file] -i hosts -m win_ping # Gathering Hostnames $ ansible [host_group_name_in_inventory_file] -i hosts -m setup | grep ansible_Hostname # Start the service $ ansible [host_group_name_in_inventory_file] -m win_service –a "name=ser _name“ # check specific file is exist or not $ ansible [host_group_name] -m win_file –a “path=c:filename” , “state=touch” Service commands # Start the service in all the servers $ ansible [host_group] -m win_service –a "name=ser _name state=started“ # Retart the service in the servers $ ansible [host_group] -m win_service –a "name=ser _name state=restarted“ # Stop the service in servers $ ansible [host_group] -m win_service –a "name=ser _name state=stopped“ # Pause the service in servers $ ansible [host_group] -m win_service –a "name=ser _name state=pause“ File commands # Create a Directory $ ansible [host_group] -i hosts -m win_file –a “path=c:directory name state=directory” # deleting a directory $ ansible [host_group] -i hosts -m win_file –a “path=c:directory name state=absent” # download a file or image using url $ ansible [host_group] -m win_get_url -a "url=https://www.somewebsite.com/ansible.jpg dest=c:fileansible.jpg" Updating Windows # Install only security updates as a scheduled task for Server win_updates: category_names: SecurityUpdates use_scheduled_task: yes # Install only particular updates based on the KB numbers win_updates: category_name: - SecurityUpdates whitelist: - KB******* - KB******* Sample play book --- - name: Getting started First play book hosts: win tasks: - name: Create directory structure win_file: path: C:Tempshellscripts state: directory - name: copy a shell script win_copy: src: /etc/ansible/localuser.ps1 dest: c:Tempshellscripts - name: run the powershell script win_shell: c:Tempshellscriptslocaluser.ps1 >> c:script.txt - name: create a user using ansible module win_user: name: Level3 password: Pass@123 state: present groups: - administrators - users - name: DNS updation win_dns_client: adapter_names: "*" ipv4_addresses: - 192.168.3.16 - 192.168.3.19 log_path: c:dna_log.txt Writing & Running play book # writing a play book $ vim play_book name.yaml (or) $ vim play_book.yml # Run a play book $ ansible-playbook –m Module name –a arguments –i inventory # Run a play book interactively $ ansible –playbook_name –step # Run a play book at a particular task $ ansible-playbook playbook-name.yml --start-at-task=“task_name” Ansible windows cheat sheet Anil Kumar .K Note: please download the ConfigureRemotingforansible.ps1 from https://raw.githubusercontent.com/ANILVM/powershell/master/ConfigureRemotingForAnsible.ps1