├── official_docs.md ├── basic_concept.md ├── Ansible_Conditionals.md ├── LICENSE.md ├── install_ansible.md ├── ansible_windows.md └── README.md /official_docs.md: -------------------------------------------------------------------------------- 1 | #官方文件 2 | 3 | ##所有套件列表 All Modules 4 | http://docs.ansible.com/ansible/list_of_packaging_modules.html 5 | 6 | - [Ansible Documentation][0] 7 | - [Ansible - Module Index][1] 8 | - [Ansible - Playbooks][2] 9 | - [Ansible - Best Practices][3] 10 | 11 | [0]: http://docs.ansible.com/index.html 12 | [1]: http://docs.ansible.com/modules_by_category.html 13 | [2]: http://docs.ansible.com/playbooks.html 14 | [3]: http://docs.ansible.com/playbooks_best_practices.html 15 | 16 | ## Ansible playbook 範例 github 17 | https://github.com/ansible/ansible-examples 18 | -------------------------------------------------------------------------------- /basic_concept.md: -------------------------------------------------------------------------------- 1 | #基本概念 2 | 3 | //待補 4 | 5 | 6 | 7 | ## **1. Ansible 環境** 8 | 9 | * controller 端 python > 2.7 10 | * _managed 端(自己稱為受控端) _python > 2.5 11 | * _ansible_ (pip/yum/apt) 最新2.0 12 | 13 | 安裝ansible步驟 [點我](https://github.com/marxwang/ansible-learn-resources/blob/master/install_ansible.md) 14 | 15 | ## 2.學習 Ansible 專注focus 幾件事 16 | 17 | * Inventory (hosts) file 18 | * playbook(s) 19 | * role(s) 20 | * variables 21 | 22 | ## 3. 基本名詞 23 | from [Ansible状态管理](http://xdays.me/ansible%E7%8A%B6%E6%80%81%E7%AE%A1%E7%90%86.html) 24 | 25 | ### hosts/inventory 26 | 重點:管理對象、用什麼帳號管理,連線方式ssh/winrm 27 | - host,应用play的主机范围 28 | - user,在这些主机上以什么用户运行playbook 29 | 30 | ### task/play/playbooks/roles 31 | 重點:執行單一任務task、一組任務play、一系列任務roles 32 | - task,由模块来完成的一个单位任务,如修改文件或者启动服务 33 | - play,一组task的集合,ansible会自上而下执行 34 | - handler,task可以触发一定的事件,而处理该事件的task即为handler 35 | - role,角色,一组playbook以及和其配合的元素(vars, files等)的集合 36 | 37 | 38 | ## roles 目錄結構 39 | //待補 40 | 41 | 42 | -------------------------------------------------------------------------------- /Ansible_Conditionals.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Conditionals 條件式 4 | 5 | 目的:利用條件式協助task 過濾,滿足條件時才執行 6 | 7 | 使用時機[語法] 8 | - when [when:] 9 | - loops [with_items:] 10 | - loops [with_dicts:] 11 | - Custom Facts [ when: my_custom_facts == '1234'] 12 | - Conditional imports 13 | - Select files and Templates based on variables 14 | 15 | 16 | ## 2. 常見ansible_os_family 17 | 18 | - when: ansible_os_family == "CentOS" 19 | - when: ansible_os_family == "Redhat" 20 | - when: ansible_os_family == "Darwin" 21 | - when: ansible_os_family == "Debian" 22 | - when: ansible_os_family == "Windows" 23 | 24 | ## 3. 條件可以多選,並且可以用 And/OR 組合 25 | 26 | `when: (條件一) and/or (條件二)...and/or (更多條件)` 27 | 28 | 不過要寫到那麼精準,會不會讓playbook 變得很難維護,就要看人嚕 29 | 30 | 31 | ## 4. 本文英文版 32 | 順手寫了 Stack Overflow Docs beta 的文件,很開心被接受了,整理的過程中也發現自己的不足,讓全世界的人都來補完,是個好點子! 33 | 34 | Ansible: Conditionals - ansible - Stack Overflow 35 | http://stackoverflow.com/documentation/ansible/3555/ansible-conditionals#t=201607251002236395826 36 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010-2016 Google, Inc. http://angularjs.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /install_ansible.md: -------------------------------------------------------------------------------- 1 | 2 | #安裝 ansible 3 | 4 | ##requirements 5 | control 端 (python > 2.6,2.7) 6 | managed 端 (python > 2.5) 7 | 8 | ## install via 9 | 10 | ###pip 11 | 12 | `pip install ansible` 13 | 14 | 沒有pip 裝 15 | ``` 16 | wget https://bootstrap.pypa.io/ez_setup.py -O - | python 17 | easy_install pip 18 | ``` 19 | 20 | 或者沒有python > 2.7 先裝pyenvs (越搞越大?) 21 | ``` 22 | git clone https://github.com/yyuu/pyenv.git ~/.pyenv 23 | git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv 24 | 25 | #add .bashrc 26 | echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc 27 | echo 'eval "$(pyenv init -)"' >> ~/.bashrc 28 | echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc 29 | 30 | source ~/.bashrc 31 | 32 | #pyenv require library 33 | 34 | sudo apt-get install -y python-dev libffi-dev libssl-dev libxml2-dev libxslt1-dev 35 | sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ 36 | libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev python3-dev 37 | ``` 38 | 39 | 40 | ###yum redhat/centos 41 | 42 | `sudo yum install ansible` 43 | 44 | ###apt 45 | //官方建議作法 46 | ``` 47 | $ sudo apt-get install software-properties-common 48 | $ sudo apt-add-repository ppa:ansible/ansible 49 | $ sudo apt-get update 50 | $ sudo apt-get install ansible 51 | ``` 52 | 53 | ### osx 54 | 55 | 1.pip way (同上) 56 | 2.brew way `brew install ansible` 57 | 58 | ### git 59 | ``` 60 | $ git clone git://github.com/ansible/ansible.git 61 | $ cd ansible 62 | $ sudo make install 63 | ``` 64 | 65 | ##ref 66 | 67 | [官方 intro_installation 說明] (http://docs.ansible.com/ansible/intro_installation.html) 68 | -------------------------------------------------------------------------------- /ansible_windows.md: -------------------------------------------------------------------------------- 1 | #3.5 Ansible on windows 應用 2 | 3 | 【前言】 4 | 1. 官方聲明不會支援控制端設在windows (cygwin 環境勉強算有) 5 | 2. 控制端(control node)只有linux/bsd based,且必須 6 | - 安裝pywinrm 套件 7 | - 安裝kerberos套件 8 | 9 | 3.管控端(managed node)如是windows 必須有以下條件 10 | - 支援powershell >3 11 | - 設定環境給winrm 控制(ConfigureForWinrm.ps1) 12 | - winrm 服務安裝 13 | - winrm 服務執行 14 | - 開啟防火牆5986(https), 5985(http) 給winrm連線(非ssh協議連線) 15 | 16 | #控制端 (control node)設定 17 | ##安裝pywinrm 18 | `pip install http://github.com/diyan/pywinrm/archive/master.zip#egg=pywinrm` 19 | 20 | ##安裝 kerberos 21 | 1. 執行`pip install kerberos` 22 | 23 | 24 | 25 | 2. 如果出現「`krb5-config: not found`」錯誤訊息 26 | 27 | 請先裝 28 | - krb5-config 29 | - libkrb5-dev 30 | - libssl-dev 31 | - libsasl2-dev 32 | - libsasl2-modules-gssapi-mit 33 | 34 | `sudo apt-get install -y krb5-config libkrb5-dev libssl-dev libsasl2-dev libsasl2-modules-gssapi-mit` 35 | 36 | credit: [kerberos installation error](http://stackoverflow.com/questions/30088355/kerberos-installation-error-error-setup-script-exited-with-error-command-i68) 37 | 38 | 39 | #管控端(managed node) 設定 //自己的翻譯用詞 40 | 41 | ## 管理win 版本與環境設定 42 | 43 | from [開始用 Ansible 管理 Windows](https://metavige.github.io/2016/01/19/ansible-windows-manage-start/) 44 | from [Ansible For Windows (詳盡)](http://yumaojun03.gotoip55.com/?p=1232) 45 | 46 | 1. Windows 7/2008R2 版 47 | - 安裝 .net4.0 [下载地址](http://download.microsoft.com/download/B/A/4/BA4A7E71-2906-4B2D-A0E1-80CF16844F5F/dotNetFx45_Full_x86_x64.exe) 安装过后重启 windows ,进行下一步 更新到 power shell 3.0 48 | - patch bug http://support.microsoft.com/kb/2842230 49 | 50 | 2. Windows 8.1/2012 51 | 已經安裝了 .Net 4.0,所以不需要特別作什麼事情 52 | 53 | 54 | ## windows powershell setup script 55 | 56 | ansible/examples/scripts at devel 57 | https://github.com/ansible/ansible/tree/devel/examples/scripts 58 | 59 | 執行前 請先讓powershell 的執行策略改為`RemotedSigned` 60 | 61 | 檢查 PS> `Get-ExecutionPolicy`=>"RemoteSigned" 62 | 設定為 PS> `Set-ExecutionPolicy RemoteSigned` 63 | 64 | 1. 升級powershell3 65 | [upgradeps3.ps1](https://github.com/ansible/ansible/blob/devel/examples/scripts/upgrade_to_ps3.ps1) 66 | 67 | 2. 設定winrm 環境 68 | [configwinrm.ps1](https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1) 69 | 70 | 3. 檢查winrm 服務狀態 71 | 開啟powershell (系統管理員權限) :`winrm quickconfig` 72 | 73 | 應該會出現 74 | ``` 75 | WinRM 服務已在這台電腦上執行。 76 | 此電腦上的 WinRM 已設定為可接受遠端管理。 77 | ``` 78 | 79 | 4. 設定 AllowUnencrytped = false(一定要加密連線) 80 | 81 | PS >`winrm set winrm/config/service '@{AllowUnencrypted="false"}'` 82 | 83 | 5. 檢查連線驗證方式 84 | PS >`winrm get winrm/config/service/Auth` 85 | 86 | 結果 87 | ``` 88 | Auth 89 | Basic = true 90 | Kerberos = true 91 | Negotiate = true 92 | Certificate = false 93 | CredSSP = false 94 | CbtHardeningLevel = Relaxed 95 | ``` 96 | 97 | 98 | #【應用】 99 | ## 1. 控制端 (via vagrant) 100 | 控制端:linux on virtualbox(win) 101 | 管控端:any ansible hosts 102 | 103 | 番外篇:在 Windows 上也能使用 Ansible 104 | http://school.soft-arch.net/courses/ansible/lectures/659421 105 | 106 | 概念 用vagrant 新增控制端 Ansible 主機 107 | - vagrant box: https://github.com/William-Yeh/ansible-vagrantbox 108 | - 工具: vag2inv (Vagrant to Inventory) 幫你爬出vb 虛擬主機的 hosts 資訊 109 | https://github.com/William-Yeh/vag2inv 110 | 111 | ## 2.Control 端 on windows (via cygwin) 112 | 113 | Running Vagrant with Ansible Provisioning on Windows | Azavea Labs 114 | http://www.azavea.com/blogs/labs/2014/10/running-vagrant-with-ansible-provisioning-on-windows/ 115 | 116 | ##ref 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ansible-learn-resources 2 | ansible 學習教學資源整理 3 | 4 | ##【說明】 5 | 以初學者角度蒐集相關資源,國內外重要講師的學習資源。 6 | 簡單、好入手原則去蒐集,沒時間的可以先看小信豬系列(個人覺得精簡易懂)、william yeh大的文章、影片(國內重要推手) 7 | 全面性的可以看 Geekwolf 的電子檔(方方面面都照顧到),實做系列 Adam Brett文章 循序漸進引導入門。 8 | 9 | 希望對學習Ansible的朋友們有幫助,也歡迎不吝告知其他優質的學習資源! 10 | 11 | 包含 : 12 | - 教學課程 (本文) 13 | - 入門文章 (本文) 14 | - 基本概念 [basic](https://github.com/marxwang/ansible-learn-resources/blob/master/basic_concept.md) 15 | - 官方文件 [offical docs](https://github.com/marxwang/ansible-learn-resources/blob/master/official_docs.md) 16 | - windows 控制端 與管理端 [ansible on windows]( 17 | https://github.com/marxwang/ansible-learn-resources/blob/master/ansible_windows.md) 18 | 19 | 20 | # 教學課程 21 | 22 | ##william yeh 23 | 24 | * I. Ansible 實戰講堂,2016/01 開課了!(付費課程) 25 | [http://get.soft-arch.net/ansible/](http://get.soft-arch.net/ansible/) 26 | * II. Ansible 自動化組態管理實戰講堂 :: DevOps 2015 Workshop (付費課程) 27 | http://devopsconf.ithome.com.tw/workshop/ansible/ 28 | * (影片) 七分鐘掌握 Ansible 核心觀念 | Software Architecture School 29 | http://school.soft-arch.net/courses/ansible/lectures/655359 30 | 31 | ##Justin Weissig 32 | 33 | * 19 Minutes With Ansible (Part 1/4) 34 | https://sysadmincasts.com/episodes/43-19-minutes-with-ansible-part-1-4 35 | * Learning Ansible with Vagrant (Part 2/4) 36 | https://sysadmincasts.com/episodes/45-learning-ansible-with-vagrant-part-2-4 37 | * Configuration Management with Ansible (Part 3/4) 38 | https://sysadmincasts.com/episodes/46-configuration-management-with-ansible-part-3-4 39 | * Zero-downtime Deployments with Ansible (Part 4/4) 40 | https://sysadmincasts.com/episodes/47-zero-downtime-deployments-with-ansible-part-4-4 41 | 42 | ## 李松涛-Ansible系列课程-基础入门-InventoryFile 43 | http://www.jianshu.com/p/82208d730417 44 | 45 | ## 【實做】Vagrant & Ansible Quickstart Tutorial by Adam Brett 46 | https://adamcod.es/2014/09/23/vagrant-ansible-quickstart-tutorial.html(推!) 47 | 48 | #入門文章 49 | 50 | ##【概念文】 51 | 52 | - 20151226 淺談Ansible - Google Slides 53 | https://docs.google.com/presentation/d/136VKHI_H8wKyrLIm1eaTMLz82uoPgjV4zTiGb1_-_Ig/edit#slide=id.g7483853ab_0_17 54 | 55 | - Ansible 實戰:top down 觀點 56 | http://www.slideshare.net/williamyeh/ansible-top-down 57 | 58 | - IT Automation with Ansible 59 | http://www.slideshare.net/rayedalrashed/ansible-pdf 60 | 61 | ##【小信豬系列】 62 | 63 | * [Ansible] 初探 Ansible – 小信豬的原始部落 64 | https://godleon.github.io/blog/2015/02/22/ansible-introduction 65 | * [Ansible] playbook 入門 – 小信豬的原始部落 66 | http://godleon.github.io/blog/2015/03/26/ansible-playbooks-tutorial-1 67 | * [Ansible] playbook 使用介紹(vars & handler & template) – 小信豬的原始部落 68 | http://godleon.github.io/blog/2015/03/26/ansible-playbooks-tutorial-2 69 | * [Ansible] Include 使用介紹 – 小信豬的原始部落 70 | http://godleon.github.io/blog/2015/05/24/ansible-how-to-use-include 71 | * [Ansible] Role 使用介紹 – 小信豬的原始部落 72 | http://godleon.github.io/blog/2015/04/12/ansible-roles-introduction 73 | * [Ansible] 使用 module & ad-hoc command – 小信豬的原始部落 74 | http://godleon.github.io/blog/2015/02/22/ansible-module-ad-hoc-command 75 | 76 | 77 | ##【Ansible 大全整理】 中階難度 推! 78 | Ansible介绍 79 | http://www.simlinux.com/books/Ansible-notes.pdf 80 | 81 | # 大頭參考書 (推!) 82 | 83 | 1. ansible-playbook-essentials by Gourav Shah 84 | https://www.packtpub.com/networking-and-servers/ansible-playbook-essentials/?utm_source=scribd&utm_medium=cd&utm_campaign=samplechapter 85 | 86 | 2. Ansible Up and Running by Lorin Hochstein 87 | Ansible: Up and Running - O'Reilly Media 88 | http://shop.oreilly.com/product/0636920035626.do 89 | 90 | 91 | # 電子書 文章 92 | 93 | 1. 【電子書】Variables — ansible中文权威指南 1.0.1 documentation 94 | http://ansible-tran.readthedocs.org/en/latest/docs/playbooks_variables.html 95 | 96 | 2. 【文】Ansible状态管理 97 | http://xdays.me/ansible%E7%8A%B6%E6%80%81%E7%AE%A1%E7%90%86.html 98 | 99 | 100 | 101 | 102 | 103 | --------------------------------------------------------------------------------