SlideShare uma empresa Scribd logo
1 de 88
Baixar para ler offline
[ chusiang@study-area ~ ] $ cat .profile
# Author: 凍仁翔 / chusiang.lai (at) gmail.com
# Blog: http://note.drx.tw
# Modified: 2016-07-16 01:23
Ⅱ
我是誰?
• 凍仁翔 (@chusiang_lai)。
• 4 年年以上 IT 經驗。
• Ansible 實戰講堂 4e. 學員。
• 於 Galaxy 分享的 Roles:
• php7 (php-fpm)
• vim-and-vi-mode
• win_vim
• zabbix-agent
2
坐穩囉
要開始了了!
3
Outline
I. Roles 是什什麼?
4
Outline
I. Roles 是什什麼?
II. 怎麼使⽤用 Roles?
5
Outline
I. Roles 是什什麼?
II. 怎麼使⽤用 Roles?
III. Windows Support 是什什麼?
6
Outline
I. Roles 是什什麼?
II. 怎麼使⽤用 Roles?
III. Windows Support 是什什麼?
IV. 怎麼部署 Ansible 管 Windows 環境?
7
Outline
I. Roles 是什什麼?
II. 怎麼使⽤用 Roles?
III. Windows Support 是什什麼?
IV. 怎麼部署 Ansible 管 Windows 環境?
V. 怎麼⽤用 Ansible 管 Windows?
8
Outline
I. Roles 是什什麼?
II. 怎麼使⽤用 Roles?
III. Windows Support 是什什麼?
IV. 怎麼部署 Ansible 管 Windows 環境?
V. 怎麼⽤用 Ansible 管 Windows?
VI. Q & A
9
Ⅰ. Roles 是什什麼?
10
Scaling Up
Your Playbooks
-《Ansible: Up and Running》
Safari Books Online - https://goo.gl/dxoGSb
– chusiang
「 Roles 可以降低 Playbooks 的複雜性
,更更可以增加 Playbooks 的可⽤用性。」
Roles 是什什麼?
• 字⾯面上的意思是⾓角⾊色,其全名
為 Playbook Roles。
• 將 Playbook 分割成多個⽂文件
的 (抽象化) 封裝設計。
• 好比 Python 的 Packages。使
⽤用 Roles 我們可省去重造輪輪⼦子
的時間,然後提早下班!
Ansible Docs - http://goo.gl/mV6ToX
13
Playbooks 是什什麼?
• ⼀一鍵部署的強⼤大武器,比 Shell
Script 更更具結構化的腳本語
⾔言。
• 使⽤用 YAML 格式,寫 code 就
如同寫⽂文件,簡單易易讀。
• 可使⽤用 Jinja2 (template 系統)
表達式,並⽀支援變數、判斷式

、迴圈 ... 等語法。
Baby Playbook Onesie - http://goo.gl/GKJvXn
14
15
Playbook Roles Playbooksv.s.
[ jonny@sa ~/playbook-role ]$ tree -L 3
.
!"" LICENSE
!"" README.md
!"" ......
!"" ansible.cfg
!"" group_vars
#   %"" windows.yml
!"" requirements.yml
!"" roles
#   %"" chusiang.win_vim
#   !"" LICENSE
#   !"" README.md
#   !"" ......
#   !"" tasks
#   %"" templates
!"" setup.yml
!"" staging
%"" templates
%"" check_vim_version.bat.j2
[ jonny@sa ~/playbook ]$ tree -L 3
.
!"" LICENSE
!"" README.md
!"" ......
!"" ansible.cfg
!"" defaults
#   %"" main.yml
!"" group_vars
#   %"" windows.yml
!"" setup.yml
!"" staging
!"" tasks
#   !"" main.yml
#   %"" use-msi.yml
%"" templates
%"" check_vim_version.bat.j2
Ⅱ. 怎麼使⽤用 Roles?
搜尋、安裝、初始化
16
ansible-galaxyand
17
Galaxy
Galaxy
18
https://galaxy.ansible.com
23
$ ansible-galaxy ▌
怎麼搜尋 Roles?
24
# ansible-galaxy [delete|import|info|init|install|list|login|remove|search|setup]
[--help] [options] ...
$ ansible-galaxy search win_vim
Found 11 roles matching your search:
Name Description
---- -----------
chusiang.win_vim Install Vim and on Windows.
mingraham.win_import_pfx_cert Imports pfx certs to windows machine with pr
alban.andrieu.windows A role for installing windows
ypid.wine Setup and manage Wine for running MS Windows
trondhindenes.win_reboot A role to manage reboots on Windows nodes. T
kafecho.windows-couchdb Ansible role to deploy Apache CouchDB 1.6.1
cchurch.win-ec2 Create and destroy Windows instances on EC2.
shrikeh.pagerduty-maintenance-windows Ansible role to create PagerDuty scheduled m
peterszatmary.xfce Installs the XFCE window manager and lightdm
JamesSmaldon.xfce Installs the XFCE window manager and lightdm
deekayen.tls Host more secure communications for services
(END)
怎麼安裝 Roles?
25
$ ansible-galaxy install chusiang.win_vim
- downloading role 'win_vim', owned by chusiang
- downloading role from https://github.com/chusiang/win_vim.ansible.role/
archive/1.0.5.tar.gz
- extracting chusiang.win_vim to /usr/local/etc/ansible/roles/chusiang.win_vim
- chusiang.win_vim was installed successfully
$ ansible-galaxy install -f -p roles chusiang.win_vim
- downloading role 'win_vim', owned by chusiang
- downloading role from https://github.com/chusiang/win_vim.ansible.role/
archive/1.0.5.tar.gz
- extracting chusiang.win_vim to roles/chusiang.win_vim
- chusiang.win_vim was installed successfully
怎麼邊安裝 Roles 邊⾃自訂 Roles 位置?
怎麼初始化 Roles?
26
$ ansible-galaxy init new_role
- new_role was created successfully
$ tree new_role/
new_role/
!"" README.md
!"" defaults
#   %"" main.yml
!"" files
!"" handlers
#   %"" main.yml
!"" meta
#   %"" main.yml
!"" tasks
#   %"" main.yml
!"" templates
!"" tests
#   !"" inventory
#   %"" test.yml
%"" vars
%"" main.ymlhttps://galaxy.ansible.com/intro
Ⅲ. Windows Support 是什什麼?
27
Ansible Docs - http://goo.gl/jm8lpl
28
在官⽅方⽂文件中,

有個章節專⾨門在說 ...
Ansible Docs - http://goo.gl/jm8lpl
29
在官⽅方⽂文件中,

有個章節專⾨門在說 ...
怎麼⽤用 Ansible 管 Windows!
Ansible 從 1.7 開始⽀支援
Windows Managed node。
Ansible Docs - http://goo.gl/jm8lpl
30
Ansible 2.0 對 Windows
Managed node 的⽀支援度

⼤大幅提升。
jhawkesworth - http://goo.gl/5C4mrc
31
Ansible 怎麼管 Windows?
透過 inventory 定義 Managed node,並藉由 WinRM (或 SSH) 與 PowerShell 進⾏行行溝通。
32
Ansible 怎麼管 Unix-like?
透過 inventory 定義 Managed node,並藉由 SSH 與 Python 進⾏行行溝通。
33
Unix-like node
SSH
Python
Windows node
WinRM, SSH
PowerShell
Unix-like node
SSH
Python
Windows node
WinRM, SSH
PowerShell
Unix-like node
SSH
Python
Windows node
WinRM, SSH
PowerShell
Unix-like node
SSH
Python
Windows node
WinRM, SSH
PowerShell
Ⅳ. 怎麼部署 Ansible 管 Windows 環境?
安裝、設定
怎麼部署 Control Machine?
• 安裝 ansible 和 pywinrm。
39
# Reference:

# 

# http://docs.ansible.com/ansible/intro_windows.html#installing-on-the-
control-machine



# Debian & Ubuntu (propose).
$ sudo apt-get install ansible
# Mac OS X (propose).
$ sudo brew install ansible
# Python.
$ sudo pip install ansible
# pywinrm (need).
$ sudo pip install "pywinrm>=0.1.1"
怎麼部署 Managed node?
啟⽤用 WinRM 服務、安裝 PowerShell 3.0+、關閉 UAC
1. 前往 Windows Support ⽂文件⾴頁⾯面。
2. 點擊 Windows System Prep 連結。
3. 點擊 this PowerShell script 連結。
4. 點擊 Raw 連結。
5. 另存 ConfigureRemotingForAnsible.ps1 成新檔。
6. 使⽤用管理理者權限開啟 PowerShell。
7. 使⽤用管理理者權限執⾏行行 ConfigureRemotingForAnsible.ps1。
R
8. 若若 Script 有 UAC 權限問題,請先解鎖 (Unblock) 再執⾏行行。
9. 若若網路路有問題,請改⽤用私⼈人網路路 (Private network)。
$ winrm quickconfig -q
$ winrm set winrm/config/winrs @{MaxMemoryPerShellMB="512"}
$ winrm set winrm/config @{MaxTimeoutms="1800000"}
$ winrm set winrm/config/service @{AllowUnencrypted="true"}
$ winrm set winrm/config/service/auth @{Basic="true"}
$ sc config WinRM start= auto
10. 還有問題?請⽤用管理理者權限開啟命列列提⽰示字元,並執⾏行行以上 6 ⾏行行。
C: ▌
怎麼部署 Managed node?
啟⽤用 WinRM 服務、安裝 PowerShell 3.0+、關閉 UAC
Windows 8, 10、Server 2012 已內建 PowerShell 3.0+。
Windows 7、Server 2008 R2 需⼿手動安裝 PowerShell 3.0。
怎麼部署 Managed node?
啟⽤用 WinRM 服務、安裝 PowerShell 3.0+、關閉 UAC
(選項) 若若未停⽤用 UAC,可能會造成部份 tasks 被中斷。
怎麼設定 Ansible?
• 藉由 ansible.cfg 來來設定 inventory (host file) 檔案路路徑、
Managed node (被控端) 使⽤用者名稱、SSH ⾦金金鑰 … 等。
56
$ vim ansible.cfg
[defaults]
# 指定 inventory 檔案路路徑。
hostfile = staging
# 遠端使⽤用者名稱
remote_user = vagrant
# host_key_checking: 不詢問加入 ssh ⾦金金鑰
#host_key_checking = False
inventory 是什什麼?
• 主要⽤用來來定義 Managed node (被控端) 主機位址與群組,
也可⽤用來來設定 WinRM 連線資訊。
57
$ vim staging
# ansible_host: 遠端主機位址。
# ansible_port: 遠端埠⼝口 (Port)。
# ansible_user: 遠端使⽤用者名稱。
# ansible_pass: 遠端密碼 (建議改⽤用私鑰)。
[local]
win10.local ansible_host=127.0.0.1 ansible_user=IEUser
ansible_password=Passw0rd! ansible_port=55986
inventory 是什什麼?
• 在控管 Windows Managed node 前,我們還需設定這些
inventory 變數。
58
$ vim group_vars/windows.yml
---
# windows support
#################
ansible_connection: winrm
ansible_port: 5986
# The following is necessary for Python 2.7.9+ when using 
# default WinRM self-signed certificates:
ansible_winrm_server_cert_validation: ignore
Ⅴ. 怎麼⽤用 Ansible 管 Windows?
Ad-Hoc command, Playbooks x Roles
Ad-Hoc command
60
Playbooks x Roles
怎麼⽤用 Ad-Hoc command 管 Windows?
• -m 後的各項參參數請參參考官⽅方⽂文件 - Windows Modules

,⽀支援 Windows 的 Module ⼤大多為 win 開頭。
61
# ansible <主機名稱> -m <模組> -a <參參數1> -a <參參數2>
$ ansible all -m win_ping
win10.local | SUCCESS => {
"changed": false,
"ping": "pong"
}
$ ansible all -m raw -a "echo Hello World"
win10.local | SUCCESS | rc=0 >>
Hello World
怎麼⽤用 Playbooks 和 Roles 管 Windows?
62
$ vim setup.yml
---
- hosts: all
roles:
- chusiang.win_vim
tasks:
- name: copy check vim version file
win_template:
src: 'templates/check_vim_version.bat.j2'
dest: '{{ tmp_path }}check_vim_version.bat'
when: ansible_os_family == "Windows"
- name: check vim version
raw: '{{ tmp_path }}check_vim_version.bat'
register: vim_version
when: ansible_os_family == "Windows"
- name: print vim version
debug:
msg: "{{ vim_version }}"
when: ansible_os_family == "Windows"
怎麼⽤用 Playbooks 和 Roles 管 Windows?
63
$ vim setup.yml
---
- hosts: all
roles:
- chusiang.win_vim
tasks:
- name: copy check vim version file
win_template:
src: 'templates/check_vim_version.bat.j2'
dest: '{{ tmp_path }}check_vim_version.bat'
when: ansible_os_family == "Windows"
- name: check vim version
raw: '{{ tmp_path }}check_vim_version.bat'
register: vim_version
when: ansible_os_family == "Windows"
- name: print vim version
debug:
msg: "{{ vim_version }}"
when: ansible_os_family == "Windows"
Play
怎麼⽤用 Playbooks 和 Roles 管 Windows?
64
$ vim setup.yml
---
- hosts: all
roles:
- chusiang.win_vim
tasks:
- name: copy check vim version file
win_template:
src: 'templates/check_vim_version.bat.j2'
dest: '{{ tmp_path }}check_vim_version.bat'
when: ansible_os_family == "Windows"
- name: check vim version
raw: '{{ tmp_path }}check_vim_version.bat'
register: vim_version
when: ansible_os_family == "Windows"
- name: print vim version
debug:
msg: "{{ vim_version }}"
when: ansible_os_family == "Windows"
role1: chusiang.win_vim
task1: copy script
to remote.
task2: run script.
task3: print stdout.
怎麼⽤用 Playbooks 和 Roles 管 Windows?
65
$ vim setup.yml
---
- hosts: all
roles:
- chusiang.win_vim
tasks:
- name: copy check vim version file
win_template:
src: 'templates/check_vim_version.bat.j2'
dest: '{{ tmp_path }}check_vim_version.bat'
when: ansible_os_family == "Windows"
- name: check vim version
raw: '{{ tmp_path }}check_vim_version.bat'
register: vim_version
when: ansible_os_family == "Windows"
- name: print vim version
debug:
msg: "{{ vim_version }}"
when: ansible_os_family == "Windows"
Module
怎麼⽤用 Playbooks 和 Roles 管 Windows?
66
$ ansible-playbook setup.yml
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [win10.local]
TASK [chusiang.win_vim : Create temp directory] ********************************
ok: [win10.local]
TASK [chusiang.win_vim : delegate to 'msi' system for installation] ************
included: /Users/jonny/vcs/9.demo/studyarea1607-ansible-demo/roles/
chusiang.win_vim/tasks/use-msi.yml for win10.local
TASK [chusiang.win_vim : get vim.msi on windows] *******************************
changed: [win10.local]
TASK [chusiang.win_vim : install vim with msi] *********************************
changed: [win10.local]
怎麼⽤用 Playbooks 和 Roles 管 Windows?
67
TASK [copy check vim version file] *********************************************
changed: [win10.local]
TASK [check vim version] *******************************************************
ok: [win10.local]
TASK [print vim version] *******************************************************
ok: [win10.local] => {
"msg": {
"changed": false,
"rc": 0,
"stderr": "",
"stdout": "rnC:UsersIEUser>"C:Program Files (x86)vimvim74
vim.exe" --version rnVIM - Vi IMproved 7.4 (2013 Aug 1
......
]
}
}
PLAY RECAP *********************************************************************
win10.local : ok=8 changed=3 unreachable=0 failed=0
怎麼⽤用 Playbooks 和 Roles 管 Windows?
68
TASK [copy check vim version file] *********************************************
changed: [win10.local]
TASK [check vim version] *******************************************************
ok: [win10.local]
TASK [print vim version] *******************************************************
ok: [win10.local] => {
"msg": {
"changed": false,
"rc": 0,
"stderr": "",
"stdout": "rnC:UsersIEUser>"C:Program Files (x86)vimvim74
vim.exe" --version rnVIM - Vi IMproved 7.4 (2013 Aug 1
......
]
}
}
PLAY RECAP *********************************************************************
win10.local : ok=8 changed=3 unreachable=0 failed=0總結
火 ⼒力力 展 ⽰示
Live Demo
69
https://youtu.be/wZLT1B_uh9Q
https://github.com/chusiang/studyarea1607-ansible-demo
怎麼避開 Windows Playbooks 路路徑地雷?
1. 使⽤用 key:value 寫法會比 key=value 少踩點雷,後者不時會遇
到路路徑 (PATH) 無法辨識問題。
2. 避免在每⾏行行的結尾使⽤用 。
3. 若若遇到  可使⽤用  來來替代,因為 Windows 原先就會這樣解析
路路徑。
4. 特殊符號解析有誤?請先寫好批次檔,傳檔後 (win_copy,
win_template) 再執⾏行行 (raw)。例例:`C:Program Files (x86)`。
5. 在 Playbooks 裡,/ 做為路路徑的分隔符號是有效的。
73
常⽤用的 Windows Module 有哪些?
常⽤用的 Windows Module 有哪些?
1. raw: Executes a low-down and dirty SSH command.
2. win_copy: Copies files to remote locations on windows
hosts.
3. win_file: Creates, touches or removes files or directories.
4. win_get_url: Fetches a file from a given URL.
5. win_lineinfile: Ensure a particular line is in a file, or
replace an existing line using a back-referenced regular
expression.
常⽤用的 Windows Module 有哪些?
6. win_msi: Installs and uninstalls Windows MSI files.
7. win_ping: A windows version of the classic ping
module.
8. win_reboot: Reboot a windows machine.
9. win_stat: returns information about a Windows file.
10.win_template: Templates a file out to a remote server.
Q & A
嚴禁拍打餵食
76
參參考⽂文獻
A. 《Ansible: Up and Running》- https://www.ansible.com/ansible-book
B. Windows Support | Ansible Docs - http://docs.ansible.com/ansible/intro_windows.html
C. Ansible 2.0 and Windows | AnsibleFest London 2016 - https://goo.gl/OmScaQ
D. Ansible 實戰講堂 - http://get.soft-arch.net/ansible/
E. 淺談 Ansible by sakana / Max - https://goo.gl/gR0dox
F. 現代 IT ⼈人⼀一定要知道的 Ansible ⾃自動化組態技巧 | 凍仁的筆記 - http://goo.gl/JXqlez
G. 開始⽤用 Ansible 管理理 Windows | @metavige - https://goo.gl/F79v1N
H. Create A Vagrant Windows Base Box | Smalltown Tech Blog - https://goo.gl/rcy3tT
I. Issues · ansible/ansible | GitHub - https://github.com/ansible/ansible/issues
77
Free
圖片來來源
a. Blasts Off Space Rocket From Cosmodrom In The Clouds, Polygonal Stock
Illustration | dreamstime - http://goo.gl/6FAuiQ
b. 國家地理理雜誌 - http://www.ngtaiwan.com
c. Avatar, business, company, group, manager, people, users icon | Icon search engine

- https://goo.gl/Hm6ScX
d. A Galaxy Just Appeared Out of Nowhere - http://goo.gl/ND2Jwb
e. PowerShell Gallery | azure-sdk - https://goo.gl/bES4Ba
f. Brown Book Icon - someBooks Icons - SoftIcons.com - http://goo.gl/IDb4jp
g. Deployment of Symfony2 applications with Ansible - ServerGroveServerGrove

- http://blog.servergrove.com/2014/04/01/deployment-symfony2-applications-ansible/
78
⼯工商服務
79
80
.tw
http://mopcon.org
https://gitter.im/DevOpsTW/
https://devopstaiwan.slack.com/
DevOps Taiwan
https://www.facebook.com/groups/DevOpsTaiwan/
http://www.vim.tw
COSCUP 2016 商品預購
⼩小啄貼紙簿
蒐集貼 (ㄒㄩㄣ) 紙 (ㄓㄤ) 的神兵!
⼩小啄 VR 眼鏡
體驗 VR 虛擬實境的利利器!
請密切注意 COSCUP 2016!
http://coscup.org/2016/
88
END

Mais conteúdo relacionado

Mais procurados

Linux Networking Explained
Linux Networking ExplainedLinux Networking Explained
Linux Networking ExplainedThomas Graf
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
 
Cgroups, namespaces and beyond: what are containers made from?
Cgroups, namespaces and beyond: what are containers made from?Cgroups, namespaces and beyond: what are containers made from?
Cgroups, namespaces and beyond: what are containers made from?Docker, Inc.
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Jérôme Petazzoni
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with AnsibleRayed Alrashed
 
[FR] Présentatation d'Ansible
[FR] Présentatation d'Ansible [FR] Présentatation d'Ansible
[FR] Présentatation d'Ansible Armand Guio
 
How Netflix Tunes EC2 Instances for Performance
How Netflix Tunes EC2 Instances for PerformanceHow Netflix Tunes EC2 Instances for Performance
How Netflix Tunes EC2 Instances for PerformanceBrendan Gregg
 
File System Hierarchy
File System HierarchyFile System Hierarchy
File System Hierarchysritolia
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansibleGeorge Shuklin
 
Course 102: Lecture 26: FileSystems in Linux (Part 1)
Course 102: Lecture 26: FileSystems in Linux (Part 1) Course 102: Lecture 26: FileSystems in Linux (Part 1)
Course 102: Lecture 26: FileSystems in Linux (Part 1) Ahmed El-Arabawy
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageKernel TLV
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationSuresh Kumar
 
Writing Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxWriting Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxRajKumar Rampelli
 
Boosting I/O Performance with KVM io_uring
Boosting I/O Performance with KVM io_uringBoosting I/O Performance with KVM io_uring
Boosting I/O Performance with KVM io_uringShapeBlue
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory ManagementNi Zo-Ma
 
Introduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and DracutIntroduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and DracutTaisuke Yamada
 
Virtualization Architecture & KVM
Virtualization Architecture & KVMVirtualization Architecture & KVM
Virtualization Architecture & KVMPradeep Kumar
 
Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Neeraj Shrimali
 
An Introduction to CMake
An Introduction to CMakeAn Introduction to CMake
An Introduction to CMakeICS
 

Mais procurados (20)

Linux Networking Explained
Linux Networking ExplainedLinux Networking Explained
Linux Networking Explained
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Cgroups, namespaces and beyond: what are containers made from?
Cgroups, namespaces and beyond: what are containers made from?Cgroups, namespaces and beyond: what are containers made from?
Cgroups, namespaces and beyond: what are containers made from?
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
 
Linux: LVM
Linux: LVMLinux: LVM
Linux: LVM
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
[FR] Présentatation d'Ansible
[FR] Présentatation d'Ansible [FR] Présentatation d'Ansible
[FR] Présentatation d'Ansible
 
How Netflix Tunes EC2 Instances for Performance
How Netflix Tunes EC2 Instances for PerformanceHow Netflix Tunes EC2 Instances for Performance
How Netflix Tunes EC2 Instances for Performance
 
File System Hierarchy
File System HierarchyFile System Hierarchy
File System Hierarchy
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
Course 102: Lecture 26: FileSystems in Linux (Part 1)
Course 102: Lecture 26: FileSystems in Linux (Part 1) Course 102: Lecture 26: FileSystems in Linux (Part 1)
Course 102: Lecture 26: FileSystems in Linux (Part 1)
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Writing Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxWriting Character driver (loadable module) in linux
Writing Character driver (loadable module) in linux
 
Boosting I/O Performance with KVM io_uring
Boosting I/O Performance with KVM io_uringBoosting I/O Performance with KVM io_uring
Boosting I/O Performance with KVM io_uring
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Introduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and DracutIntroduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and Dracut
 
Virtualization Architecture & KVM
Virtualization Architecture & KVMVirtualization Architecture & KVM
Virtualization Architecture & KVM
 
Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup.
 
An Introduction to CMake
An Introduction to CMakeAn Introduction to CMake
An Introduction to CMake
 

Semelhante a 現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows

Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)Chu-Siang Lai
 
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...Laird Cheng
 
Docker tutorial
Docker tutorialDocker tutorial
Docker tutorialazole Lai
 
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來Shengyou Fan
 
Cfengine培训文档 刘天斯
Cfengine培训文档 刘天斯Cfengine培训文档 刘天斯
Cfengine培训文档 刘天斯liuts
 
Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)Chu-Siang Lai
 
unix toolbox 中文版
unix toolbox 中文版unix toolbox 中文版
unix toolbox 中文版Jie Bao
 
Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Yiwei Ma
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuMarsZ Chen
 
Continuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CIContinuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CIChu-Siang Lai
 
2, installation
2, installation2, installation
2, installationted-xu
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结Yiwei Ma
 
X64服务器 lamp服务器部署标准 new
X64服务器 lamp服务器部署标准 newX64服务器 lamp服务器部署标准 new
X64服务器 lamp服务器部署标准 newYiwei Ma
 
利用Cent Os快速构建自己的发行版
利用Cent Os快速构建自己的发行版利用Cent Os快速构建自己的发行版
利用Cent Os快速构建自己的发行版xingsu1021
 
Continuous Delivery Workshop with Ansible x GitLab CI (2nd)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd)Continuous Delivery Workshop with Ansible x GitLab CI (2nd)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd)Chu-Siang Lai
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介GO LL
 
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)JoXuZi
 
康盛创想项目部Linux 服务器部署标准(最新版)
康盛创想项目部Linux 服务器部署标准(最新版)康盛创想项目部Linux 服务器部署标准(最新版)
康盛创想项目部Linux 服务器部署标准(最新版)Yiwei Ma
 
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩Wen-Tien Chang
 
Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版redhat9
 

Semelhante a 現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows (20)

Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)
 
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
 
Docker tutorial
Docker tutorialDocker tutorial
Docker tutorial
 
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來
 
Cfengine培训文档 刘天斯
Cfengine培训文档 刘天斯Cfengine培训文档 刘天斯
Cfengine培训文档 刘天斯
 
Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)
 
unix toolbox 中文版
unix toolbox 中文版unix toolbox 中文版
unix toolbox 中文版
 
Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for Ubuntu
 
Continuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CIContinuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CI
 
2, installation
2, installation2, installation
2, installation
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结
 
X64服务器 lamp服务器部署标准 new
X64服务器 lamp服务器部署标准 newX64服务器 lamp服务器部署标准 new
X64服务器 lamp服务器部署标准 new
 
利用Cent Os快速构建自己的发行版
利用Cent Os快速构建自己的发行版利用Cent Os快速构建自己的发行版
利用Cent Os快速构建自己的发行版
 
Continuous Delivery Workshop with Ansible x GitLab CI (2nd)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd)Continuous Delivery Workshop with Ansible x GitLab CI (2nd)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd)
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
 
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
 
康盛创想项目部Linux 服务器部署标准(最新版)
康盛创想项目部Linux 服务器部署标准(最新版)康盛创想项目部Linux 服务器部署标准(最新版)
康盛创想项目部Linux 服务器部署标准(最新版)
 
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
 
Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版
 

Mais de Chu-Siang Lai

The System Engineer in Agile Team
The System Engineer in Agile TeamThe System Engineer in Agile Team
The System Engineer in Agile TeamChu-Siang Lai
 
Is it really easy for companies to import Ansible automation
Is it really easy for companies to import Ansible automationIs it really easy for companies to import Ansible automation
Is it really easy for companies to import Ansible automationChu-Siang Lai
 
See the Agile from Mindset
See the Agile from MindsetSee the Agile from Mindset
See the Agile from MindsetChu-Siang Lai
 
Writing skills for Information Technology
Writing skills for Information TechnologyWriting skills for Information Technology
Writing skills for Information TechnologyChu-Siang Lai
 
Continuous Delivery Workshop with Ansible x GitLab CI (5th)
 Continuous Delivery Workshop with Ansible x GitLab CI (5th) Continuous Delivery Workshop with Ansible x GitLab CI (5th)
Continuous Delivery Workshop with Ansible x GitLab CI (5th)Chu-Siang Lai
 
Continuous Delivery Workshop with Ansible x GitLab CI (3rd)
Continuous Delivery Workshop with Ansible x GitLab CI (3rd)Continuous Delivery Workshop with Ansible x GitLab CI (3rd)
Continuous Delivery Workshop with Ansible x GitLab CI (3rd)Chu-Siang Lai
 
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)Chu-Siang Lai
 
Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Chu-Siang Lai
 
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIContinuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIChu-Siang Lai
 
Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)Chu-Siang Lai
 
前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧Chu-Siang Lai
 
Git and Github basic with SourceTree
Git and Github basic with SourceTreeGit and Github basic with SourceTree
Git and Github basic with SourceTreeChu-Siang Lai
 
使用 Multi-sites 技術快速建置多 Drupal 網站
使用 Multi-sites 技術快速建置多 Drupal 網站使用 Multi-sites 技術快速建置多 Drupal 網站
使用 Multi-sites 技術快速建置多 Drupal 網站Chu-Siang Lai
 
歡迎來到 Ubuntu 9.10 Release Party (台中)
歡迎來到 Ubuntu 9.10 Release Party (台中)歡迎來到 Ubuntu 9.10 Release Party (台中)
歡迎來到 Ubuntu 9.10 Release Party (台中)Chu-Siang Lai
 
無痛入門 Chromecast
無痛入門 Chromecast無痛入門 Chromecast
無痛入門 ChromecastChu-Siang Lai
 

Mais de Chu-Siang Lai (20)

My DevOps Tour 2.3
My DevOps Tour 2.3My DevOps Tour 2.3
My DevOps Tour 2.3
 
The System Engineer in Agile Team
The System Engineer in Agile TeamThe System Engineer in Agile Team
The System Engineer in Agile Team
 
Is it really easy for companies to import Ansible automation
Is it really easy for companies to import Ansible automationIs it really easy for companies to import Ansible automation
Is it really easy for companies to import Ansible automation
 
My DevOps Tour 0.1
My DevOps Tour 0.1My DevOps Tour 0.1
My DevOps Tour 0.1
 
See the Agile from Mindset
See the Agile from MindsetSee the Agile from Mindset
See the Agile from Mindset
 
Writing skills for Information Technology
Writing skills for Information TechnologyWriting skills for Information Technology
Writing skills for Information Technology
 
Continuous Delivery Workshop with Ansible x GitLab CI (5th)
 Continuous Delivery Workshop with Ansible x GitLab CI (5th) Continuous Delivery Workshop with Ansible x GitLab CI (5th)
Continuous Delivery Workshop with Ansible x GitLab CI (5th)
 
My DevOps Tour 1.0
My DevOps Tour 1.0My DevOps Tour 1.0
My DevOps Tour 1.0
 
Continuous Delivery Workshop with Ansible x GitLab CI (3rd)
Continuous Delivery Workshop with Ansible x GitLab CI (3rd)Continuous Delivery Workshop with Ansible x GitLab CI (3rd)
Continuous Delivery Workshop with Ansible x GitLab CI (3rd)
 
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
 
Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)
 
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIContinuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CI
 
Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)
 
前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧
 
Git and Github basic with SourceTree
Git and Github basic with SourceTreeGit and Github basic with SourceTree
Git and Github basic with SourceTree
 
helloTux 2012
helloTux 2012helloTux 2012
helloTux 2012
 
Unity & Googlizer
Unity & GooglizerUnity & Googlizer
Unity & Googlizer
 
使用 Multi-sites 技術快速建置多 Drupal 網站
使用 Multi-sites 技術快速建置多 Drupal 網站使用 Multi-sites 技術快速建置多 Drupal 網站
使用 Multi-sites 技術快速建置多 Drupal 網站
 
歡迎來到 Ubuntu 9.10 Release Party (台中)
歡迎來到 Ubuntu 9.10 Release Party (台中)歡迎來到 Ubuntu 9.10 Release Party (台中)
歡迎來到 Ubuntu 9.10 Release Party (台中)
 
無痛入門 Chromecast
無痛入門 Chromecast無痛入門 Chromecast
無痛入門 Chromecast
 

現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows

  • 1. [ chusiang@study-area ~ ] $ cat .profile # Author: 凍仁翔 / chusiang.lai (at) gmail.com # Blog: http://note.drx.tw # Modified: 2016-07-16 01:23 Ⅱ
  • 2. 我是誰? • 凍仁翔 (@chusiang_lai)。 • 4 年年以上 IT 經驗。 • Ansible 實戰講堂 4e. 學員。 • 於 Galaxy 分享的 Roles: • php7 (php-fpm) • vim-and-vi-mode • win_vim • zabbix-agent 2
  • 5. Outline I. Roles 是什什麼? II. 怎麼使⽤用 Roles? 5
  • 6. Outline I. Roles 是什什麼? II. 怎麼使⽤用 Roles? III. Windows Support 是什什麼? 6
  • 7. Outline I. Roles 是什什麼? II. 怎麼使⽤用 Roles? III. Windows Support 是什什麼? IV. 怎麼部署 Ansible 管 Windows 環境? 7
  • 8. Outline I. Roles 是什什麼? II. 怎麼使⽤用 Roles? III. Windows Support 是什什麼? IV. 怎麼部署 Ansible 管 Windows 環境? V. 怎麼⽤用 Ansible 管 Windows? 8
  • 9. Outline I. Roles 是什什麼? II. 怎麼使⽤用 Roles? III. Windows Support 是什什麼? IV. 怎麼部署 Ansible 管 Windows 環境? V. 怎麼⽤用 Ansible 管 Windows? VI. Q & A 9
  • 11. Scaling Up Your Playbooks -《Ansible: Up and Running》 Safari Books Online - https://goo.gl/dxoGSb
  • 12. – chusiang 「 Roles 可以降低 Playbooks 的複雜性 ,更更可以增加 Playbooks 的可⽤用性。」
  • 13. Roles 是什什麼? • 字⾯面上的意思是⾓角⾊色,其全名 為 Playbook Roles。 • 將 Playbook 分割成多個⽂文件 的 (抽象化) 封裝設計。 • 好比 Python 的 Packages。使 ⽤用 Roles 我們可省去重造輪輪⼦子 的時間,然後提早下班! Ansible Docs - http://goo.gl/mV6ToX 13
  • 14. Playbooks 是什什麼? • ⼀一鍵部署的強⼤大武器,比 Shell Script 更更具結構化的腳本語 ⾔言。 • 使⽤用 YAML 格式,寫 code 就 如同寫⽂文件,簡單易易讀。 • 可使⽤用 Jinja2 (template 系統) 表達式,並⽀支援變數、判斷式
 、迴圈 ... 等語法。 Baby Playbook Onesie - http://goo.gl/GKJvXn 14
  • 15. 15 Playbook Roles Playbooksv.s. [ jonny@sa ~/playbook-role ]$ tree -L 3 . !"" LICENSE !"" README.md !"" ...... !"" ansible.cfg !"" group_vars #   %"" windows.yml !"" requirements.yml !"" roles #   %"" chusiang.win_vim #   !"" LICENSE #   !"" README.md #   !"" ...... #   !"" tasks #   %"" templates !"" setup.yml !"" staging %"" templates %"" check_vim_version.bat.j2 [ jonny@sa ~/playbook ]$ tree -L 3 . !"" LICENSE !"" README.md !"" ...... !"" ansible.cfg !"" defaults #   %"" main.yml !"" group_vars #   %"" windows.yml !"" setup.yml !"" staging !"" tasks #   !"" main.yml #   %"" use-msi.yml %"" templates %"" check_vim_version.bat.j2
  • 20.
  • 21.
  • 22.
  • 24. 怎麼搜尋 Roles? 24 # ansible-galaxy [delete|import|info|init|install|list|login|remove|search|setup] [--help] [options] ... $ ansible-galaxy search win_vim Found 11 roles matching your search: Name Description ---- ----------- chusiang.win_vim Install Vim and on Windows. mingraham.win_import_pfx_cert Imports pfx certs to windows machine with pr alban.andrieu.windows A role for installing windows ypid.wine Setup and manage Wine for running MS Windows trondhindenes.win_reboot A role to manage reboots on Windows nodes. T kafecho.windows-couchdb Ansible role to deploy Apache CouchDB 1.6.1 cchurch.win-ec2 Create and destroy Windows instances on EC2. shrikeh.pagerduty-maintenance-windows Ansible role to create PagerDuty scheduled m peterszatmary.xfce Installs the XFCE window manager and lightdm JamesSmaldon.xfce Installs the XFCE window manager and lightdm deekayen.tls Host more secure communications for services (END)
  • 25. 怎麼安裝 Roles? 25 $ ansible-galaxy install chusiang.win_vim - downloading role 'win_vim', owned by chusiang - downloading role from https://github.com/chusiang/win_vim.ansible.role/ archive/1.0.5.tar.gz - extracting chusiang.win_vim to /usr/local/etc/ansible/roles/chusiang.win_vim - chusiang.win_vim was installed successfully $ ansible-galaxy install -f -p roles chusiang.win_vim - downloading role 'win_vim', owned by chusiang - downloading role from https://github.com/chusiang/win_vim.ansible.role/ archive/1.0.5.tar.gz - extracting chusiang.win_vim to roles/chusiang.win_vim - chusiang.win_vim was installed successfully 怎麼邊安裝 Roles 邊⾃自訂 Roles 位置?
  • 26. 怎麼初始化 Roles? 26 $ ansible-galaxy init new_role - new_role was created successfully $ tree new_role/ new_role/ !"" README.md !"" defaults #   %"" main.yml !"" files !"" handlers #   %"" main.yml !"" meta #   %"" main.yml !"" tasks #   %"" main.yml !"" templates !"" tests #   !"" inventory #   %"" test.yml %"" vars %"" main.ymlhttps://galaxy.ansible.com/intro
  • 27. Ⅲ. Windows Support 是什什麼? 27
  • 28. Ansible Docs - http://goo.gl/jm8lpl 28 在官⽅方⽂文件中, 有個章節專⾨門在說 ...
  • 29. Ansible Docs - http://goo.gl/jm8lpl 29 在官⽅方⽂文件中, 有個章節專⾨門在說 ... 怎麼⽤用 Ansible 管 Windows!
  • 30. Ansible 從 1.7 開始⽀支援 Windows Managed node。 Ansible Docs - http://goo.gl/jm8lpl 30
  • 31. Ansible 2.0 對 Windows Managed node 的⽀支援度 ⼤大幅提升。 jhawkesworth - http://goo.gl/5C4mrc 31
  • 32. Ansible 怎麼管 Windows? 透過 inventory 定義 Managed node,並藉由 WinRM (或 SSH) 與 PowerShell 進⾏行行溝通。 32
  • 33. Ansible 怎麼管 Unix-like? 透過 inventory 定義 Managed node,並藉由 SSH 與 Python 進⾏行行溝通。 33
  • 38. Ⅳ. 怎麼部署 Ansible 管 Windows 環境? 安裝、設定
  • 39. 怎麼部署 Control Machine? • 安裝 ansible 和 pywinrm。 39 # Reference:
 # 
 # http://docs.ansible.com/ansible/intro_windows.html#installing-on-the- control-machine
 
 # Debian & Ubuntu (propose). $ sudo apt-get install ansible # Mac OS X (propose). $ sudo brew install ansible # Python. $ sudo pip install ansible # pywinrm (need). $ sudo pip install "pywinrm>=0.1.1"
  • 40. 怎麼部署 Managed node? 啟⽤用 WinRM 服務、安裝 PowerShell 3.0+、關閉 UAC
  • 41. 1. 前往 Windows Support ⽂文件⾴頁⾯面。
  • 42. 2. 點擊 Windows System Prep 連結。
  • 43. 3. 點擊 this PowerShell script 連結。
  • 44. 4. 點擊 Raw 連結。
  • 48. 8. 若若 Script 有 UAC 權限問題,請先解鎖 (Unblock) 再執⾏行行。
  • 50. $ winrm quickconfig -q $ winrm set winrm/config/winrs @{MaxMemoryPerShellMB="512"} $ winrm set winrm/config @{MaxTimeoutms="1800000"} $ winrm set winrm/config/service @{AllowUnencrypted="true"} $ winrm set winrm/config/service/auth @{Basic="true"} $ sc config WinRM start= auto 10. 還有問題?請⽤用管理理者權限開啟命列列提⽰示字元,並執⾏行行以上 6 ⾏行行。 C: ▌
  • 51. 怎麼部署 Managed node? 啟⽤用 WinRM 服務、安裝 PowerShell 3.0+、關閉 UAC
  • 52. Windows 8, 10、Server 2012 已內建 PowerShell 3.0+。
  • 53. Windows 7、Server 2008 R2 需⼿手動安裝 PowerShell 3.0。
  • 54. 怎麼部署 Managed node? 啟⽤用 WinRM 服務、安裝 PowerShell 3.0+、關閉 UAC
  • 56. 怎麼設定 Ansible? • 藉由 ansible.cfg 來來設定 inventory (host file) 檔案路路徑、 Managed node (被控端) 使⽤用者名稱、SSH ⾦金金鑰 … 等。 56 $ vim ansible.cfg [defaults] # 指定 inventory 檔案路路徑。 hostfile = staging # 遠端使⽤用者名稱 remote_user = vagrant # host_key_checking: 不詢問加入 ssh ⾦金金鑰 #host_key_checking = False
  • 57. inventory 是什什麼? • 主要⽤用來來定義 Managed node (被控端) 主機位址與群組, 也可⽤用來來設定 WinRM 連線資訊。 57 $ vim staging # ansible_host: 遠端主機位址。 # ansible_port: 遠端埠⼝口 (Port)。 # ansible_user: 遠端使⽤用者名稱。 # ansible_pass: 遠端密碼 (建議改⽤用私鑰)。 [local] win10.local ansible_host=127.0.0.1 ansible_user=IEUser ansible_password=Passw0rd! ansible_port=55986
  • 58. inventory 是什什麼? • 在控管 Windows Managed node 前,我們還需設定這些 inventory 變數。 58 $ vim group_vars/windows.yml --- # windows support ################# ansible_connection: winrm ansible_port: 5986 # The following is necessary for Python 2.7.9+ when using # default WinRM self-signed certificates: ansible_winrm_server_cert_validation: ignore
  • 59. Ⅴ. 怎麼⽤用 Ansible 管 Windows? Ad-Hoc command, Playbooks x Roles
  • 61. 怎麼⽤用 Ad-Hoc command 管 Windows? • -m 後的各項參參數請參參考官⽅方⽂文件 - Windows Modules
 ,⽀支援 Windows 的 Module ⼤大多為 win 開頭。 61 # ansible <主機名稱> -m <模組> -a <參參數1> -a <參參數2> $ ansible all -m win_ping win10.local | SUCCESS => { "changed": false, "ping": "pong" } $ ansible all -m raw -a "echo Hello World" win10.local | SUCCESS | rc=0 >> Hello World
  • 62. 怎麼⽤用 Playbooks 和 Roles 管 Windows? 62 $ vim setup.yml --- - hosts: all roles: - chusiang.win_vim tasks: - name: copy check vim version file win_template: src: 'templates/check_vim_version.bat.j2' dest: '{{ tmp_path }}check_vim_version.bat' when: ansible_os_family == "Windows" - name: check vim version raw: '{{ tmp_path }}check_vim_version.bat' register: vim_version when: ansible_os_family == "Windows" - name: print vim version debug: msg: "{{ vim_version }}" when: ansible_os_family == "Windows"
  • 63. 怎麼⽤用 Playbooks 和 Roles 管 Windows? 63 $ vim setup.yml --- - hosts: all roles: - chusiang.win_vim tasks: - name: copy check vim version file win_template: src: 'templates/check_vim_version.bat.j2' dest: '{{ tmp_path }}check_vim_version.bat' when: ansible_os_family == "Windows" - name: check vim version raw: '{{ tmp_path }}check_vim_version.bat' register: vim_version when: ansible_os_family == "Windows" - name: print vim version debug: msg: "{{ vim_version }}" when: ansible_os_family == "Windows" Play
  • 64. 怎麼⽤用 Playbooks 和 Roles 管 Windows? 64 $ vim setup.yml --- - hosts: all roles: - chusiang.win_vim tasks: - name: copy check vim version file win_template: src: 'templates/check_vim_version.bat.j2' dest: '{{ tmp_path }}check_vim_version.bat' when: ansible_os_family == "Windows" - name: check vim version raw: '{{ tmp_path }}check_vim_version.bat' register: vim_version when: ansible_os_family == "Windows" - name: print vim version debug: msg: "{{ vim_version }}" when: ansible_os_family == "Windows" role1: chusiang.win_vim task1: copy script to remote. task2: run script. task3: print stdout.
  • 65. 怎麼⽤用 Playbooks 和 Roles 管 Windows? 65 $ vim setup.yml --- - hosts: all roles: - chusiang.win_vim tasks: - name: copy check vim version file win_template: src: 'templates/check_vim_version.bat.j2' dest: '{{ tmp_path }}check_vim_version.bat' when: ansible_os_family == "Windows" - name: check vim version raw: '{{ tmp_path }}check_vim_version.bat' register: vim_version when: ansible_os_family == "Windows" - name: print vim version debug: msg: "{{ vim_version }}" when: ansible_os_family == "Windows" Module
  • 66. 怎麼⽤用 Playbooks 和 Roles 管 Windows? 66 $ ansible-playbook setup.yml PLAY [all] ********************************************************************* TASK [setup] ******************************************************************* ok: [win10.local] TASK [chusiang.win_vim : Create temp directory] ******************************** ok: [win10.local] TASK [chusiang.win_vim : delegate to 'msi' system for installation] ************ included: /Users/jonny/vcs/9.demo/studyarea1607-ansible-demo/roles/ chusiang.win_vim/tasks/use-msi.yml for win10.local TASK [chusiang.win_vim : get vim.msi on windows] ******************************* changed: [win10.local] TASK [chusiang.win_vim : install vim with msi] ********************************* changed: [win10.local]
  • 67. 怎麼⽤用 Playbooks 和 Roles 管 Windows? 67 TASK [copy check vim version file] ********************************************* changed: [win10.local] TASK [check vim version] ******************************************************* ok: [win10.local] TASK [print vim version] ******************************************************* ok: [win10.local] => { "msg": { "changed": false, "rc": 0, "stderr": "", "stdout": "rnC:UsersIEUser>"C:Program Files (x86)vimvim74 vim.exe" --version rnVIM - Vi IMproved 7.4 (2013 Aug 1 ...... ] } } PLAY RECAP ********************************************************************* win10.local : ok=8 changed=3 unreachable=0 failed=0
  • 68. 怎麼⽤用 Playbooks 和 Roles 管 Windows? 68 TASK [copy check vim version file] ********************************************* changed: [win10.local] TASK [check vim version] ******************************************************* ok: [win10.local] TASK [print vim version] ******************************************************* ok: [win10.local] => { "msg": { "changed": false, "rc": 0, "stderr": "", "stdout": "rnC:UsersIEUser>"C:Program Files (x86)vimvim74 vim.exe" --version rnVIM - Vi IMproved 7.4 (2013 Aug 1 ...... ] } } PLAY RECAP ********************************************************************* win10.local : ok=8 changed=3 unreachable=0 failed=0總結
  • 69. 火 ⼒力力 展 ⽰示 Live Demo 69
  • 72. 怎麼避開 Windows Playbooks 路路徑地雷? 1. 使⽤用 key:value 寫法會比 key=value 少踩點雷,後者不時會遇 到路路徑 (PATH) 無法辨識問題。 2. 避免在每⾏行行的結尾使⽤用 。 3. 若若遇到 可使⽤用 來來替代,因為 Windows 原先就會這樣解析 路路徑。 4. 特殊符號解析有誤?請先寫好批次檔,傳檔後 (win_copy, win_template) 再執⾏行行 (raw)。例例:`C:Program Files (x86)`。 5. 在 Playbooks 裡,/ 做為路路徑的分隔符號是有效的。
  • 74. 常⽤用的 Windows Module 有哪些? 1. raw: Executes a low-down and dirty SSH command. 2. win_copy: Copies files to remote locations on windows hosts. 3. win_file: Creates, touches or removes files or directories. 4. win_get_url: Fetches a file from a given URL. 5. win_lineinfile: Ensure a particular line is in a file, or replace an existing line using a back-referenced regular expression.
  • 75. 常⽤用的 Windows Module 有哪些? 6. win_msi: Installs and uninstalls Windows MSI files. 7. win_ping: A windows version of the classic ping module. 8. win_reboot: Reboot a windows machine. 9. win_stat: returns information about a Windows file. 10.win_template: Templates a file out to a remote server.
  • 77. 參參考⽂文獻 A. 《Ansible: Up and Running》- https://www.ansible.com/ansible-book B. Windows Support | Ansible Docs - http://docs.ansible.com/ansible/intro_windows.html C. Ansible 2.0 and Windows | AnsibleFest London 2016 - https://goo.gl/OmScaQ D. Ansible 實戰講堂 - http://get.soft-arch.net/ansible/ E. 淺談 Ansible by sakana / Max - https://goo.gl/gR0dox F. 現代 IT ⼈人⼀一定要知道的 Ansible ⾃自動化組態技巧 | 凍仁的筆記 - http://goo.gl/JXqlez G. 開始⽤用 Ansible 管理理 Windows | @metavige - https://goo.gl/F79v1N H. Create A Vagrant Windows Base Box | Smalltown Tech Blog - https://goo.gl/rcy3tT I. Issues · ansible/ansible | GitHub - https://github.com/ansible/ansible/issues 77 Free
  • 78. 圖片來來源 a. Blasts Off Space Rocket From Cosmodrom In The Clouds, Polygonal Stock Illustration | dreamstime - http://goo.gl/6FAuiQ b. 國家地理理雜誌 - http://www.ngtaiwan.com c. Avatar, business, company, group, manager, people, users icon | Icon search engine
 - https://goo.gl/Hm6ScX d. A Galaxy Just Appeared Out of Nowhere - http://goo.gl/ND2Jwb e. PowerShell Gallery | azure-sdk - https://goo.gl/bES4Ba f. Brown Book Icon - someBooks Icons - SoftIcons.com - http://goo.gl/IDb4jp g. Deployment of Symfony2 applications with Ansible - ServerGroveServerGrove
 - http://blog.servergrove.com/2014/04/01/deployment-symfony2-applications-ansible/ 78
  • 86. ⼩小啄 VR 眼鏡 體驗 VR 虛擬實境的利利器!