ansible rychlý úvod - soit · deploying new servers “install this software on this servers.”...

29
Ansible rychlý úvod Věroš Kaplan @verosk http://inuits.eu/ http://veroskaplan.cz/

Upload: others

Post on 27-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Ansiblerychlý úvod

Věroš Kaplan@verosk

http://inuits.eu/

http://veroskaplan.cz/

Page 2: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Managing computers

“It’s quick change here and there…”“And fix this, please.”“Install this software. Fix it.”

Page 3: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Deploying new servers

“Install this software on this servers.”“Make a copy of this machine and change something.”ASAP

2 servers ->

Page 4: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Image by Torkild Retvedt, CC BY SA

Page 5: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

PuppetOne manifest rules them all!

… a potom!

Page 6: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->
Page 7: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

… but after some time

● lost in curly brackets● lost in manifest dependencies● lost in duplicate resource names

● a bit lost in Ruby● puppet master can’t be bootstrapped by

Puppet● OOM

DISCLAIMER: in fact, not Puppet problem, but my bad usage of Puppet!

Page 8: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Ansible

You can start in minutesNo agent installation

Readable recipesPython insideJinja inside

http://ansible.com/http://github.com/ansible/ansible

Page 9: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

AnsibleIn fact, it’s parallel ssh...

…. but done in smart way.

Page 10: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

● deployment of internal systems○ owncloud, iSCSI…○ whatever…

● automation of error-prone tasks○ resize file system, LVM and pack it○ mass configuration of KVM guests○ deploy testing machine (6 times a day)

● authorized_keys

(My) usage

Page 11: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Installation

$ yum install ansible||

$ pip install ansible

Page 12: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Hello, Ansible!

$ ansible -i hosts -m ping all

astarte | success >> { "changed": false, "ping": "pong"}

Page 13: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Run ansible module

$ ansible -i hosts -m ping all

inventory file

module

host selection

Page 14: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->
Page 15: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

SSH key distribution

$ ansible -i hosts -m authorized_key \-a “user=root key=’ssh-rsa …. verosk’ ” \all

…40 hosts OK

Page 16: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Simple playbook

● YAML based● list of tasks

$ ansible-playbook -i hosts playbook.yml -v

Page 17: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->
Page 18: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->
Page 19: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->
Page 20: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Role based playbook

● machine roles are defined○ webserver, DB server, KVM server,...○ role is YAML playbook

● machines in groups○ by inventory file

● roles are applied to machines || groups

● roles depends on each other

Page 21: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->
Page 22: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->
Page 23: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Interesting features

handlersregister_variablefailed_whenignore_errorsnotifydelegate_touser, sudo_user

tagsasync_taskwith_items, with_*

ansible-pullansible-vault

Page 24: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

FAQ

Page 25: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Reusable roles?

http://galaxy.ansible.com/

Page 26: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

$ ansible -c local localhost -m setup

local facts in/etc/ansible/facts.d/

Facts

Page 27: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Distribution dependent playbooks

- message: Debian when: ansible_os_distribution == ‘debian’

- include_vars: {{ansible_os_distribution}}

https://galaxy.ansible.com/list#/roles/1229

Page 28: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

Demo time?

Page 29: Ansible rychlý úvod - SOIT · Deploying new servers “Install this software on this servers.” “Make a copy of this machine and change something.” ASAP 2 servers ->

in Vagrant

https://github.com/VerosK/vagrant-playground-logstash-kibana

Logstash (E+L+K)