automate with ansible basic (3/e)

50
[ chusiang @tossug ~ ] $ cat .profile # Author: 㲺Ռᗼ / chusiang (at) drx.tw # Blog: http://note.drx.tw # Modified: 2017-03-22 13: 44 3/e

Upload: chu-siang-lai

Post on 11-Apr-2017

44 views

Category:

Technology


1 download

TRANSCRIPT

[ chusiang@tossug ~ ] $ cat .profile # Author: / chusiang (at) drx.tw # Blog: http://note.drx.tw # Modified: 2017-03-22 13:44

3/e

3

OutlineI. IT

4

OutlineI. IT

II.

5

OutlineI. IT

II.

III. Ansible

6

OutlineI. IT

II.

III. Ansible

IV. Ansible

7

OutlineI. IT

II.

III. Ansible

IV. Ansible

V. Ansible

8

OutlineI. IT

II.

III. Ansible

IV. Ansible

V. Ansible

VI. Q & A

9

Ⅰ. IT

10

DevOps

DevOps Agile Tour by x Mina @ 2017.01.14

11

IT

12

IT IT

(hr) 30 (min)

code  code 

( )

Ⅱ.

13

※ = Configuration management (CM)

Ansible

- Ansible as Automation Glue14

" "

15

Ⅲ. Ansible

16

Ansible

Ender

- https://goo.gl/4xftZT17

Ansible DevOps

2013 4

DevOps

iThome - http://goo.gl/yJbWtz18

Ansible

• Puppet, SaltStack, Chef (Infrastructure as Code)

DevOps

• Push Python SSH Angent

• Python

19

Ⅳ. Ansible

20

Ansible inventory Managed node SSH Python

21

Ansible• Control Machine Ansible Managed node

Python 2.5+ SSH

22

# Debian & Ubuntu (apt).$ sudo apt-get install ansible

# RHEL & CentOS (yum).$ sudo yum install ansible

# Mac OS X (homebrew). $ brew install ansible

# Python (pip).$ sudo pip install ansible

Ansible• ansible.cfg inventory (host file)

Managed node ( ) SSH …

23

$ vim ansible.cfg[defaults] # inventory hostfile = hosts

# remote_user = docker#private_key_file = ~/.ssh/id_rsa

# host_key_checking: ssh host_key_checking = False

inventory • Managed node ( )

ssh

24

$ vim hosts # ansible_ssh_host: SSH # ansible_ssh_port: SSH (Port)# ansible_ssh_user: SSH # ansible_ssh_private_key_file: SSH # ansible_ssh_pass: SSH ( )[dev]ansible-demo ansible_ssh_host=127.0.0.1 ansible_ssh_pass=pwd

[test]ansible-test ansible_ssh_host=172.10.10.1 ansible_ssh_port=2222

[prod]ansible-prod ansible_ssh_host=10.10.10.1 ansible_ssh_user=deploy

Ⅴ. Ansible

25

Ad-Hoc command, Playbook* (Module)

Ad-Hoc command

and

26

Playbook

Ad-Hoc command • ( ) command line

27

# command line

$ ping ansible-demo.localPING localhost (127.0.0.1): 56 data bytes64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.037 ms

--- localhost ping statistics ---1 packets transmitted, 1 packets received, 0.0% packet lossround-trip min/avg/max/stddev = 0.037/0.037/0.037/0.000 ms

$ echo Hello WorldHello World

Ad-Hoc command • -m Ansible Module Index

28

# ansible < > -m < >

$ ansible all -m ping ansible-demo.local | SUCCESS => { "changed": false, "ping": "pong" }

$ ansible all -m command -a "echo Hello World"ansible-demo.local | SUCCESS | rc=0 >>Hello World

Playbooks

• Shell Script

• YAML code

• Play, Task, Module

• Jinja2 (template )

Baby Playbook Onesie - http://goo.gl/GKJvXn29

Playbooks • Playbook Play Tasks

• Play*1, Task*3 Module*3 (command, apt, lineinfile)

30

$ vim example.yml ---

- name: This is a Super-basic playbook. hosts: all tasks: - name: Hello World command: echo "Hello World"

- name: Install Vim & Emacs become: yes apt: name={{ item }} state=present with_items: - vim - emacs

# emacs - name: use vi-mode in readline become: yes lineinfile: dest=/etc/inputrc line="set editing-mode vi"

Playbooks • Playbook Play Tasks

• Play*1, Task*3 Module*3 (command, apt, lineinfile)

31

$ vim example.yml ---

- name: This is a Super-basic playbook. hosts: all tasks: - name: Hello World command: echo "Hello World"

- name: Install Vim & Emacs become: yes apt: name={{ item }} state=present with_items: - vim - emacs

# emacs - name: use vi-mode in readline become: yes lineinfile: dest=/etc/inputrc line="set editing-mode vi"

Play

Playbooks • Playbook Play Tasks

• Play*1, Task*3 Module*3 (command, apt, lineinfile)

32

$ vim example.yml ---

- name: This is a Super-basic playbook. hosts: all tasks: - name: Hello World command: echo "Hello World"

- name: Install Vim & Emacs become: yes apt: name={{ item }} state=present with_items: - vim - emacs

# emacs - name: use vi-mode in readline become: yes lineinfile: dest=/etc/inputrc line="set editing-mode vi"

Task 1

Task 2

Task 3

Playbooks • Playbook Play Tasks

• Play*1, Task*3 Module*3 (command, apt, lineinfile)

33

$ vim example.yml ---

- name: This is a Super-basic playbook. hosts: all tasks: - name: Hello World command: echo "Hello World"

- name: Install Vim & Emacs become: yes apt: name={{ item }} state=present with_items: - vim - emacs

# emacs - name: use vi-mode in readline become: yes lineinfile: dest=/etc/inputrc line="set editing-mode vi"

Module

Playbooks • playbook

34

$ ansible-playbook example.yml

PLAY [This is a Super-basic playbook.] *****************************************

TASK [setup] *******************************************************************ok: [ansible-demo.local]

TASK [Hello World] *************************************************************changed: [ansible-demo.local]

TASK [Install Vim & Emacs] *****************************************************changed: [ansible-demo.local] => (item=[u'vim', u'emacs'])

TASK [use vi-mode in readline] *************************************************changed: [ansible-demo.local]

PLAY RECAP *********************************************************************ansible-demo.local : ok=4 changed=3 unreachable=0 failed=0

Playbooks • playbook

35

$ ansible-playbook example.yml

PLAY [This is a Super-basic playbook.] *****************************************

TASK [setup] *******************************************************************ok: [ansible-demo.local]

TASK [Hello World] *************************************************************changed: [ansible-demo.local]

TASK [Install Vim & Emacs] *****************************************************changed: [ansible-demo.local] => (item=[u'vim', u'emacs'])

TASK [use vi-mode in readline] *************************************************changed: [ansible-demo.local]

PLAY RECAP *********************************************************************ansible-demo.local : ok=4 changed=3 unreachable=0 failed=0

Setup

(Recap)

Module

36

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

Docs » commands Modules

yes

https://goo.gl/ntmX4n

Practice

41

Control Machine (Ubuntu 14.04) + Managed node*2 (Debian 8, CentOS 6)

Ansible Jupyter Managed node

42

Chu-Siang Lai / [email protected]

Play the Ansible on Jupyter notebook !

• Ansible Docs - http://docs.ansible.com/ansible/intro_installation.html

• Ansible: Up and Running - https://www.ansible.com/ansible-book

• Ansible (7:15) | Software Architecture School - http://goo.gl/nhykzE

• Ansible - http://get.soft-arch.net/ansible/

• | ・ - http://school.soft-arch.net/blog/90699/

metaphor-in-cm

• Ansible by sakana / Max - https://goo.gl/e9RwhE

• Ansible | - http://goo.gl/5gs1q9

• IT Ansible - https://goo.gl/EOjs4I

44

Free

• Blasts Off Space Rocket From Cosmodrom In The Clouds, Polygonal Stock Illustration | dreamstime - http://goo.gl/6FAuiQ

• - http://www.ngtaiwan.com

• Using cloud-init and uvtool to initialize cloud instances | Rui - https://goo.gl/CbdvTH

• Books icon (PSD) | GraphicsFuel - http://www.graphicsfuel.com/2012/07/books-icon-psd/

• Avatar, business, company, group, manager, people, users icon | Icon search engine - https://goo.gl/Hm6ScX

• A Galaxy Just Appeared Out of Nowhere - http://chirpnews.com/2016/04/17/new-galaxy-appeared/

45

46

http:// .tw

DevOps Taiwan

https://www.facebook.com/groups/DevOpsTaiwan/

https://devopstaiwan.slack.com/

https://gitter.im/DevOpsTW/

Ansible Taiwan

https://telegram.me/ansible_tw

https://github.com/ansible-tw

http://ansible.tw

Q & A

49

E N D