Word or Excel Tutorial - Automate Tasks With Visual Basic Macros
Automate with Ansible basic (2/e)
-
Upload
chu-siang-lai -
Category
Technology
-
view
129 -
download
2
Transcript of Automate with Ansible basic (2/e)
![Page 1: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/1.jpg)
[ chusiang@secret ~ ] $ cat .profile # Author: / chusiang.lai (at) gmail.com # Blog: http://note.drx.tw # Modified: 2017-03-09 15:54
2nd
![Page 2: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/2.jpg)
• (@chusiang_lai)
• 1 Ansible
• Roles
• php7 (php-fpm)
• switch-apt-mirror
• vim-and-vi-mode
• zabbix-agent
2
![Page 3: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/3.jpg)
3
![Page 4: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/4.jpg)
OutlineI. IT
4
![Page 5: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/5.jpg)
OutlineI. IT
II.
5
![Page 6: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/6.jpg)
OutlineI. IT
II.
III. Ansible
6
![Page 7: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/7.jpg)
OutlineI. IT
II.
III. Ansible
IV. Ansible
7
![Page 8: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/8.jpg)
OutlineI. IT
II.
III. Ansible
IV. Ansible
V. Ansible
8
![Page 9: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/9.jpg)
OutlineI. IT
II.
III. Ansible
IV. Ansible
V. Ansible
VI. Q & A
9
![Page 10: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/10.jpg)
Ⅰ. IT
10
DevOps
![Page 11: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/11.jpg)
IT
11
IT IT
(hr) 30 (min)
code code
( )
![Page 12: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/12.jpg)
Ⅱ.
12
※ = Configuration management (CM)
![Page 14: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/14.jpg)
" "
14
![Page 15: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/15.jpg)
Ⅲ. Ansible
15
![Page 16: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/16.jpg)
Ansible
Ender
- https://goo.gl/4xftZT16
![Page 18: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/18.jpg)
Ansible
• Puppet, SaltStack, Chef (Infrastructure as Code)
DevOps
• Push Python SSH Angent
• Python
18
![Page 19: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/19.jpg)
Ⅳ. Ansible
19
![Page 20: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/20.jpg)
Ansible inventory Managed node SSH Python
20
![Page 21: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/21.jpg)
Ansible• Control Machine Ansible Managed node
Python 2.5+ SSH
21
# 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
![Page 22: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/22.jpg)
Ansible• ansible.cfg inventory (host file)
Managed node ( ) SSH …
22
$ vim ansible.cfg[defaults] # inventory hostfile = hosts
# remote_user = docker#private_key_file = ~/.ssh/id_rsa
# host_key_checking: ssh host_key_checking = False
![Page 23: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/23.jpg)
inventory • Managed node ( )
ssh
23
$ 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
![Page 24: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/24.jpg)
Ⅴ. Ansible
24
Ad-Hoc command, Playbook* (Module)
![Page 25: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/25.jpg)
Ad-Hoc command
and
25
Playbook
![Page 26: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/26.jpg)
Ad-Hoc command • ( ) command line
26
# 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
![Page 27: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/27.jpg)
Ad-Hoc command • Ansible -m
Module Index
27
# 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
![Page 28: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/28.jpg)
Playbooks
• Shell Script
• YAML code
• Play, Task, Module
• Jinja2 (template )
Baby Playbook Onesie - http://goo.gl/GKJvXn28
![Page 29: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/29.jpg)
Playbooks • Playbook Play Tasks
• Play*1, Task*3 Module*3 (command, apt, lineinfile)
29
$ 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"
![Page 30: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/30.jpg)
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"
Play
![Page 31: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/31.jpg)
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"
Task 1
Task 2
Task 3
![Page 32: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/32.jpg)
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"
Module
![Page 33: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/33.jpg)
Playbooks • example.yml playbook
33
$ 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
![Page 34: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/34.jpg)
Playbooks • example.yml 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
Setup
(Recap)
![Page 35: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/35.jpg)
Module
35
![Page 36: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/36.jpg)
http://docs.ansible.com/ansible/list_of_commands_modules.html
![Page 37: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/37.jpg)
![Page 38: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/38.jpg)
Docs » commands Modules
yes
![Page 39: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/39.jpg)
Practice
39
![Page 40: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/40.jpg)
https://goo.gl/EYJ40O Control Machine*1 Managed node*2
Ansible Jupyter Managed node
40
![Page 41: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/41.jpg)
![Page 42: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/42.jpg)
Q & A
42
![Page 43: Automate with Ansible basic (2/e)](https://reader031.fdocuments.us/reader031/viewer/2022021814/58e4a1211a28abf5428b623b/html5/thumbnails/43.jpg)
E N D