ansible - 'half of it nobody understands anyway.' · i ansible:createprogram i...

65
Ansible ... ”Half of it nobody understands anyway.” Dr. Bernhard Hopfenmüller 16.10.2018

Upload: others

Post on 25-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ansible ...”Half of it nobody understands anyway.”

Dr. Bernhard Hopfenmüller

16.10.2018

Page 2: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

whoami

Bernhard HopfenmüllerIT Consultant @ ATIX AG

IRC: Fobhepgithub.com/Fobhep

#atix #osad2018

Page 3: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

whoarewe

The Linux & Open Source CompanyGarching @ München

over 15 yearsdatacenter automation, Linux

Consulting, Engineering, Support,Training

#atix #osad2018

Page 4: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ender’s Game

imdb.com

#atix #osad2018

Page 5: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ansible in a nutshell

Ansible ...

I ... is „radically simple“

I ... requires: 1 Unixnode, SSH,Python

I ... needs no agent

I ... describes the desired state

I ... is written in YAML

I ... satisfies idempotency

#atix #osad2018

Page 6: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Run Ansible

I User: Write Statements

I Ansible: Create program

I Ansible: Copy program to Run-Node

I Ansible: Connect to Run-Node (local, SSH, PowerShell )

I Ansible: Run Program

I Ansible: Communication via JSON

I Ansible: Delete local Program

I Ansible: Give Feedback to User

#atix #osad2018

Page 7: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ansible dict

I Inventory - infrastructure as code

I Adhoc mode - one task + terminal

I Playbook - collection of tasks/roles

I Role - one collection of tasks

I Task - one Ansible command:’apt-get install nano’

I Jinja 2 templating - e.g. forvariables

I Modules - core-components:yum module, ping module,...communication via JSON

#atix #osad2018

Page 8: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Inventory

[dbserver]db1.server.comdb2.server.com

[webserver]web1.server.com ansible_host=4.8.15.16web2.server.com ansible_host=4.8.23.42

[appserver]app1.server.com default_port=23app2.server.com default_port=69105

I defining the infrastructure

I ini or yaml syntax

I combine servers into groups

I define specific vars

#atix #osad2018

Page 9: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ad-hoc mode

I run only one task quickly

I either one-timer or quickerthan playbook

$ ansible webserver -m patch \-a \"src=/src/critical.patch \dest=/app/bin/base"

$ ansible webserver -a "sbin/reboot"

$ ansible webserver -m ping

#atix #osad2018

Page 10: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Playbook

---- hosts: webserver # where ?

become: true # run as rootroles:

- bake_server # role1- gitlab # role2

I combination of roles

I written in YAML (orJSON)-Syntax

I ideally in combination withVCS

#atix #osad2018

Page 11: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Role

I combination of tasks

I featuring idempotency

I ideally in combination withVCS

---- name: Install GitLab dependencies

yum:name: "{{ item }}"state: latest

loop:- openssh-server- postfix- curl- openssl

- name: Install GitLabyum:

name: "{{ gitlab-version }}"state: present

- name: Copy config filetemplate:

src: gitlab.rb.j2dest: /etc/gitlab/gitlab.rbmode: 0600

notify: restart gitlab...

#atix #osad2018

Page 12: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Questions - so far?

https://imgflip.com/

#atix #osad2018

Page 13: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Some RL- Stories

unrelated cat-content

#atix #osad2018

Page 14: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

My variable is not working!!”

#atix #osad2018

Page 15: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

---a_dict:

foo: "fine!"

#atix #osad2018

Page 16: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

--- # don't forget this!a_dict:

foo: "fine!"foo42: "meh- but ok"

#atix #osad2018

Page 17: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

--- # don't forget this!a_dict:

foo: "fine!"foo42: "meh- but ok"foo-two: "no!"

#atix #osad2018

Page 18: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

--- # don't forget this!a_dict:

foo: "fine!"foo42: "meh- but ok"foo-two: "no!"foo.bar: "oh god, noo!"

#atix #osad2018

Page 19: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

--- # don't forget this!a_dict:

foo: "fine!"foo42: "meh- but ok"foo-two: "no!"foo.bar: "oh god, noo!"foo bar: "what??!"

#atix #osad2018

Page 20: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

--- # don't forget this!a_dict:

foo: "fine!"foo42: "meh- but ok"foo-two: "no!"foo.bar: "oh god, noo!"foo bar: "what??!"12: "... oO"

#atix #osad2018

Page 21: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

--- # don't forget this!a_dict:

foo: "fine!"foo42: "meh- but ok"foo-two: "no!"foo.bar: "oh god, noo!"foo bar: "what??!"12: "... oO"foo_12: "yes!!"

#atix #osad2018

Page 22: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

“Ansible is not working!”

#atix #osad2018

Page 23: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

---ver_1: 2.4.2ver_2: 2.5

- name: Diff versionsdebug:

msg: "Version 1 is smaller!"when: ver1 < ver2 # Nope!

#atix #osad2018

Page 24: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

YAML - everything easy, or not?!

---ver_1: "2.4.2"ver_2: "2.5"

- name: Diff versionsdebug:

msg: "Yeah!"when: ver1 < ver2 # YipYip!

#atix #osad2018

Page 25: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

ooor...be smart ;)

Filters ftw!!

{{ ver2 | version_compare('ver1', '>=') }}

#atix #osad2018

Page 26: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Easy life with filters

“We need this, but it’s impossible in Ansible!”

#atix #osad2018

Page 27: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Easy life with filters

Add a new entry to a dict? Make use of implemented filters!

---vars:

dict:foo: "bar"foo2: "bar2"

tasks:- set_fact:

dict: "{{ dict | combine( { 'foo3': 'bar3' } ) }}"...

Fair enough - but what about removing a key?

#atix #osad2018

Page 28: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Easy life with filters

Real life example: PUT- Request to REST - API

body = {"id":"01189998819991197253","label":"plugin","skip_production": true #< we don't want this!}

#atix #osad2018

Page 29: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Easy life with filters

imgflip.com

a while later...

#atix #osad2018

Page 30: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Easy life with filters

---- set_fact:

body: "{{ {} |combine({item.key: item.value})}}"when: "{{item.key not in ['skip_production']}}"with_dict: "{{ body }}"

...

imgflip.com

#atix #osad2018

Page 31: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Easy life with filters

---- set_fact:

body: "{{ {} |combine({item.key: item.value})}}"when: "{{item.key not in ['skip_production']}}"with_dict: "{{ body }}"

...

imgflip.com

#atix #osad2018

Page 32: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Easy life with filters

imgflip.com

another while later...

#atix #osad2018

Page 33: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

#filter_plugins/remove_key.py#!/usr/bin/pythonclass FilterModule(object):

def filters(self):return {

'remove_key': self.remove_key}

def remove_key(self,old_dict,key):old_dict.pop(key, None)return old_dict

---- set_fact:

body: "{{ body | remove_key('skip_production') }}"...

#atix #osad2018

Page 34: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

#filter_plugins/remove_key.py#!/usr/bin/pythonclass FilterModule(object):

def filters(self):return {

'remove_key': self.remove_key}

def remove_key(self,old_dict,key):old_dict.pop(key, None)return old_dict

---- set_fact:

body: "{{ body | remove_key('skip_production') }}"...

#atix #osad2018

Page 35: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

---- set_fact:

body: "{{ body | remove_key('skip_production') }}"...

imgflip.com

accurate face expression

#atix #osad2018

Page 36: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

---- set_fact:

body: "{{ body | remove_key('skip_production') }}"...

imgflip.com

accurate face expression

#atix #osad2018

Page 37: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ansible-CLI

“”Wait? There’s more than ansible and ansible-playbook?””

#atix #osad2018

Page 38: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ansible-CLI

ansible-galaxy

I search public roles

I create a template for roles

I ...

#atix #osad2018

Page 39: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ansible-CLI

ansible-doc

I offline documentation

I any plugin type

I ...

#atix #osad2018

Page 40: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ansible-CLI

ansible-console

I Ansible REPL

I test stuff quickly, e.g. jinja...

I ...

#atix #osad2018

Page 41: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ansible-CLI

ansible-pull

I automize your automation

I reset system automatically

I speed up!

I ...

#atix #osad2018

Page 42: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

It’s slooow...

#atix #osad2018

Page 43: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 44: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 45: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 46: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 47: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 48: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 49: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 50: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 51: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 52: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 53: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

What are you doing Ansible

I scan used module for python deps

I add create script and add it and deps to ZIP-file

I base64 encoding of ZIP-file

I write content to local filesystem for sftp

I find target user home dir

I create temp dir in user home

I sftp ZIP

I run script on target (16 quote layering! 10 steps including fileoperations)

I rm temp dir on target

#atix #osad2018

Page 54: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Forking

forks = 5 # default# parallel Ansible processes i.e. number of hosts

#atix #osad2018

Page 55: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Async

- name: I will work while the rest goes onpip:

requirements: requirements.txtasync: 1000 # choose this high enough!poll: 0 # fire and forget!register: pip_install

- name: More tasks....[....]

- name: Deploy a python app.. I might crash :(

#atix #osad2018

Page 56: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Async

- name: I will work while the rest goes onpip:

requirements: requirements.txtasync: 1000 # choose this high enough!poll: 0 # fire and forget!register: pip_install

- name: More tasks....[....]

- name: PIP result checkasync_status:

jid: "{{ pip_install.ansible_job_id }}"register: job_resultuntil: job_result.finishedretries: 30

- name: Deploy a python app.. I am happy now :)

#atix #osad2018

Page 57: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

SSH Pipelining

[ssh_connection]pipelining = True

Careful: This needs to disable requiretty’ in /etc/sudoers on all managedhosts

#atix #osad2018

Page 58: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Mitogen

I Python library

I self reproducing programs(cells: Mitosis)

I “network-capable fork() onsteroids”

I “lazily-loaded duplicates onremote hosts, withoutrequiring any upfront remotedisk writes”

I tl;dr: similar to SSH-Pipelinebut no “require-tty problem”

I facts only: ”1.25x - 7xspeedup + CPU usagereduction >= 2x”

#atix #osad2018

Page 59: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Mitogen

I Python library

I self reproducing programs(cells: Mitosis)

I “network-capable fork() onsteroids”

I “lazily-loaded duplicates onremote hosts, withoutrequiring any upfront remotedisk writes”

I tl;dr: similar to SSH-Pipelinebut no “require-tty problem”

I facts only: ”1.25x - 7xspeedup + CPU usagereduction >= 2x”

https://mitogen.readthedocs.io/en/latest/

_images/cell_division.png

#atix #osad2018

Page 60: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Mitogen

I Python library

I self reproducing programs(cells: Mitosis)

I “network-capable fork() onsteroids”

I “lazily-loaded duplicates onremote hosts, withoutrequiring any upfront remotedisk writes”

I tl;dr: similar to SSH-Pipelinebut no “require-tty problem”

I facts only: ”1.25x - 7xspeedup + CPU usagereduction >= 2x”

https://mitogen.readthedocs.io/en/latest/

_images/cell_division.png

#atix #osad2018

Page 61: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Mitogen

I Python library

I self reproducing programs(cells: Mitosis)

I “network-capable fork() onsteroids”

I “lazily-loaded duplicates onremote hosts, withoutrequiring any upfront remotedisk writes”

I tl;dr: similar to SSH-Pipelinebut no “require-tty problem”

I facts only: ”1.25x - 7xspeedup + CPU usagereduction >= 2x”

https://mitogen.readthedocs.io/en/latest/

_images/cell_division.png

#atix #osad2018

Page 62: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Mitogen

I Python library

I self reproducing programs(cells: Mitosis)

I “network-capable fork() onsteroids”

I “lazily-loaded duplicates onremote hosts, withoutrequiring any upfront remotedisk writes”

I tl;dr: similar to SSH-Pipelinebut no “require-tty problem”

I facts only: ”1.25x - 7xspeedup + CPU usagereduction >= 2x”

https://mitogen.readthedocs.io/en/latest/

_images/cell_division.png

#atix #osad2018

Page 63: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Mitogen

I Python library

I self reproducing programs(cells: Mitosis)

I “network-capable fork() onsteroids”

I “lazily-loaded duplicates onremote hosts, withoutrequiring any upfront remotedisk writes”

I tl;dr: similar to SSH-Pipelinebut no “require-tty problem”

I facts only: ”1.25x - 7xspeedup + CPU usagereduction >= 2x”

https://mitogen.readthedocs.io/en/latest/

_images/cell_division.png

#atix #osad2018

Page 64: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

The End

More questions - your story?

#atix #osad2018

Page 65: Ansible - 'Half of it nobody understands anyway.' · I Ansible:Createprogram I Ansible:CopyprogramtoRun-Node I Ansible:ConnecttoRun-Node(local,SSH,PowerShell) I Ansible:RunProgram

Ansible Training

atix.de/training/ansible-training/

I 2 or 3 days

I Hands-on based

I topics include

I Ansible basicsI From Paper to PlaybookI Jinja TemplatingI Ansible + VCS

...

#atix #osad2018