Ansible Windows Getting Started

About Me

DevOps@RajeshKumar.XYZ

Getting Started with Ansible on Windows


INTRODUCTION

Servers


Dozen?

HUNDREDS??

Administering many servers is difficult, tedious, and error-prone.

Humans aren’t good at doing the same thing over and over in exactly the same way.

Ansible

We're going to learn how to use Ansible with Windows servers

It's helpful if you've already used Ansible with Linux

If not, check out "Hands-on Ansible" by Aaron Paxson at Pluralsight

Will refer back to the hands-on course when necessary

What You Should Have


You should follow along with the course with your own Ansible environment

Ansible Runs on *nix

Ansible Runs on nix

Ansible => WinRM=> Windows Server

Ansible WinRM Windows Server

Ansible: Commands

Ansible Commands

Ansible: Inventory


  • File or group of files
  • Contains all the names and/or IPs of target servers
  • Also sometimes contains login info for target servers

Ansible: Modules


  • Pre-written functions that perform a specific task
  • Used to do things like add a user, install a specific feature, etc
  • Good for compartmentalizing code
  • Ansible comes with many manymodules

Ansible: Playbooks


  • A collection of commands and/or calls to modules
  • Good for setting up a server or servers for a specific role requiring many steps

What's the Story?

What's the Story

Summary


This was a brief introduction to the course and some Ansible basics

In the next module, we'll setup our Ansible environment

Building the Ansible Environment


Globomantics Servers


We'll create local virtual servers to represent the Globomantics servers

Two Windows web servers, one Windows database server

We’ll need one Linux server as the Ansible "control" computer

Start with a Small Test

Start with a Small Test

We'll Need a Hypervisor

We'll Need a Hypervisor

Platform Considerations

Platform Considerations

Create a Vagrant file with details about how to create the virtual machines

I've got a Windows instance already built–more on that in a bit

Once set up, we'll test our connections between virtual machines

VirtualBox: http://virtualbox.org

Vagrant: https://www.vagrantup.com

Where'd Those VM Images Come From?

Where'd Those VM Images Come From

Atlas Has Many Linux Images

Atlas Has Many Linux Images

Atlas Has Few Windows Images

Atlas Has Few Windows Images

Produce Your Own Vagrant Images!


  • You can use Hashicorp's "Packer" tool to build your own images
  • Read Matt Wrock's blog http://www.hurryupandwait.io/blog/
  • For Windows Desktop, it's not really worth it
  • I'll do my best to keep the Windows 2012R2 Server image fresh

Summary


  • Setup Ansible environment using Vagrant and VirtualBox
  • Created Vagrant files to easily provision virtual machines
  • Now we'll install Ansibleon the control instance

Installing Ansible


Ansible Runs on Python 2.x


  • Requires Python 2.6 or 2.7
  • Will not run under 3.x nor will it run on Windows under any version
  • Most Unix and/or Linux distributions come with Python
  • Whatever your control server OS is, make sure you’ve installed a supported Python version

Many Ways to Install Ansible

Many Ways to Install Ansible

Hands-on Ansible

https://www.pluralsight.com/courses/hands-on-ansible

To get to control server, we'll SSH from host command line

Then we'll begin the installation process

Finally, we'll run a test with Ansible

Summary


  • We installed Ansibleon our control server
  • Tested Ansibleby "pinging" the Windows web server using the win_pingmodule
  • Next, we'll talk more about Windows modules and playbooks

Modules, Playbooks, and Roles


Modules


  • Pre-built pieces of code, our main building blocks
  • Used to do tasks like copy files or add a rule to Windows firewall

Ansible Includes Many Modules

Ansible Includes Many Modules

Windows Modules: win_something

http://docs.ansible.com/ansible/list_of_windows_modules.html

Execute modules from the command line

Can be used to orchestrate Windows targets on the fly

Playbooks


  • Playbooks are collections of commands and modules calls
  • Perform one or many tasks

Playbook Syntax (yaml)


---
-
hosts: web
tasks:

-name: Do a thing
win_feature: "name=Package state=present"

-name: Do another thing
win_service: "name=W3SVC state=restarted"

Let's write a web server playbook

The win_featuremodule will be helpful to get us started

Roles


  • Compartmentalized collections of tasks, templates, variables, and more
  • Used to create a function like "web server", "email server", or "database server"

Clean up and create a web server role

Good building block for the next course module

Summary


  • We used modules and wrote playbooks and roles
  • This cleaned up our project structure
  • Next, we'll build the rest of our roles and tasks for the Globomantics server setup

Completing the Ansible Configuration


Update Vagrant File

Update Vagrant File

Resource Warning

Resource Warning

Modify Vagrant file and boot up new VMs

Verify new VMs using test Ansible commands

Production Roles and Playbooks


  • 3 total servers ✔
  • Credentials encrypted ✔
  • Don't need a new role for webserver02
  • But we need to write a database role

Additional requirements

"localadmin" user with administrative access on all servers

Notepad++ application installed to all servers

Integrate New Requirements

Integrate New Requirements

Create common and database roles

Modify playbooks accordingly to include the new roles

Production servers are ready!

Time to turn them over to the development team for deployments

Ansible supports Active Directory

http://docs.ansible.com/ansible/intro_windows.html

Summary


  • Completed Globomantics production configuration using all our skills
  • Encrypted our login credentials for security
  • Wrote all the roles and playbooks we'd need to meet the requirements
  • Next: Ansible Tower

Managing Servers with Ansible Tower


Ansible Tower Is a Commercial Product


  • Ansible Tower is not free
  • 10 node trial version is ideal for getting started with
  • Check out pricing at http://www.ansible.com/tower
  • Excellent solution for managing playbooks, users, inventories, etc

Installing Ansible

Installing Ansible

Let's install Ansible Tower

Modify Vagrant file to add RAM to the control VM

Boot control VM and install Ansible Tower

Ansible Tower Tour


  • Setup Globomantics org in Tower
  • Import inventory
  • Test running our plays
  • Check play status visually

Create the Globomantics organization

Import inventory, run plays, and create a schedule

Validate play runs

Wrapping Up


Ansible for Devops


  • Ansible for DevOps by Jeff Geerling
  • Create all-round intro to Ansible
  • Focus on Linux but lots of useful info for all users

Summary


  • Installed and configured Ansible Tower
  • Imported our existing inventory
  • Configured Tower for Globomantics
  • Next: Start using Ansible!

Ansible 2.1 Release


  • Ansible 2.1 released as this course was being published
  • Release focuses a lot on increased Windows support
  • All demos in this course will work just fine on Ansible 2.1

Question

Question

Thank you!


  • I hope you enjoyed this course
  • I encourage you to leave feedback in the appropriate section and ask questions
  • Good luck!