ansible 配置文件的學習

  • 配置文件node

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

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

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

 

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
    

 

簡化配置redis

[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

 

+
相關文章
相關標籤/搜索