Slide 1

Slide 1 text

Introduction to Ansible Krishantha Dinesh Msc, MIEEE, MBCS Software Architect www.krishantha.com www.youtube.com/krish @krishantha

Slide 2

Slide 2 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Configuration management • Manage software on top of hardware • Maintain consistency based on functionality and design • It is systems engineering process for establishing and maintaining consistency of a product's performance

Slide 3

Slide 3 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Why Configuration Management • Make consistency • Maintain integrity • No need separate log in / execution on each server • Centralize control / management • Scaling made easy • No time to deploy or configure after successful build • Rolling back is easy

Slide 4

Slide 4 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ What is ansible • Ansible is an open-source software provisioning, configuration management, and application-deployment tool. • It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. • Its pushed based configuration management tool

Slide 5

Slide 5 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Why ansible • Free. Ansible is an open-source tool. • Very simple to set up and use. No special coding skills are necessary to use Ansible’s playbooks • Powerful. Ansible lets you model even highly complex IT workflows. • Flexible. You can orchestrate the entire application environment no matter where it’s deployed. You can also customize it based on your needs. • Agentless. You don’t need to install any other software or firewall ports on the client systems you want to automate. You also don’t have to set up a separate management structure. • Efficient. Because you don’t need to install any extra software, there’s more room for application resources on your server.

Slide 6

Slide 6 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Ansible Architecture • Modules • Modules are like small programs that Ansible pushes out from a control machine to all the nodes / remote hosts. • The modules are executed using playbooks. • They control things such as services, packages and files. Ansible executes all the modules for installing updates or whatever the required task is, and then removes them when finished. • Ansible provides 400+ modules for common tasks

Slide 7

Slide 7 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ • Plugins • As many other tools and platforms, plugins are extra pieces of code that augment functionality. • Ansible comes with a number of its own plugins. • we can write your own as well.

Slide 8

Slide 8 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ • Inventory • All the machines you’re using with Ansible (the control machine plus nodes) are listed in a single simple file, with their IP addresses, names etc. • Once you list the inventory, you can assign variables to any of the hosts using a simple text file.

Slide 9

Slide 9 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ • Playbook • Ansible playbooks are like instruction manuals for tasks. • They are simple files written in YAML. (human-readable data serialization language). • Playbooks are really at the heart of what makes Ansible so popular because they describe the tasks to be done easily and without the need for the user to know or remember any special syntax. Not only can they declare configurations, but they can orchestrate the steps of any manually ordered task, and can execute tasks at the same time or at different times. • Each playbook is composed of one or multiple plays, and the goal of a play is to map a group of hosts to well- defined roles, represented by tasks.

Slide 10

Slide 10 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Ansible Tower • Ansible Tower is Red Hat’s commercial web-based solution for managing Ansible. • Its best-known feature is an easy-to-use UI for managing configurations and deployments, • Ansible Tower contains the most important features of Ansible, especially those that are easier to see in a graphical format rather than a text-based format.

Slide 11

Slide 11 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Practical example Ansible installed EC2 Manager EC2 node1 10.0.81.10 EC2 node2 10.0.81.11 EC2 node1 10.0.81.12

Slide 12

Slide 12 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Generate ssh key at Manager EC2 ssh-keygen

Slide 13

Slide 13 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Copy public key to remote (to node 1-2-3) • cat ~/.ssh/id_rsa.pub |ssh -i kkey.pem [email protected] "cat - >> ~/.ssh/authorized_keys” • Repeat above step to all 3 nodes

Slide 14

Slide 14 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Install ansible on Manager OR OR in ubuntu

Slide 15

Slide 15 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Every steps here onward to be execute on Manager (ansible installed instance)

Slide 16

Slide 16 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Basic config • Ansible by default install basic configs at /etc/ansible • Good practice is copy that and work on copy

Slide 17

Slide 17 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Configure hostfile • Since we have taken a copy we need to configure which host file to be used • Update ansible.cfg as follows

Slide 18

Slide 18 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Update hosts

Slide 19

Slide 19 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Verify [ad-hoc command] • Now we can verify that ansible can use all hosts or not

Slide 20

Slide 20 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Some more ad-hoc command • Add-hoc commands are the command can use directly on terminal without configure • -m à shell module • -a à argument

Slide 21

Slide 21 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/

Slide 22

Slide 22 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Failed – need sudo access

Slide 23

Slide 23 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ -b sudo access –K ask sudu password

Slide 24

Slide 24 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Verify user With ansible Without ansible

Slide 25

Slide 25 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Roles • Ansible will execute roles on target machines • Palybook can determine which role to which target machine • Role is directory under roles and need other directory call task and inside main.yml

Slide 26

Slide 26 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Install a package • nmap is not installed

Slide 27

Slide 27 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Create main.yml

Slide 28

Slide 28 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Create playbook

Slide 29

Slide 29 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ EXECUTE

Slide 30

Slide 30 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ verify nmap installed

Slide 31

Slide 31 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Configure additional packages

Slide 32

Slide 32 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Additional packages

Slide 33

Slide 33 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Variable substitution • Ansible can replace values with variable. • Lets see how we can use one install option and provide packages

Slide 34

Slide 34 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/

Slide 35

Slide 35 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Copy files • Create sample file at /home/ec2-user/data.txt vim roles/setup/tasks/main.yml

Slide 36

Slide 36 text

* http://www.krishantha.com * https://www.youtube.com/krish * https://www.linkedin.com/in/krish-din/ Execute and verify