ansible 配置文件

配置文件

   兩個核心文件:ansible.cfg和hosts文件,默認都存放在/etc/ansible目錄下。

   ansible.cfg:主要設置一些ansible初始化的信息,比如日志存放路徑、模塊、插件等配置信息

   hosts:機器清單,進行分組管理

?

 1.ansible.cfg

# config file for ansible -- http://ansible.com/
# ==============================================# nearly all parameters can be overridden in ansible-playbook 
# or with command line flags. ansible will read ANSIBLE_CONFIG,
# ansible.cfg in the current working directory, .ansible.cfg in
# the home directory or /etc/ansible/ansible.cfg, whichever it
# finds first[defaults]   --->通用默認配置# some basic default values...inventory      = /etc/ansible/hosts     這個是默認庫文件位置,腳本,或者存放可通信主機的目錄
#library        = /usr/share/my_modules/   Ansible默認搜尋模塊的位置
remote_tmp     = $HOME/.ansible/tmp   Ansible 通過遠程傳輸模塊到遠程主機,然后遠程執行,執行后在清理現場.在有些場景下,你也許想使用默認路徑希望像更換補丁一樣使用
pattern        = *    如果沒有提供“hosts”節點,這是playbook要通信的默認主機組.默認值是對所有主機通信
forks          = 5    在與主機通信時的默認并行進程數 ,默認是5d
poll_interval  = 15    當具體的poll interval 沒有定義時,多少時間回查一下這些任務的狀態, 默認值是5秒
sudo_user      = root   sudo使用的默認用戶 ,默認是root
#ask_sudo_pass = True   用來控制Ansible playbook 在執行sudo之前是否詢問sudo密碼.默認為no
#ask_pass      = True    控制Ansible playbook 是否會自動默認彈出密碼
transport      = smart   通信機制.默認 值為’smart’。如果本地系統支持 ControlPersist技術的話,將會使用(基于OpenSSH)‘ssh’,如果不支持講使用‘paramiko’.其他傳輸選項包括‘local’, ‘chroot’,’jail’等等
#remote_port    = 22    遠程SSH端口。 默認是22
module_lang    = C   模塊和系統之間通信的計算機語言,默認是C語言# plays will gather facts by default, which contain information about
# the remote system.
#
# smart - gather by default, but don't regather if already gathered
# implicit - gather by default, turn off with gather_facts: False
# explicit - do not gather by default, must say gather_facts: True
gathering = implicit   控制默認facts收集(遠程系統變量). 默認值為’implicit’, 每一次play,facts都會被收集# additional paths to search for roles in, colon separated
#roles_path    = /etc/ansible/roles   roles 路徑指的是’roles/’下的額外目錄,用于playbook搜索Ansible roles# uncomment this to disable SSH key host checking
#host_key_checking = False    檢查主機密鑰# change this for alternative sudo implementations
sudo_exe = sudo     如果在其他遠程主機上使用另一種方式執sudu操作.可以使用該參數進行更換# what flags to pass to sudo   傳遞sudo之外的參數
#sudo_flags = -H# SSH timeout    SSH超時時間
timeout = 10# default user to use for playbooks if user is not specified
# (/usr/bin/ansible will use current user as default)
#remote_user = root   使用/usr/bin/ansible-playbook鏈接的默認用戶名,如果不指定,會使用當前登錄的用戶名# logging is off by default unless this path is defined
# if so defined, consider logrotate
#log_path = /var/log/ansible.log     日志文件存放路徑# default module name for /usr/bin/ansible
#module_name = command     ansible命令執行默認的模塊# use this shell for commands executed under sudo
# you may need to change this to bin/bash in rare instances
# if sudo is constrained
#executable = /bin/sh     在sudo環境下產生一個shell交互接口. 用戶只在/bin/bash的或者sudo限制的一些場景中需要修改# if inventory variables overlap, does the higher precedence one win
# or are hash values merged together?  The default is 'replace' but
# this can also be set to 'merge'.
#hash_behaviour = replace    特定的優先級覆蓋變量# list any Jinja2 extensions to enable here:
#jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n      允許開啟Jinja2拓展模塊# if set, always use this private key file for authentication, same as 
# if passing --private-key to ansible or ansible-playbook
#private_key_file = /path/to/file         私鑰文件存儲位置# format of string {{ ansible_managed }} available within Jinja2 
# templates indicates to users editing templates files will be replaced.
# replacing {file}, {host} and {uid} and strftime codes with proper values.
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}   這個設置可以告知用戶,Ansible修改了一個文件,并且手動寫入的內容可能已經被覆蓋.# by default, ansible-playbook will display "Skipping [host]" if it determines a task
# should not be run on a host.  Set this to "False" if you don't want to see these "Skipping" 
# messages. NOTE: the task header will still be shown regardless of whether or not the 
# task is skipped.
#display_skipped_hosts = True     顯示任何跳過任務的狀態 ,默認是顯示# by default (as of 1.3), Ansible will raise errors when attempting to dereference 
# Jinja2 variables that are not set in templates or action lines. Uncomment this line
# to revert the behavior to pre-1.3.
#error_on_undefined_vars = False      如果所引用的變量名稱錯誤的話, 將會導致ansible在執行步驟上失敗# by default (as of 1.6), Ansible may display warnings based on the configuration of the
# system running ansible itself. This may include warnings about 3rd party packages or
# other conditions that should be resolved if possible.
# to disable these warnings, set the following value to False:
#system_warnings = True    允許禁用系統運行ansible相關的潛在問題警告# by default (as of 1.4), Ansible may display deprecation warnings for language
# features that should no longer be used and will be removed in future versions.
# to disable these warnings, set the following value to False:
#deprecation_warnings = True     允許在ansible-playbook輸出結果中禁用“不建議使用”警告# (as of 1.8), Ansible can optionally warn when usage of the shell and
# command module appear to be simplified by using a default Ansible module
# instead.  These warnings can be silenced by adjusting the following
# setting or adding warn=yes or warn=no to the end of the command line 
# parameter string.  This will for example suggest using the git module
# instead of shelling out to the git command.
# command_warnings = False    當shell和命令行模塊被默認模塊簡化的時,Ansible 將默認發出警告# set plugin path directories here, separate with colons
action_plugins     = /usr/share/ansible_plugins/action_plugins  
callback_plugins   = /usr/share/ansible_plugins/callback_plugins
connection_plugins = /usr/share/ansible_plugins/connection_plugins
lookup_plugins     = /usr/share/ansible_plugins/lookup_plugins
vars_plugins       = /usr/share/ansible_plugins/vars_plugins
filter_plugins     = /usr/share/ansible_plugins/filter_plugins# by default callbacks are not loaded for /bin/ansible, enable this if you
# want, for example, a notification or logging callback to also apply to 
# /bin/ansible runs
#bin_ansible_callbacks = False    用來控制callback插件是否在運行 /usr/bin/ansible 的時候被加載. 這個模塊將用于命令行的日志系統,發出通知等特性# don't like cows?  that's unfortunate.
# set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1 
#nocows = 1    默認ansible可以調用一些cowsay的特性   開啟/禁用:0/1# don't like colors either?
# set to 1 if you don't want colors, or export ANSIBLE_NOCOLOR=1
#nocolor = 1  輸出帶上顏色區別, 開啟/關閉:0/1# the CA certificate path used for validating SSL certs. This path 
# should exist on the controlling node, not the target nodes
# common locations:
# RHEL/CentOS: /etc/pki/tls/certs/ca-bundle.crt
# Fedora     : /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
# Ubuntu     : /usr/share/ca-certificates/cacert.org/cacert.org.crt
#ca_file_path =    # the http user-agent string to use when fetching urls. Some web server
# operators block the default urllib user agent as it is frequently used
# by malicious attacks/scripts, so we set it to something unique to 
# avoid issues.
#http_user_agent = ansible-agent# if set to a persistent type (not 'memory', for example 'redis') fact values
# from previous runs in Ansible will be stored.  This may be useful when
# wanting to use, for example, IP information from one group of servers
# without having to talk to them in the same playbook run to get their
# current IP information.
fact_caching = memory# retry files
#retry_files_enabled = False
#retry_files_save_path = ~/.ansible-retry[privilege_escalation]
#become=True
#become_method=sudo
#become_user=root
#become_ask_pass=False[paramiko_connection]# uncomment this line to cause the paramiko connection plugin to not record new host
# keys encountered.  Increases performance on new host additions.  Setting works independently of the
# host key checking setting above.
#record_host_keys=False# by default, Ansible requests a pseudo-terminal for commands executed under sudo. Uncomment this
# line to disable this behaviour.
#pty=False[ssh_connection]# ssh arguments to use
# Leaving off ControlPersist will result in poor performance, so use 
# paramiko on older platforms rather than removing it
#ssh_args = -o ControlMaster=auto -o ControlPersist=60s# The path to use for the ControlPath sockets. This defaults to
# "%(directory)s/ansible-ssh-%%h-%%p-%%r", however on some systems with
# very long hostnames or very long path names (caused by long user names or 
# deeply nested home directories) this can exceed the character limit on
# file socket names (108 characters for most platforms). In that case, you 
# may wish to shorten the string below.
# 
# Example: 
# control_path = %(directory)s/%%h-%%r
#control_path = %(directory)s/ansible-ssh-%%h-%%p-%%r# Enabling pipelining reduces the number of SSH operations required to 
# execute a module on the remote server. This can result in a significant 
# performance improvement when enabled, however when using "sudo:" you must 
# first disable 'requiretty' in /etc/sudoers
#
# By default, this option is disabled to preserve compatibility with
# sudoers configurations that have requiretty (the default on many distros).
# 
#pipelining = False# if True, make ansible use scp if the connection type is ssh 
# (default is sftp)
#scp_if_ssh = True[accelerate]
accelerate_port = 5099
accelerate_timeout = 30
accelerate_connect_timeout = 5.0# The daemon timeout is measured in minutes. This time is measured
# from the last activity to the accelerate daemon.
accelerate_daemon_timeout = 30 # If set to yes, accelerate_multi_key will allow multiple
# private keys to be uploaded to it, though each user must
# have access to the system via SSH to add a new key. The default
# is "no".
#accelerate_multi_key = yes[selinux]
# file systems that require special treatment when dealing with security context
# the default behaviour that copies the existing context or uses the user default
# needs to be changed to use the file system dependant context.
#special_context_filesystems=nfs,vboxsf,fuse

簡易配置:

[defaults]
inventory      = /etc/ansible/hosts
sudo_user=root
remote_port=22
host_key_checking=False
remote_user=root
log_path=/var/log/ansible.log
module_name=command
private_key_file=/root/.ssh/id_rsa
no_log:True

?

 2.hosts

# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups# Ex 1: Ungrouped hosts, specify before any group headers.green.example.com
blue.example.com
192.168.100.1
192.168.100.10# Ex 2: A collection of hosts belonging to the 'webservers' group[webservers]
alpha.example.org
beta.example.org
192.168.1.100
192.168.1.110# If you have multiple hosts following a pattern you can specify
# them like this:www[001:006].example.com# Ex 3: A collection of database servers in the 'dbservers' group[dbservers]db01.intranet.mydomain.net
db02.intranet.mydomain.net
10.25.1.56
10.25.1.57# Here's another example of host ranges, this time there are no
# leading 0s:db-[99:101]-node.example.com

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/457776.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/457776.shtml
英文地址,請注明出處:http://en.pswp.cn/news/457776.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

高內聚低耦合通俗理解_抱歉,請不要把“業務邏輯層”理解為“業務中臺”

在IAS2019中臺架構峰會上,我曾與一位年輕帥氣的技術小伙來了一番有趣的對話。因為和朋友有約,所以我在現場互動結束之后,就急匆匆地跟其他嘉賓打了聲招呼,抱著筆記本沖出了會場。但沒想到剛到電梯口,卻被一位帥小伙迎面…

ofstream的使用方法--超級精細。C++文件寫入、讀出函數(轉)

ofstream的使用方法ofstream是從內存到硬盤,ifstream是從硬盤到內存,其實所謂的流緩沖就是內存空間; 在C中,有一個stream這個類,所有的I/O都以這個“流”類為基礎的,包括我們要認識的文件I/O,stream這個類…

org-mode入門教程

org-mode 入門教程By Z.H. Fu切問錄 www.fuzihao.orgorg-mode 入門教程 org-mode是Emacs提供的一個強大的編輯模式,可以用于做會議筆記以及制作各種待辦事項(GDT)。其語法類似于Markdown但是提供了比Markdown更多的操作,再加上Ema…

ansible 配置文件優先級

優先級如下: 1.首先找執行ansible命令的當前目錄中,是否有 ansible.cfg文件 ./ansible.cfg 2.如果找不到,再 找 當前用戶的家目錄下是否有 .ansible.cfg ~/.ansible.cfg 3.如果還找不到,就找 /etc/ansible/ansible.cfg /etc/ansible/ansible.…

如何對web.config進行加密和解密

http://blog.csdn.net/jf_jifei/article/details/6527390 在WEB網站開發過程中,如果我們將數據庫連接字符串封裝到.DLL文件中,將會給數據庫和程序的遷移帶來麻煩,因為萬一服務器地址或者數據庫發生變更,那么我們就不得不修改源程序…

java 爬蟲_Java原生代碼實現爬蟲(爬取小說)

Java也能做爬蟲。現在提到爬蟲人第一個想到的就是python,其實使用Java編寫爬蟲也是很好的選擇,Java成熟的爬蟲框架很多,下面給大家展示一個使用Java基礎語言編寫的爬取小說的案例:實現功能:爬取目標網站全本小說代碼編…

JS window對象 Location對象 location用于獲取或設置窗體的URL,并且可以用于解析URL。 語法: location.[屬性|方法]...

Location對象 location用于獲取或設置窗體的URL&#xff0c;并且可以用于解析URL。 語法: location.[屬性|方法] location對象屬性圖示: location 對象屬性&#xff1a; location 對象方法: 任務 在右邊編輯器script標簽內&#xff0c;獲取當前顯示文檔的URL,并輸出。 <!DOC…

ansible inventory 主機清單配置

文章目錄 環境介紹 ansible ssh配置 操作測試/etc/hosts 配置Inventory文件 主機與組主機變量、組變量把一個組變成另一個組的子成員變量太多了&#xff0c;不好管理怎么辦&#xff1f;來&#xff0c;分文件定義主機變量和組變量 操作環境介紹 為了練習方便&#xff0c;本次使…

python(26)查看文件的大小

有時候&#xff0c;在寫文件的時候需要判斷文件的大小&#xff0c;或者刪除空的文件 import os from os.path import join, getsizedef getdirsize(dir):size 0Lfor root, dirs, files in os.walk(dir):print filesfor name in files:print nameprint join(root,name) #輸出文…

java 數據結構_Java版-數據結構-隊列(數組隊列)

前言看過筆者前兩篇介紹的 Java版數據結構 數組和 棧的盆友&#xff0c;都給予了筆者一致的好評&#xff0c;在這里筆者感謝大家的認可&#xff01;&#xff01;&#xff01;由于本章介紹的數據結構是 隊列&#xff0c;在隊列的實現上會基于前面寫的 動態數組來實現&#xff0c…

ssh 介紹 和使用 程序不掛起

目錄 SSH的安全機制 SSH的安裝 啟動服務器的SSH服務 SSH兩種級別的遠程登錄 SSH的高級應用 Secure Shell(SSH) 是由 IETF(The Internet Engineering Task Force) 制定的建立在應用層基礎上的安全網絡協議。它是專為遠程登錄會話(甚至可以用Windows遠程登錄Linux服務器進行…

corpus? academic writing

http://micusp.elicorpora.info/ http://corpus.byu.edu/coca/ http://rcpce.engl.polyu.edu.hk/RACorpus/轉載于:https://www.cnblogs.com/gisalameda/p/5590034.html

vim命令練習題。

練習題。1. vi 與 vim 有什么區別呢&#xff0c;它們之間有什么關系&#xff1f;答&#xff1a;vi 和vim最大的區別就是編輯一個文本時&#xff0c;vi不會顯示顏色&#xff0c;而vim會顯示顏色。顯示顏色更易于用戶進行編輯。vim的這些優勢主要體現在以下幾個方面&#xff1a;1…

java 四舍五入_Java常用類

每個人的心里&#xff0c;都藏著一個了不起的自己&#xff0c;只要你不頹廢&#xff0c;不消極&#xff0c;一直悄悄醞釀著樂觀&#xff0c;培養著豁達&#xff0c;堅持著善良&#xff0c;只要在路上&#xff0c;就沒有到達不了的遠方&#xff01;BigInteger在Java中&#xff0…

Sublime 插件- px 轉rem

一個CSS的px值轉rem值的Sublime Text 3自動完成插件。 插件效果如下&#xff1a; 安裝 克隆項目 https://github.com/hyb628/cssrem.git進入packages目錄&#xff1a;Sublime Text -> Preferences -> Browse Packages...復制下載的cssrem目錄到剛才的packges目錄里。重…

ansible 批量部署ssh免密鑰

1 創建ssh秘鑰 yum install epel-release -y yum install sshpass -y ssh-keygen -t rsa 2 批量復制秘鑰并授權 ansible web -m shell -a ‘mkdir ~/.ssh’ -k ansible web -m copy -a ‘src~/.ssh/id_rsa.pub dest~/.ssh/authorized_keys mode0600’ -k 3 測試 ssh 10.0.0.2…

window8下安裝RabbitMQ

2019獨角獸企業重金招聘Python工程師標準>>> 1.下載并安裝erlang&#xff0c;http://www.erlang.org/download.html。64位的下載的是otp_win64_19.1.exe 查看是否安裝成功&#xff1a; 2.下載RabbitMQ,最新版是2.8.1&#xff0c;http://www.rabbitmq.com/releases/r…

python如何避免轉義字符_如何解決因轉義字符而報錯的問題(在使用python導入文件時)...

有些萌新在初次使用python導入文件時&#xff0c;可能會遇到遇到各種各樣的報錯。今天我們就來講講其中最常見的一種報錯---轉義字符“\”沖突。問題重述&#xff1a;比如像下面這樣&#xff0c;當我們想導入一個常見的csv文件時&#xff0c;發現居然報了這樣一個錯誤&#xff…

同意條款按鈕可用

// 同意條款function isaccepted(){ if(document.getElementById("read").checkedtrue){ document.getElementById("submit").disabled false; $(#submit).css("background","#f25618"); }else{ document.getElementById("s…

Ansible執行過程分析、異步模式和速度優化

Ansible系列(七)&#xff1a;執行過程分析、異步模式和速度優化 分類: Linux服務篇 undefined 我寫了更完善的Ansible專欄文章&#xff1a;一步到位玩兒透Ansible Ansible系列文章&#xff1a;http://www.cnblogs.com/f-ck-need-u/p/7576137.html 1.1 ansible執行過程分析 …