iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >3、Ansible配置文件和Invent
  • 471
分享到

3、Ansible配置文件和Invent

配置文件AnsibleInvent 2023-01-31 03:01:03 471人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

如果是用RPM包方式安装的Ansible,那么安装完成后会生成以下文件:/etc/ansible                              ###存放ansible配置文件的目录/etc/ansible/hosts    

如果是用RPM包方式安装的Ansible,那么安装完成后会生成以下文件:

  • /etc/ansible                              ###存放ansible配置文件的目录

  • /etc/ansible/hosts                   ###ansible Inventory文件

  • /etc/ansible/ansible.cfg        ###ansible的配置文件


如果是pip安装的Ansible,那么需要手动创建这些文件,也可以从其他地方拷贝。



ansible.cfg文件:

获取最新的ansible.cfg配置文件:

https://raw.GitHubusercontent.com/ansible/ansible/devel/examples/ansible.cfg


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/
#remote_tmp     = $HOME/.ansible/tmp
#local_tmp      = $HOME/.ansible/tmp
#forks          = 5
#poll_interval  = 15
#sudo_user      = root
#ask_sudo_pass = True
#ask_pass      = True
#transport      = smart
#remote_port    = 22
#module_lang    = C
#module_set_locale = False

# 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

# by default retrieve all facts subsets
# all - gather all subsets
# network - gather min and network facts
# hardware - gather hardware facts (longest facts to retrieve)
# virtual - gather min and virtual facts
# facter - import facts from facter
# ohai - import facts from ohai
# You can combine them using comma (ex: network,virtual)
# You can negate them using ! (ex: !hardware,!facter,!ohai)
# A minimal set of facts is always gathered.
#gather_subset = all

# additional paths to search for roles in, colon separated
#roles_path    = /etc/ansible/roles

# uncomment this to disable ssh key host checking
#host_key_checking = False

# change the default callback
#stdout_callback = skippy
# enable additional callbacks
#callback_whitelist = timer, mail

# Determine whether includes in tasks and handlers are "static" by
# default. As of 2.0, includes are dynamic by default. Setting these
# values to True will make includes behave more like they did in the
# 1.x versions.
#task_includes_static = True
#handler_includes_static = True

# change this for alternative sudo implementations
#sudo_exe = sudo

# What flags to pass to sudo
# WARNING: leaving out the defaults might create unexpected behaviours
#sudo_flags = -H -S -n

# SSH timeout
#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

# 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

# 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

# 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

# by default, variables from roles will be visible in the global variable
# scope. To prevent this, the following option can be enabled, and only
# tasks and handlers within the role will see the variables there
#private_role_vars = yes

# list any Jinja2 extensions to enable here:
#jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n

# 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

# If set, configures the path to the Vault passWord file as an alternative to
# specifying --vault-password-file on the command line.
#vault_password_file = /path/to/vault_password_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}
# This short version is better used in templates as it won't flag the file as changed every run.
#ansible_managed = Ansible managed: {file} on {host}

# 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, if a task in a playbook does not include a name: field then
# ansible-playbook will construct a header that includes the task's action but
# not the task's args.  This is a security feature because ansible cannot know
# if the *module* considers an argument to be no_log at the time that the
# header is printed.  If your environment doesn't have a problem securing
# stdout from ansible-playbook (or you have manually specified no_log in your
# playbook on all of the tasks where you have secret information) then you can
# safely set this to True to get more informative messages.
#display_args_to_stdout = False

# 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

# 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

# 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

# (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


# set plugin path directories here, separate with colons
#action_plugins     = /usr/share/ansible/plugins/action
#callback_plugins   = /usr/share/ansible/plugins/callback
#connection_plugins = /usr/share/ansible/plugins/connection
#lookup_plugins     = /usr/share/ansible/plugins/lookup
#vars_plugins       = /usr/share/ansible/plugins/vars
#filter_plugins     = /usr/share/ansible/plugins/filter
#test_plugins       = /usr/share/ansible/plugins/test
#strategy_plugins   = /usr/share/ansible/plugins/strategy

# 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


# don't like cows?  that's unfortunate.
# set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1
#nocows = 1

# set which cowsay stencil you'd like to use by default. When set to 'random',
# a random stencil will be selected for each task. The selection will be filtered
# against the `cow_whitelist` option below.
#cow_selection = default
#cow_selection = random

# when using the 'random' option for cowsay, stencils will be restricted to this list.
# it should be formatted as a comma-separated list with no spaces between names.
# NOTE: line continuations here are for formatting purposes only, as the INI parser
#       in python does not support them.
#cow_whitelist=bud-frogs,bunny,cheese,daemon,default,draGon,elephant-in-snake,elephant,eyes,\
#              hellokitty,kitty,luke-koala,meow,milk,moofasa,moose,ren,sheep,small,stegosaurus,\
#              stimpy,supermilker,three-eyes,turkey,turtle,tux,udder,vader-koala,vader,www

# don't like colors either?
# set to 1 if you don't want colors, or export ANSIBLE_NOCOLOR=1
#nocolor = 1

# 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
# When a playbook fails by default a .retry file will be created in ~/
# You can disable this feature by setting retry_files_enabled to False
# and you can change the location of the files by setting retry_files_save_path

#retry_files_enabled = False
#retry_files_save_path = ~/.ansible-retry

# squash actions
# Ansible can optimise actions that call modules with list parameters
# when looping. Instead of calling the module once per with_ item, the
# module is called once with all items at once. Currently this only works
# under limited circumstances, and only with parameters named 'name'.
#squash_actions = apk,apt,dnf,package,pacman,pkgng,yum,zypper

# prevents logging of task data, off by default
#no_log = False

# prevents logging of tasks, but only on the targets, data is still logged on the master/controller
#no_target_syslog = False

# controls whether Ansible will raise an error or warning if a task has no
# choice but to create world readable temporary files to execute a module on
# the remote Machine.  This option is False by default for security.  Users may
# turn this on to have behaviour more like Ansible prior to 2.1.x.  See
# https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user
# for more secure ways to fix this than enabling this option.
#allow_world_readable_tmpfiles = False

# controls the compression level of variables sent to
# worker processes. At the default of 0, no compression
# is used. This value must be an integer from 0 to 9.
#var_compression_level = 9

# controls what compression method is used for new-style ansible modules when
# they are sent to the remote system.  The compression types depend on having
# support compiled into both the controller's Python and the client's python.
# The names should match with the python Zipfile compression types:
# * ZIP_STORED (no compression. available everywhere)
# * ZIP_DEFLATED (uses zlib, the default)
# These values may be set per host via the ansible_module_compression inventory
# variable
#module_compression = 'ZIP_DEFLATED'

# This controls the cutoff point (in bytes) on --diff for files
# set to 0 for unlimited (RAM may suffer!).
#max_diff_size = 1048576

[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, -C controls compression use
#ssh_args = -C -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

# if False, sftp will not use batch mode to transfer files. This may cause some
# types of file transfer failures impossible to catch however, and should
# only be disabled if your sftp version has problems with batch mode
#sftp_batch_mode = False

[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 dependent context.
#special_context_filesystems=nfs,vboxsf,fuse,ramfs

# Set this to yes to allow libvirt_lxc connections to work without SELinux.
#libvirt_lxc_noseclabel = yes

[colors]
#highlight = white
#verbose = blue
#warn = bright purple
#error = red
#debug = dark gray
#deprecate = purple
#skip = cyan
#unreachable = red
#ok = green
#changed = yellow
#diff_add = green
#diff_remove = red
#diff_lines = cyan

下面这个链接中有对配置文件中各个指令的解释:

http://ansible-tran.readthedocs.io/en/latest/docs/intro_configuration.html


Inventory文件:

Ansible 通过读取默认的主机清单配置/etc/ansible/hosts,可以同时连接到多个远程主机上执行任务,默认路径可以通过修改 ansible.cfg 的 hostfile 参数指定路径 

/etc/ansible/hosts 主机清单配置格式如下 :

mail.example.com

[WEBservers]
foo.example.com
bar.example.com

[dbservers]
one.example.com
two.example.com
three.example.com

方括号[]中是组名,用于对系统进行分类,便于对不同系统进行个别的管理

下面的链接中有对Inventory文件更详细的介绍:

http://ansible-tran.readthedocs.io/en/latest/docs/intro_inventory.html






--结束END--

本文标题: 3、Ansible配置文件和Invent

本文链接: https://www.lsjlt.com/news/187714.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 3、Ansible配置文件和Invent
    如果是用RPM包方式安装的Ansible,那么安装完成后会生成以下文件:/etc/ansible                              ###存放ansible配置文件的目录/etc/ansible/hosts     ...
    99+
    2023-01-31
    配置文件 Ansible Invent
  • emacs配置文件3
    Emacs配置文件3;;普通设置(setq inhibit-startup-message t);关闭起动时闪屏(setq visible-bell t);关闭出错时的提示声(show-paren-mode t);显示括号匹配;(set-d...
    99+
    2023-01-31
    配置文件 emacs
  • ansible怎么安装和配置
    这篇“ansible怎么安装和配置”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“ansib...
    99+
    2024-04-02
  • SpringBoot 常用读取配置文件的 3 种方法!
    我们在SpringBoot框架进行项目开发中该如何优雅的读取配置呢?或者说对于一些List或者Map应该如何配置呢? 本篇主要解决如下几个问题: Spring Boot有哪些常用的读取配置文件方式? 1)使用 @Value 读取配置文件 2...
    99+
    2023-08-17
    java 数据库 mysql 面试 服务器
  • WCF简单教程(3) 试着去掉配置文件
    第三篇:试着去掉配置文件 通过配置文件来设置Host、Endpoint、Binding等是WCF中推荐的方法,这样可以使发布尽量灵活。其实配置文件中的值,最终还是要体现到代码中的,只不过这部分工作由底层帮你做了。我们今天来尝试去掉配置文件,...
    99+
    2023-01-31
    试着 配置文件 简单
  • Spring Boot读取Yml配置文件的3种方法
    简述: 项目开发中难免要读取配置文件,本文结合开发经验介绍几种使用过的读取配置文件的方法。 1.基础用法,使用注解@Autowired注入Environment类 这种方式比较常见,就像注入service或者dao一样,声明一个Env...
    99+
    2023-09-03
    spring boot java spring Powered by 金山文档
  • Spring Boot读取配置文件内容的3种方式(@Value、Environment和@ConfigurationProperties)
    目录前言一、@Value二、Environment2.1 注入对象2.2 调用获取属性的方法2.3 上述两种方法对比三、@ConfigurationProperties3.1 创建一...
    99+
    2023-01-04
    springboot中读取配置文件 spring boot读取配置文件 springboot如何读取配置文件
  • 详解SpringBoot读取Yml配置文件的3种方法
    目录简述:1.基础用法,使用注解@Autowired注入Environment类2.基础用法,使用@Value注解直接注入配置信息3.进阶方法简述: 项目开发中难免要读取配置文件,本...
    99+
    2023-05-14
    SpringBoot读取Yml配置文件 SpringBoot读取Yml
  • ASP.NETCore配置文件的获取和设置
    在ASP.NET Core 中,应用程序配置数据可以使用JSON, XML 和 INI格式 和内置环境变量,命令行参数或内存中的集合。 1.如何获取和设置配置 ASP.NET Cor...
    99+
    2024-04-02
  • Spring使用注解和配置文件配置事务
    本文实例为大家分享了Spring使用注解和配置文件配置事务的具体代码,供大家参考,具体内容如下 需求图: 使用注解配置事务: package com.atguigu.spring...
    99+
    2024-04-02
  • docker修改容器配置文件的3种方法总结
    目录run时候已经进行绑定操作修改未绑定的配置文件拷贝容器内外的文件操作修改对外端口等总结run时候已经进行绑定操作 在启动容器的时候可以通过 -v双向绑定本地的某文件,这样任意修改...
    99+
    2024-04-02
  • 总结SpringBoot常用读取配置文件的3种方法
    文章目录 1、使用 @Value 读取配置文件2、 使用 @ConfigurationProperties 读取配置文件3、读取配置文件中的List 1、使用 @Value 读取配置文件 ...
    99+
    2023-09-03
    spring boot java spring
  • 使用log4j2自定义配置文件位置和文件名(附log4j2.xml配置实例)
    目录log4j2自定义配置文件位置和文件名web.xml配置生效配置文件日志配置文件实例log4j2.xml配置及例子1.使用log4j2需要下载包2.配置文件可以有三种格式3.日志...
    99+
    2024-04-02
  • 配置config.sys文件
    这篇文章主要介绍“配置config.sys文件”,在日常操作中,相信很多人在配置config.sys文件问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”配置config.sys文件”的疑惑有所帮助!接下来,请跟...
    99+
    2023-06-09
  • mysql5.7配置文件
    路径 /etc/mysql/conf.d/my.cnf 内容 [client] default-character-set=utf8 [mysql] default-character-set=utf8 ...
    99+
    2024-04-02
  • ini配置文件
    ini配置文件 ini文件是initialization file的缩写,即初始化文件,是widows系统配置文件所采用的存储格式。 文件扩展名: .ini ini配置文件的后缀名也不一定必须是....
    99+
    2023-08-31
    开发语言 ini python c
  • host文件配置
    hosts文件的作用: hosts文件是一个用于储存计算机网络中各节点信息的计算机文件;作用是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从Hosts文件中寻找对应的...
    99+
    2023-09-03
    服务器 运维
  • webpack中怎么配置文件入口和文件出口
    今天小编给大家分享一下webpack中怎么配置文件入口和文件出口的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我...
    99+
    2024-04-02
  • 怎么使用log4j2自定义配置文件位置和文件名
    本篇内容主要讲解“怎么使用log4j2自定义配置文件位置和文件名”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么使用log4j2自定义配置文件位置和文件名”吧!log4j2自定义配置文件位置和...
    99+
    2023-06-22
  • yml配置文件中map的配置
      @Configuration@ConfigurationProperties(prefix = "stable")@Getter@Setter@ToStringpublic class StableCoinConfig { pr...
    99+
    2023-09-03
    java spring mysql
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作