ansible - t-dose · index introduction installing & configuration playbooks variables roles...
TRANSCRIPT
![Page 2: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/2.jpg)
Index
● Introduction● Installing & configuration● Playbooks● Variables● Roles● Ansible galaxy● Configuration management tool● Add hoc usage
![Page 3: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/3.jpg)
IntroductionMarcel Nijenhof
● Computational physics● 20 years unix & linux
administrator● Games
– Britannica, 1861
– http://megagame-makers.nl
● Proxy & Rijkswaterstaat
![Page 4: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/4.jpg)
IntroductionDemos, Exercises & Questions
● Demos, Exercises– There is a lot time for
demos & exercises
– Based on CentOS 7
● Questions– Are welcome during the
lecture
![Page 5: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/5.jpg)
IntroductionAnsible
● A configuration management tool– Automatic deployment of system configurations
– Maintain configuration during live cycle
– Uses a dsl to specify the desired state
● Comparable with– Puppet, Cfengine, chef, …
![Page 6: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/6.jpg)
IntroductionDifferences with puppet
● Uses “ssh” for connection– No client software needed
● Sshd
● Sudo
● python
● No master!– No default running components
● Ssh
● python
● Crontab + authorized account
● Dsl is in yaml
● Written in python
![Page 7: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/7.jpg)
Introductioncompare config management tools
Language License Agent-less First release Latest stable release
Ansible Python GPL Yes 2012-03-08 2015-04-28 1.9.1
Chef Ruby, Erlang Apache Yes 2009-01-15 2014-12-16 12.0.3
CFEngine C GPL, COSL No 1993 2014-12-05 3.6.3
Puppet Ruby Apache No 2005-08-30 2015-03-26 3.7.5
https://en.wikipedia.org/wiki/Comparison_of_open-source_configuration_management_software
![Page 8: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/8.jpg)
Installing & configurationFinish
![Page 9: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/9.jpg)
Installing & configurationAnsible “master” (CentOS 7)
● Activate epel– https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
– yum install epel-release-latest-7.noarch.rpm
● Install ansible– yum install ansible
● Version: 1.9.2
● Debian 8:
– apt-get install ansible● Version: 1.7.2
![Page 10: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/10.jpg)
Installing & configurationMaster configuration
● Configuration files– /etc/ansible/ansible.cfg
● Settings of ansible– Defaults work!
● User version of the file– ~/.ansible.cfg
– /etc/ansible/hosts● List of ansible clients
– Group membership– Connection information
● You need to configure your clients
![Page 11: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/11.jpg)
Installing & configurationansible host file
● List of groups– Ini format file
– List of hosts in the group● Hosts can be member of more then one group● Extra information per hosts is possible
– Ssh port– connection information– variables
– Groups of groups is possible
![Page 12: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/12.jpg)
Installing & configurationhost file example
localhost
misc.example.lan
[db]
db-prim.example.lan
db-slave.example.lan
[web]
web*.example.lan
![Page 13: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/13.jpg)
Installing & configurationDemo: Ansible master
![Page 14: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/14.jpg)
Installing & configurationclient requirements
● Software:– Ssh server
– Sudo
– python
● Privileges:– Login with ssh
– Any sudo command
![Page 15: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/15.jpg)
Installing & configurationThe client (CentOS 7)
● Add the client to ansible host file● Login with ssh (with keys)
– Ssh-copy-id
– It's possible to use ansible with ssh passwords
● Make sure that sudo works for all commands– <user> ALL=(ALL) ALL
– Sudo without tty is preferred
– Without passwords● Or supply sudo password through ansible
![Page 16: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/16.jpg)
Installing & configurationTest the client
● ansible <client> -m ping– $ ansible d4-193 -m ping
d4-193 | success >> { "changed": false, "ping": "pong"}
● ansible <client> -m raw -s -a “id” – $ ansible d4-193 -m raw -s -a id
d4-193 | success | rc=0 >>uid=0(root) gid=0(root) groups=0(root) ...
![Page 17: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/17.jpg)
Installing & configurationDemo: Ansible client
![Page 18: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/18.jpg)
Installing & configurationFinish
![Page 19: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/19.jpg)
Playbooksrecipe to install and/or configure software
● Written in yaml● Contains
– options how to install● Host list● User for the installation
– Program logic● Variables● Conditionals● Loops
– Include statements
– Calls to ansible modules
● Description of the desired state
![Page 20: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/20.jpg)
PlaybooksModules
● http://docs.ansible.com/ansible/list_of_all_modules.html
● Many (> 100)
– Files:● File● Copy● Template
– Packages:● Yum● Apt
– User
– ...
![Page 21: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/21.jpg)
Playbooksyaml
● https://en.wikipedia.org/wiki/YAML● A format to serialize data
– A yaml file start with “---”● One “os file” can contain multiple yaml files
– Can contains hashes:● key: value
– Can contain arrays● Each elemement start with a “-”
– It's possible to nest data structures● Indention is used to specify nesting
![Page 22: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/22.jpg)
Playbooksyaml example
---
Persoon:
- Name: Marcel Nijenhof
Games:
- Britannia
- 1861
- Name: ...
![Page 23: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/23.jpg)
Playbooksyaml & ansible
---- hosts: localhost become: no tasks: - name: Ansible hello world debug: msg=”Hello world”
![Page 24: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/24.jpg)
PlaybooksDemo: Ansible hello world
![Page 25: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/25.jpg)
Playbooksvariables
- vars: name: marceln comment: Marcel Nijenhof- name: Create a user user: comment={{ comment }} name={{ name }} …
NOTE:
This example is not usefull.
![Page 26: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/26.jpg)
PlaybooksConditionals
- name: install apache on redhat yum: name: http state: installed
when: ansible_os_family == 'RedHat'
- name: install apache on Debian apt: name: apache2 state: installed when: ansible_os_family == 'Debian'
![Page 27: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/27.jpg)
PlaybooksLoops
● http://docs.ansible.com/ansible/playbooks_loops.html
● with_items– Loop over a array
● with_nested– Loop over 2 or more arrays
● with_dict– Loop over hashes
● ...
![Page 28: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/28.jpg)
Playbookswith_items
- vars:
pkg:
- httpd
- php
- name: Install package list
yum: name=”{{ item }}” state=present
with_items: “{{vars}}”
![Page 29: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/29.jpg)
PlaybooksDemo: with_items
![Page 30: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/30.jpg)
Playbookswith_dict (definitie)
vars:
users:
marceln:
uid: 1000
comment: “Marcel Nijenhof”
luc:
uid: 1001
Comment: “Luc Nieland”
![Page 31: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/31.jpg)
Playbookswith_dict (code)
- name: Add users
user: name=item.key comment=item.value.comment uid=item.value.uid
with_dict: "{users}"
![Page 32: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/32.jpg)
PlaybooksDemo: with_dict
![Page 33: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/33.jpg)
PlaybooksFinish
![Page 34: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/34.jpg)
Variablessources
● Source of variables– Facts
● Running os
– Registered variables● Values from earlier tasks
– Host declaration ● Inventory file● host_vars● group_vars
– From code● Default values● Standard values from code
![Page 35: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/35.jpg)
Variablessources
● Source of variables– Facts
● Running os
– Registered variables● Values from earlier tasks
– Host declaration ● Inventory file● host_vars● group_vars
– From code● Default values● Standard values from code
![Page 36: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/36.jpg)
Variablesfacts (setup)
● ansible d4-193 -m setup– Gives a list of facts of the system
● ansible_distribution● ansible_os_family● ansible_processor
– These values can be used in playbooks● See “Playbooks conditionals”
![Page 37: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/37.jpg)
Variablesfacts (setup)
d4-193 | success >> {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"192.168.104.193"
],
...
"ansible_architecture": "x86_64",
"ansible_bios_date": "04/01/2014",
…
"ansible_distribution": "CentOS",
"ansible_distribution_major_version": "7",
...
![Page 38: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/38.jpg)
VariablesDemo: setup
![Page 39: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/39.jpg)
Variablesregistered variables
● register: <name>– Store results of command in a variable
● This is a data structure!● <name>.rc: Return code● <name>.stdout: Standard out
– Use this result in later tasks● Debug: var=<name>
![Page 40: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/40.jpg)
VariablesDemo: registered variables
![Page 41: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/41.jpg)
Variableshost_vars, group_vars
● host_vars/<hostname>.yaml– Variables for a specific host
● group_vars/<group name>.yaml– Variables for a specific group
● Just a yaml file with a data structure:– ---
var: value
![Page 42: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/42.jpg)
VariablesDemo: host_vars
![Page 43: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/43.jpg)
VariablesFinish
![Page 44: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/44.jpg)
Rolesset of files to implement one function
● Set of files to implement one function– Installing a apache server
– Contains● Tasks to install en configure the server● Variables needed for the installation
– Package names for RedHat or Debian
● Default settings– Port 80
● There is a library with roles!!– First search before writing.
![Page 45: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/45.jpg)
RolesLayout
● README.md: Documentation of the module● tasks: Task list for installation/configuration● handlers: Task list for events● defaults: Default values variables● vars: Variables needed for install● files: File store● templates: Template store● meta: Package information
![Page 46: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/46.jpg)
RolesTemplate role
● ansible-galaxy init <user>.<rolename>– Creates the default directory setup
– Just fill in the details
![Page 47: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/47.jpg)
RolesREADME.md
● Documentation of the module– Standard github markup
– Contains:● Requirements● Used variables● Dependencies● Example Playbook● License
![Page 48: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/48.jpg)
Rolestasks
● Contains:– main.yml
May include:● include_vars: "{{ ansible_os_family }}.yml"● install.yml● config.yml● …
– Contains tasks for install en configuration.● Notify command for handlers
– Service reload
![Page 49: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/49.jpg)
Rolesdefaults
● main.yml– Contains default values for variables
– Overrule with:● host_vars● group_vars● code
![Page 50: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/50.jpg)
Rolesvars
● Defaults for various platforms– RedHat.yml
● apache_pkg: httpd● apache_config_dir: /etc/httpd/conf.d
– Debian.yml● apache_pkg: apache2● apache_config_dir: /etc/apache2
![Page 51: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/51.jpg)
Rolesmydemocontent
● Distribute our content “index.html”– Uses vars for RedHat and Debian
● In the correct directory● Under the correct user
● Create the module– mkdir roles
– cd roles
– ansible-galaxy init mydemocontent
![Page 52: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/52.jpg)
RolesDemo: mydemocontent
![Page 53: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/53.jpg)
Rolesmydemocontent/tasks/main.yml
---
# tasks file for mydemocontent
- name: Include os dependend config
include_vars: "{{ ansible_os_family }}.yml"
- name: Copy our content
copy:
src=index.html
dest="{{ docroot }}"
owner="{{ docowner }}"
![Page 54: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/54.jpg)
Rolesmydemocontent/vars/RedHat.yml
---
docroot: /var/www/html
docowner: apache
![Page 55: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/55.jpg)
Rolesmydemocontent/files/index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head> <meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org" /> <title>Demo</title></head>
<body> <h1>Demo</h1> <p>Demo file placed by ansible</p></body></html>
![Page 56: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/56.jpg)
RolesFinish
![Page 57: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/57.jpg)
Ansible galaxylibrary
● Library for roles– https://galaxy.ansible.com/list#/roles
– > 4000 roles
– Not always easy to find the best role!
● Ansible-galaxy– install
– init
– ...
![Page 58: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/58.jpg)
Ansible galaxyInstalling a role
● Search the website– marcelnijenhof.firewalld
● Install the role– Ansible-galaxy install marcelnijenhof.firewalld
● Default install in /etc/ansible/roles● Use the “-p <dir>” for other locations
![Page 59: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/59.jpg)
Ansible galaxyDemo: Download a role
![Page 60: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/60.jpg)
Ansible galaxyadding your role
● Create the code● Add it to github● Login in galaxy with your github account● Register your git project on galaxy
![Page 61: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/61.jpg)
Ansible galaxyFinish
![Page 62: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/62.jpg)
Configuration management toolPutting everything together
● site.yml: Includes all code for the site:– webservers.yml: Code for webservers
● Include the correct roles
– ...
● roles● host_vars● groups_vars
![Page 63: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/63.jpg)
Configuration management toolsite.yml
---
- include: web.yml
- include: centos7.yml
![Page 64: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/64.jpg)
Configuration management toolweb.yml
---
- hosts: web
become: yes
become_user: root
roles:
- geerlingguy.apache
- marcelnijenhof.firewalld
- mydemocontent
![Page 65: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/65.jpg)
Configuration management toolRunning the code
● ansible-playbook site.yml– When users want
– Through crontab by a dedicated user
– ...
![Page 66: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/66.jpg)
Configuration management toolDemo: putting everything together
![Page 67: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/67.jpg)
Configuration management toolFinish
![Page 68: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/68.jpg)
Add hoc usagethe reality
● Many different systems without central configuration management– Everything will be better after we rebuild everything
– It's to cumbersome to implement central configuration management on old systems
● You are just hired to do one project● But still we need more control now!!
![Page 69: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/69.jpg)
Add hoc usageWhat if you just want to do one task
● Just one task– Add the same users on 200 systems– Update security settings– Upgrade a application
● It's possible– You don't need to set up anything on the client– Just one ansible server
● And that could be your laptop!
– A inventory
– One small playbook
![Page 70: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/70.jpg)
Add hoc usageFinish
![Page 71: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/71.jpg)
More info
● http://docs.ansible.com/● http://pion.xs4all.nl/lezingen/ansible-2015.pdf
![Page 72: Ansible - T-DOSE · Index Introduction Installing & configuration Playbooks Variables Roles Ansible galaxy Configuration management tool Add hoc usage](https://reader034.vdocument.in/reader034/viewer/2022052516/5b7902eb7f8b9ad77e8c8bac/html5/thumbnails/72.jpg)
questions