一、運維相關概念介紹
二、ansible介紹
三、ansible指令
四、ansible常用子產品
五、ansible配置檔案詳解
運維:Opreations
1.系統安裝:
bare metal:pxe(pre execute enviroment),cobbler
virtual machine:
pxe:依賴于網卡自身的功能(dhcp_client,FS_client),以及網絡中預先提供的服務
FS_client:加載bootloader檔案,檔案server驅動
但是為CentOS6安裝了PXE的話,隻能安裝6的OS
cobbler:可以提供選擇界面,供使用者選擇
将多種pxe環境封裝整合
2.Configuration:應用程式:安裝配置啟動等
puppet(ruby)//應用廣泛,性能廣泛
saltstack(python) //穩定性增強中,後來者
puppet,saltstack都是重量級
ansible//相對輕量級
chef(ruby)
cfenginen
...
3.Command and Control:批量的指令執行,例如建立目錄
fabric(python)
func(相對重量級)
4.程式釋出: //不能影響使用者體驗,
人工釋出
腳本
釋出程式(運維程式)
//釋出模型(灰階模型)
釋出路徑:
在排程器上下線一批主機(标記為維護模式)-->關閉服務-->部署新版本-->啟動服務-->在排程器上啟動這一批主機
二、ansible介紹
1.ansible能夠實作運維的所有工作
程式釋出需要根據需求,自行設定,系統安裝正在開發階段
ansible:輕量化,
Configuration
Command and Control
規模更大時,建議使用puppet
支援:windows,debian系列,redhat系列
2.運維工具分類:
agent:RS上有client專用的監聽服務,更安全,
agentless(ssh):ansible,fabric
//ansible可以借助sshd也可以不使用sshd
管理主機需要管理被管理主機:需要被管理主機的特權權限
可以借助于ssh服務//
ansible:被redhat收購,1.5億美元
3.特性:
子產品化,調用特定子產品,完成特定任務
基于python語言實作,由Paramiko,PyYAML和jinja2三個關鍵模闆
部署簡單:agentless;
支援自定義子產品
支援playbook;
幂等性:一個任務執行一遍和執行n遍的結果是一樣的
4.架構:
如圖一:
---------------------------------------------------------------------
核心:ansible
核心子產品(Core Modules):這些都是ansible自帶的子產品
擴充子產品(Custom Modules):如果核心子產品不足以完成某種功能,可以添加擴充子產品
插件(Plugins):完成子產品功能的補充
劇本(Playbooks):ansible的任務配置檔案,将多個任務定義在劇本中,由ansible自動執行。YAML格式
連接配接插件(Connectior Plugins):ansible基于連接配接插件連接配接到各個主機上,雖然ansible是使用ssh連接配接到各個主機的,但是它還支援其他的連接配接方法,是以需要有連接配接插件
Host Inventory:定義了被管理主機,Inventory:清單
Ansible要和管理節點之間ssh隧道打通
Ansible指令行管理主機(Ad-hoc command)
Ansible的“指令”(module)
5.Ansible Tower //商業化軟體
Ansile Tower則是針對企業級使用者的,中心化ansible管理節點。它向管理者提供Web頁面接口,來運作ansible腳本playbook。
管理者在ansible tower上使用和分享主機的ssh key,但是不能檢視和拷貝key檔案。
登入ansible tower的所有管理者可以共享playbook腳本,減少重複工作。
此外ansible還可以收集和展現所有主機的playbook的執行狀況,便于統計和分析主機的狀态。
注意:假如被管控主機有例如ubuntu(apt-get,yum,dnf等)等其他的os的話,可以支援變量
條件判斷,判斷目标主機類型等 //puppet可以自動識别不同的OS,進行安裝
yum install ansible //epel源
[root@localhost ~]# rpm -ql ansible |egrep -v -i "man|share|lib"
<code>/etc/ansible/ansible</code><code>.cfg 配置檔案:</code>
<code>/etc/ansible/hosts</code> <code>主機清單</code>
<code>/etc/ansible/roles</code>
<code> </code>
<code>/usr/bin/ansible</code>
<code>/usr/bin/ansible-console</code>
<code>/usr/bin/ansible-doc</code> <code>檢視文檔</code>
<code>/usr/bin/ansible-galaxy</code>
<code>/usr/bin/ansible-playbook</code>
<code>/usr/bin/ansible-pull</code>
<code>/usr/bin/ansible-vault</code>
1.ansible 指令
參數:
ansible host-pattern [-f forks] [-m module] [-a args]
ansible 192.168.0.102 -a 'date'
-a 'Arguments', --args='Arguments' 指令行參數
-m NAME, --module-name=NAME 執行子產品的名字,預設使用 command 子產品,是以如果是隻執行單一指令可以不用 -m參數
-i PATH, --inventory=PATH 指定庫存主機檔案的路徑,預設為/etc/ansible/hosts. //主機清單
-u Username, --user=Username 執行使用者,使用這個遠端使用者名而不是目前使用者
-U --sud-user=SUDO_User sudo到哪個使用者,預設為 root
-k --ask-pass 登入密碼,提示輸入SSH密碼而不是假設基于密鑰的驗證
-K --ask-sudo-pass 提示密碼使用sudo
-s --sudo sudo運作
-S --su 用 su 指令
-l --list 顯示所支援的所有子產品
-s --snippet 指定子產品顯示劇本片段
-f --forks=NUM 并行任務數。NUM被指定為一個整數,預設是5。 #ansible testhosts -a "/sbin/reboot" -f 10 重新開機testhosts組的所有機器,每次重新開機10台
--private-key=PRIVATE_KEY_FILE 私鑰路徑,使用這個檔案來驗證連接配接
-v --verbose 詳細資訊
all 針對hosts 定義的所有主機執行
-M MODULE_PATH, --module-path=MODULE_PATH 要執行的子產品的路徑,預設為/usr/share/ansible/
--list-hosts 隻列印有哪些主機會執行這個 playbook 檔案,不是實際執行該 playbook 檔案
-o --one-line 壓縮輸出,摘要輸出.嘗試一切都在一行上輸出。
-t Directory, --tree=Directory 将内容儲存在該輸出目錄,結果儲存在一個檔案中在每台主機上。
-B 背景運作逾時時間
-P 調查背景程式時間
-T Seconds, --timeout=Seconds 時間,機關秒s
-P NUM, --poll=NUM 調查背景工作每隔數秒。需要- b
-c Connection, --connection=Connection 連接配接類型使用。可能的選項是paramiko(SSH),SSH和地方。當地主要是用于crontab或啟動。
--tags=TAGS 隻執行指定标簽的任務 例子:ansible-playbook test.yml --tags=copy 隻執行标簽為copy的那個任務
--list-tasks 列出所有将被執行的任務
-C, --check 隻是測試一下會改變什麼内容,不會真正去執行;相反,試圖預測一些可能發生的變化
--syntax-check 執行文法檢查的劇本,但不執行它
-l SUBSET, --limit=SUBSET 進一步限制所選主機/組模式 --limit=192.168.0.15 隻對這個ip執行
--skip-tags=SKIP_TAGS 隻運作戲劇和任務不比對這些值的标簽 --skip-tags=copy_start
-e EXTRA_VARS, --extra-vars=EXTRA_VARS 額外的變量設定為鍵=值或YAML / JSON
#cat update.yml
---
- hosts: {{ hosts }}
remote_user: {{ user }}
..............
#ansible-playbook update.yml --extra-vars "hosts=vipers user=admin" 傳遞{{hosts}}、{{user}}變量,hosts可以是 ip或組名
-l,--limit 對指定的 主機/組 執行任務 --limit=192.168.0.10,192.168.0.11 或 -l 192.168.0.10,192.168.0.11 隻對這個2個ip執行任務
2.ansible-doc是Ansible子產品文檔說明,
ansible-doc -l //檢視所有的子產品
//檢視具體某子產品的用法,這裡如檢視command子產品
# ansible-doc -s command //檢視詳細用法
3.Ansible-galaxy的功能可以簡單了解為GitHub或PIP的功能
https://galaxy.ansible.com/ 類似于github的roles庫
從Ansible-galaxy上,我們可以根據下載下傳量和關注量等資訊,查找和安裝優秀的Roles。
ansible-galaxy [init|info|install|list|remove]
init:初始化本地的Roles配置,以備上傳Roles至galaxy。
info:清單指定Role的詳細資訊。
install:下載下傳并安裝galaxy指定的Roles到本地。
list:列出本地已下載下傳的Roles。
remove:删除本地已下載下傳的Roles。
ansible-doc -l //檢視ansible支援的所有子產品
ansible-galaxy list --help //檢視幫助資訊
ansible-galaxy install patrik.uytterhoeven.Zabbix_Server //可以下載下傳他人寫好的roles
4.ansible-lint
ansible-lint是對playbook的文法進行檢查的一個工具。用法是ansible-lint playbook.yml
5.ansible-playbook
該指令是使用最多的指令,其通過讀取playbook 檔案後,執行相應的動作,這個後面會做為一個重點來講。
6.ansible-pull
該指令使用需要談到Ansible的另一種工作模式:pull 模式(Ansible預設使用push模式)。
這和通常使用的push模式工作機理剛好相反,其适用于以下場景:
(1)你有數量巨大的機器需要配置,即使使用高并發線程依舊要花費很多時間;
(2)你要在剛啟動的沒有網絡連接配接的主機上運作Anisble。
通常Ansible-pull結合git和crontab一并實作,其原理如下:通過crontab定期拉取指定的Git 版本到本地,
并以指定模式自動運作預先制訂好的指令。
ansible-pull [options] [playbook.yml]
*/20 * * * * root /usr/local/bin/ansible-pull -o -C 2.1.0 -d /srv/www/king-gw/ -i /etc/ansible/hosts -U git://git.kingifa.com/king-gw-ansiblepull >> /var/log/ansible-pull.log 2>&1
7.Ansible-vault主要用于配置檔案加密,如編寫的Playbook配置檔案包含敏感資訊并且不希望其他人随意檢視,Ansible-vault可加密/解密這個配置檔案
ansible-vault encrypt a.yml
ansible-vault decrypt a.yml
8. Ansible-console是Ansible為使用者提供的一款互動式工具
9.ansible-config
list // list all current configs reading lib/constants.py and shows env and config file setting names
dump // Shows the current settings, merges ansible.cfg if specified
--only-changed // Only show configurations that have changed from the default
view // Displays the current config file
ssh-keygen
ssh-copy-id -i .ssh/id_rsa.pub [email protected]
ssh-copy-id -i .ssh/id_rsa.pub [email protected]
ansible all -m ping //使用ping子產品測試主機是否線上
all :可以使用組名,websrvs,或者單個主機
vim /etc/ansible/ansible.cfg
forks //多個目标主機的話,一次執行5個
子產品:
ansible-doc -l //列出所有子產品
command|shell|copy|cron|fetch|file|hostname|yum|service|uri|user
-s //snippet:片段,ansible對應的子產品的幫助片段資訊,簡要幫助
例如:ansible-doc -s yum
1.command //在遠端主機上執行一個指令
ansible-doc -s command //這是在YAML中可以使用的
chdir:cd 到一個檔案夾
creates:建立一個檔案
executable:
remove:
warn:
ansible websrvs -m command -a 'ls /var' //-a指定參數
ansible websrvs -a 'ls /var' //-a指定參數, ,可省略
ansible websrvs -a 'cd /root ' -a 'ls'
注:command子產品是不支援管道的,需要調用shell子產品
輸入輸出重定向等,也要使用shell子產品
ansible websrvs -a 'echo test | passwd --stdin wolf' //這個并不能修改密碼,因為command是預設子產品,但是不支援管道
ansible websrvs -m shell -a 'echo test | passwd --stdin wolf'
2.shell子產品,支援shell特性,例如管道等
3.copy 複制本地檔案到遠端位置
src :absolute or relative.絕對路徑或者相對路徑
dest= :目标路徑
mode
owner //目标檔案的屬主和屬組
content 填充内容,而不是檔案
ansible 192.168.4.110 -m copy -a "src=/etc/sysconfig/iptables-config dest=/root owner=root"
ansible 192.168.4.106 -m copy -a "content='test' dest=/root/aab mode=0600"
ansible 192.168.4.106 -m copy -a "src=/var/test dest=/var/ " //目錄複制
注:如果目标檔案存在則直接覆寫
4.cron //計劃任務
day,hour,month,weekday,minute
state={absent|present} //缺席,出席的//是要删除任務還是添加任務
reboot,
name= //cron的名稱
job=
ansible all -m cron -a "minute=*/10 job='/usr/sbin/ntpdate 202.120.2.101 &> /dev/null' name=Synctime"
ansible all -m cron -a "state=absent name=Synctime"
//删除任務,隻需要指定state和name即可
5.fetch //拉取檔案
dest=
src=
6.file //設定檔案屬性
path= //目标檔案
src //源,
state {directory,link,}
mode='u=rw,g=r,o=r' //或者mode=0644
owner
group
recurse //遞歸修改
ansible all -m file -a "src=/tmp/fstab path=/tmp/fstab.link state=link"
//為fstab建立連結檔案為fstab.link
ansible all -m file -a "path=/tmp/dd state=directory"
建立目錄
ansible all -m file -a "path=/tmp/dd owner=wolf recurse=yes"
修改屬性
7.hostname //管理主機名
8.yum
disablerepo
enablerepo
list
name= //包名,可以指明版本号,name-1.0即可以
state={present|latest|absent} //latest最新版本
update_cache
config_file //指定yum配置檔案
ansible all -m yum -a "name=httpd state=latest"
9.service //管理服務的
enabled=1/0 ,yes/no
named=
runlevel //預設2345
sleep
state={started,stopped,restarted}
ansible all -m service -a "name=httpd state=started"
//啟動服務
ansible all -m shell -a "ss -tnl |grep 80"
//檢視狀态資訊
10.uri
url=(http|https)://hosts.domain[:port]/path
passwd
user
tiemout
method //請求的方法
11.user //管理使用者賬号的
name=
password
append
remove //當state=absent的時候,同時删除使用者的家目錄
expires
system=yes 系統使用者
uid,shell,group,groups,
state={absent|present
comment,
home,move_home
ansible all -m user -a "name=user2 system=yes uid=306 state=present"
ansible.cfg //hosts會在後面解釋
ansible配置的優先級:
ANSIBLE_CONFIG(環境變量)-->current 目錄ansible.cfg --->家目錄 .ansible.cfg-->/etc/ansible/ansible.cfg
http://docs.ansible.com/ansible/intro_configuration.html#explanation-of-values-by-section
https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg
<code>[defaults] --->通用預設配置</code>
<code># some basic default values...</code>
<code>inventory = </code><code>/etc/ansible/hosts</code> <code>這個是預設庫檔案位置,腳本,或者存放可通信主機的目錄</code>
<code>#library = /usr/share/my_modules/ Ansible預設搜尋子產品的位置</code>
<code>remote_tmp = $HOME/.ansible</code><code>/tmp</code> <code>Ansible 通過遠端傳輸子產品到遠端主機,然後遠端執行,執行後在清理現場.在有些場景下,你也許想使用預設路徑希望像更換更新檔一樣使用</code>
<code>pattern = * 如果沒有提供“hosts”節點,這是playbook要通信的預設主機組.預設值是對所有主機通信</code>
<code>forks = 5 在與主機通信時的預設并行程序數 ,預設是5d</code>
<code>poll_interval = 15 當具體的poll interval 沒有定義時,多少時間回查一下這些任務的狀态, 預設值是5秒</code>
<code>sudo_user = root </code><code>sudo</code><code>使用的預設使用者 ,預設是root</code>
<code>#ask_sudo_pass = True 用來控制Ansible playbook 在執行sudo之前是否詢問sudo密碼.預設為no</code>
<code>#ask_pass = True 控制Ansible playbook 是否會自動預設彈出密碼</code>
<code>transport = smart 通信機制.預設 值為’smart’。如果本地系統支援 ControlPersist技術的話,将會使用(基于OpenSSH)‘</code><code>ssh</code><code>’,如果不支援講使用‘paramiko’.其他傳輸選項包括‘</code><code>local</code><code>’, ‘chroot’,’jail’等等</code>
<code>#remote_port = 22 遠端SSH端口。 預設是22</code>
<code>module_lang = C 子產品和系統之間通信的計算機語言,預設是C語言</code>
<code># plays will gather facts by default, which contain information about</code>
<code># the remote system.</code>
<code>#</code>
<code># smart - gather by default, but don't regather if already gathered</code>
<code># implicit - gather by default, turn off with gather_facts: False</code>
<code># explicit - do not gather by default, must say gather_facts: True</code>
<code>gathering = implicit 控制預設facts收集(遠端系統變量). 預設值為’implicit’, 每一次play,facts都會被收集</code>
<code># additional paths to search for roles in, colon separated</code>
<code>#roles_path = /etc/ansible/roles roles 路徑指的是’roles/’下的額外目錄,用于playbook搜尋Ansible roles</code>
<code># uncomment this to disable SSH key host checking</code>
<code>#host_key_checking = False //關閉第一次使用ansible連接配接用戶端是輸入指令提示</code>
<code># change this for alternative sudo implementations</code>
<code>sudo_exe = </code><code>sudo</code> <code>如果在其他遠端主機上使用另一種方式執sudu操作.可以使用該參數進行更換</code>
<code>#what flags to pass to sudo 傳遞sudo之外的參數</code>
<code>#sudo_flags = -H</code>
<code># SSH timeout SSH逾時時間</code>
<code>timeout = 10</code>
<code># default user to use for playbooks if user is not specified</code>
<code># (/usr/bin/ansible will use current user as default)</code>
<code># remote_user = root 使用/usr/bin/ansible-playbook連結的預設使用者名,如果不指定,會使用目前登入的使用者名</code>
<code># logging is off by default unless this path is defined</code>
<code># if so defined, consider logrotate</code>
<code>#log_path = /var/log/ansible.log 日志檔案存放路徑</code>
<code># default module name for /usr/bin/ansible</code>
<code>#module_name = command ansible指令執行預設的子產品</code>
<code># use this shell for commands executed under sudo</code>
<code># you may need to change this to bin/bash in rare instances</code>
<code># if sudo is constrained</code>
<code># executable = /bin/sh 在sudo環境下産生一個shell互動接口. 使用者隻在/bin/bash的或者sudo限制的一些場景中需要修改</code>
<code># if inventory variables overlap, does the higher precedence one win</code>
<code># or are hash values merged together? The default is 'replace' but</code>
<code># this can also be set to 'merge'.</code>
<code># hash_behaviour = replace 特定的優先級覆寫變量</code>
<code># list any Jinja2 extensions to enable here:</code>
<code>#jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n 允許開啟Jinja2拓展子產品</code>
<code># if set, always use this private key file for authentication, same as </code>
<code># if passing --private-key to ansible or ansible-playbook</code>
<code>#private_key_file = /path/to/file 私鑰檔案存儲位置</code>
<code># format of string {{ ansible_managed }} available within Jinja2 </code>
<code># templates indicates to users editing templates files will be replaced.</code>
<code># replacing {file}, {host} and {uid} and strftime codes with proper values.</code>
<code>ansible_managed = Ansible managed: {</code><code>file</code><code>} modified on %Y-%m-%d %H:%M:%S by {uid} on {host} 這個設定可以告知使用者,Ansible修改了一個檔案,并且手動寫入的内容可能已經被覆寫.</code>
<code># by default, ansible-playbook will display "Skipping [host]" if it determines a task</code>
<code># should not be run on a host. Set this to "False" if you don't want to see these "Skipping" </code>
<code># messages. NOTE: the task header will still be shown regardless of whether or not the </code>
<code># task is skipped.</code>
<code># display_skipped_hosts = True 顯示任何跳過任務的狀态 ,預設是顯示</code>
<code># by default (as of 1.3), Ansible will raise errors when attempting to dereference </code>
<code># Jinja2 variables that are not set in templates or action lines. Uncomment this line</code>
<code># to revert the behavior to pre-1.3.</code>
<code># error_on_undefined_vars = False 如果所引用的變量名稱錯誤的話, 将會導緻ansible在執行步驟上失敗</code>
<code># by default (as of 1.6), Ansible may display warnings based on the configuration of the</code>
<code># system running ansible itself. This may include warnings about 3rd party packages or</code>
<code># other conditions that should be resolved if possible.</code>
<code># to disable these warnings, set the following value to False:</code>
<code>#system_warnings = True 允許禁用系統運作ansible相關的潛在問題警告</code>
<code># by default (as of 1.4), Ansible may display deprecation warnings for language</code>
<code># features that should no longer be used and will be removed in future versions.</code>
<code>#deprecation_warnings = True 允許在ansible-playbook輸出結果中禁用“不建議使用”警告</code>
<code># (as of 1.8), Ansible can optionally warn when usage of the shell and</code>
<code># command module appear to be simplified by using a default Ansible module</code>
<code># instead. These warnings can be silenced by adjusting the following</code>
<code># setting or adding warn=yes or warn=no to the end of the command line </code>
<code># parameter string. This will for example suggest using the git module</code>
<code># instead of shelling out to the git command.</code>
<code># command_warnings = False 當shell和指令行子產品被預設子產品簡化的時,Ansible 将預設發出警告</code>
<code># set plugin path directories here, separate with colons</code>
<code>action_plugins = </code><code>/usr/share/ansible_plugins/action_plugins</code>
<code>callback_plugins = </code><code>/usr/share/ansible_plugins/callback_plugins</code>
<code>connection_plugins = </code><code>/usr/share/ansible_plugins/connection_plugins</code>
<code>lookup_plugins = </code><code>/usr/share/ansible_plugins/lookup_plugins</code>
<code>vars_plugins = </code><code>/usr/share/ansible_plugins/vars_plugins</code>
<code>filter_plugins = </code><code>/usr/share/ansible_plugins/filter_plugins</code>
<code># by default callbacks are not loaded for /bin/ansible, enable this if you</code>
<code># want, for example, a notification or logging callback to also apply to </code>
<code># /bin/ansible runs</code>
<code>#bin_ansible_callbacks = False 用來控制callback插件是否在運作 /usr/bin/ansible 的時候被加載. 這個子產品将用于指令行的日志系統,發出通知等特性</code>
<code># don't like cows? that's unfortunate.</code>
<code># set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1 </code>
<code>#nocows = 1 預設ansible可以調用一些cowsay的特性 開啟/禁用:0/1</code>
<code># don't like colors either?</code>
<code># set to 1 if you don't want colors, or export ANSIBLE_NOCOLOR=1</code>
<code>#nocolor = 1 輸出帶上顔色差別, 開啟/關閉:0/1</code>
<code># the CA certificate path used for validating SSL certs. This path </code>
<code># should exist on the controlling node, not the target nodes</code>
<code># common locations:</code>
<code># RHEL/CentOS: /etc/pki/tls/certs/ca-bundle.crt</code>
<code># Fedora : /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem</code>
<code># Ubuntu : /usr/share/ca-certificates/cacert.org/cacert.org.crt</code>
<code>#ca_file_path = </code>
<code># the http user-agent string to use when fetching urls. Some web server</code>
<code># operators block the default urllib user agent as it is frequently used</code>
<code># by malicious attacks/scripts, so we set it to something unique to </code>
<code># avoid issues.</code>
<code>#http_user_agent = ansible-agent</code>
<code># if set to a persistent type (not 'memory', for example 'redis') fact values</code>
<code># from previous runs in Ansible will be stored. This may be useful when</code>
<code># wanting to use, for example, IP information from one group of servers</code>
<code># without having to talk to them in the same playbook run to get their</code>
<code># current IP information.</code>
<code>fact_caching = memory</code>
<code># retry files</code>
<code>#retry_files_enabled = False</code>
<code>#retry_files_save_path = ~/.ansible-retry</code>
<code>[privilege_escalation]</code>
<code>#become=True</code>
<code>#become_method=sudo</code>
<code>#become_user=root</code>
<code>#become_ask_pass=False</code>
<code>[paramiko_connection]</code>
<code># uncomment this line to cause the paramiko connection plugin to not record new host</code>
<code># keys encountered. Increases performance on new host additions. Setting works independently of the</code>
<code># host key checking setting above.</code>
<code>#record_host_keys=False</code>
<code># by default, Ansible requests a pseudo-terminal for commands executed under sudo. Uncomment this</code>
<code># line to disable this behaviour.</code>
<code>#pty=False</code>
<code>[ssh_connection]</code>
<code># ssh arguments to use</code>
<code># Leaving off ControlPersist will result in poor performance, so use </code>
<code># paramiko on older platforms rather than removing it</code>
<code>#ssh_args = -o ControlMaster=auto -o ControlPersist=60s</code>
<code># The path to use for the ControlPath sockets. This defaults to</code>
<code># "%(directory)s/ansible-ssh-%%h-%%p-%%r", however on some systems with</code>
<code># very long hostnames or very long path names (caused by long user names or </code>
<code># deeply nested home directories) this can exceed the character limit on</code>
<code># file socket names (108 characters for most platforms). In that case, you </code>
<code># may wish to shorten the string below.</code>
<code># </code>
<code># Example: </code>
<code># control_path = %(directory)s/%%h-%%r</code>
<code>#control_path = %(directory)s/ansible-ssh-%%h-%%p-%%r</code>
<code># Enabling pipelining reduces the number of SSH operations required to </code>
<code># execute a module on the remote server. This can result in a significant </code>
<code># performance improvement when enabled, however when using "sudo:" you must </code>
<code># first disable 'requiretty' in /etc/sudoers</code>
<code># By default, this option is disabled to preserve compatibility with</code>
<code># sudoers configurations that have requiretty (the default on many distros).</code>
<code>#pipelining = False</code>
<code># if True, make ansible use scp if the connection type is ssh </code>
<code># (default is sftp)</code>
<code>#scp_if_ssh = True</code>
<code>[accelerate]</code>
<code>accelerate_port = 5099</code>
<code>accelerate_timeout = 30</code>
<code>accelerate_connect_timeout = 5.0</code>
<code># The daemon timeout is measured in minutes. This time is measured</code>
<code># from the last activity to the accelerate daemon.</code>
<code>accelerate_daemon_timeout = 30 </code>
<code># If set to yes, accelerate_multi_key will allow multiple</code>
<code># private keys to be uploaded to it, though each user must</code>
<code># have access to the system via SSH to add a new key. The default</code>
<code># is "no".</code>
<code>#accelerate_multi_key = yes</code>
<code>[selinux]</code>
<code># file systems that require special treatment when dealing with security context</code>
<code># the default behaviour that copies the existing context or uses the user default</code>
<code># needs to be changed to use the file system dependant context.</code>
<code>#special_context_filesystems=nfs,vboxsf,fuse</code>
<code>簡易配置:</code>
<code>[defaults]</code>
<code>inventory = </code><code>/etc/ansible/hosts</code>
<code>sudo_user=root</code>
<code>remote_port=22</code>
<code>host_key_checking=False</code>
<code>remote_user=root</code>
<code>log_path=</code><code>/var/log/ansible</code><code>.log</code>
<code>module_name=</code><code>command</code>
<code>private_key_file=</code><code>/root/</code><code>.</code><code>ssh</code><code>/id_rsa</code>
<code>no_log:True</code>
<code></code><code></code>
<code></code><code>本文轉自MT_IT51CTO部落格,原文連結:http://blog.51cto.com/hmtk520/2058103,如需轉載請自行聯系原作者</code>
<code></code>