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.mzph.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执行过程分析 …