ansible api常用模块与参数
###ansibleAPI 常用模块 用于读取yaml,json格式的文件
from ansible.parsing.dataloader import DataLoader
#用于管理变量的类,包括主机,组,扩展等变量
from ansible.vars.manager import VariableManager
#用于创建和管理inventory,倒入inventory文件
from ansible.inventory.manager import InventoryManager
#ad-hoc 存储着角色列表,任务,处理代码块
from ansible.playbook.play import Play
#ad-hoc ansible底层用到的任务队列
from ansible.executor.task_queue_manager import TaskQueueManager
#回调基类,用来定义回调事件,比如返回失败成功等信息
from ansible.plugins.callback import CallbackBase
#执行playbook
from ansible.executor.playbook_executor import PlaybookExecutor
#操作单个主机
from ansible.inventory import host
#操作单个主机组
from ansible.inventory import group ###InventoryManager #实例化需要两个参数
"参数一为读取yml文件的信息,需要实例化 DataLoader"
"参数二为读取从那个位置读取资产配置文件,多个可逗号分割"
intertory = InventoryManager(loader='',sources='')
#以字典的方式打印出主机和主机组相关信息
intertory.get_group_dict()
#获取所有的主机
inventory.get_hosts()
#添加主机到指定主机组
"参数一指定主机地址"
"参数二指定主机端口"
"参数三指定主机群组,必须存在的群组"
inventory.add_host(host='1.1.1.1',port=2222,group='web_server')
#获取指定的主机对象
inventory.get_host(hostname='1.1.1.1') ###VariableManager #实例化需要两个参数
"参数一为读取yml文件的信息,需要实例化 DataLoader"
"参数二为资产管理配置变量"
variable = VariableManager(loader=loader,inventory=inventory)
#获取变量
variable.get_vars()
# 查看指定主机的详细变量信息
"传入的host是inventory.get_host获得的主机对象"
host = inventory.get_host(hostname='1.1.1.1')
host_vars = variable.get_vars(host=host)
#设置主机变量方法
"传入的host是inventory.get_host获得的主机对象"
host = inventory.get_host(hostname='1.1.1.1')
variable.set_host_variable(host=host,varname='ansible_ssh_pass',value='')
#添加扩展变量
"参数是一个字典多个逗号分割"
variable.extra_vars={'devops':'best'} ##################
Runner参数:
host_list=C.DEFAULT_HOST_LIST, # ex: /etc/ansible/hosts, legacy usage #执行host清单,如果不指定文件,会读取ansible.cfg文件的inventory = xx字段。
module_path=None, # ex: /usr/share/ansible#模块路径,比如:/usr/share/ansible ex==example。
module_name=C.DEFAULT_MODULE_NAME, # ex: copy#模块的名字。
module_args=C.DEFAULT_MODULE_ARGS, # ex: "src=/tmp/a dest=/tmp/b"#模块的参数。
forks=C.DEFAULT_FORKS, # parallelism level并发进程数。
timeout=C.DEFAULT_TIMEOUT, # SSH timeout#ssh 连接超时。
pattern=C.DEFAULT_PATTERN, # which hosts? ex: 'all', 'acme.example.org'#host清单里,匹配的组 host清单。
remote_user=C.DEFAULT_REMOTE_USER, # ex: 'username'#远程登录用户和执行用户。
remote_pass=C.DEFAULT_REMOTE_PASS, # ex: 'password123' or None if using key#远程登录用户密码。
remote_port=None, # if SSH on different ports#ssh连接端口。
private_key_file=C.DEFAULT_PRIVATE_KEY_FILE, # if not using keys/passwords#私钥位置,如果不是ssh 连接话。
background=0, # async poll every X seconds, else 0 for non-async#异步参数。
basedir=None, # directory of playbook, if applicable#playbook 路径。
setup_cache=None, # used to share fact data w/ other tasks#搜集远程节点的信息。
vars_cache=None, # used to store variables about hosts#host清单变量。
transport=C.DEFAULT_TRANSPORT, # 'ssh', 'paramiko', 'local'#连接远程主机的方式,是ssh还是paramiko....
conditional='True', # run only if this fact expression evals to true #未知
callbacks=None, # used for output#用于结果输出。
module_vars=None, # a playbooks internals thing##模块变量。
play_vars=None, #
play_file_vars=None, #
role_vars=None, #
role_params=None, #
default_vars=None, #
extra_vars=None, # extra vars specified with he playbook(s)#其他额外一些参数。
is_playbook=False, # running from playbook or not?
inventory=None, # reference to Inventory object
subset=None, # subset pattern
check=False, # don't make any changes, just try to probe for potential changes#测试play,看看对hostlist产生哪些变化。
diff=False, # whether to show diffs for template files that change
environment=None, # environment variables (as dict) to use inside the command
complex_args=None, # structured data in addition to module_args, must be a dict
error_on_undefined_vars=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR, # ex. False
accelerate=False, # use accelerated connection
accelerate_ipv6=False, # accelerated connection w/ IPv6
accelerate_port=None, # port to use with accelerated connection
vault_pass=None,
run_hosts=None, # an optional list of pre-calculated hosts to run on
no_log=False, # option to enable/disable logging for a given task
run_once=False, # option to enable/disable host bypass loop for a given task
become=False, # whether to run privelege escalation or not
become_method=C.DEFAULT_BECOME_METHOD,
become_user=C.DEFAULT_BECOME_USER, # ex: 'root'
become_pass=C.DEFAULT_BECOME_PASS, # ex: 'password123' or None
become_exe=C.DEFAULT_BECOME_EXE, # ex: /usr/local/bin/sudo
):
# used to lock multiprocess inputs and outputs at various levels
self.output_lockfile = OUTPUT_LOCKFILE
self.process_lockfile = PROCESS_LOCKFILE
ansible api常用模块与参数的更多相关文章
- ansible API 常用模块
常用模块 用于读取yaml,json格式的文件 from ansible.parsing.dataloader import DataLoader #用于管理变量的类,包括主机,组,扩展等变量 fro ...
- ansible中常用模块详解
ansible中常用的模块详解: file模块 ansible内置的可以查看模块用法的命令如下: [root@docker5 ~]# ansible-doc -s file - name: Sets ...
- Ansible之常用模块(一)
ansible之所以功能强大,不是ansible本身,是因为它有众多的模块,前文我们介绍了ansible的基础介绍,系列命令的用法以及选项的说明,通过前文的学习我们知道了ansible是基于pytho ...
- ansible 四常用模块
常用模块 Ansible默认提供了很多模块来供我们使用.在Linux中,我们可以通过 ansible-doc -l 命令查看到当前Ansible支持哪些模块,通过 ansible-doc -s [模块 ...
- ansible 003 常用模块
常用模块 file 模块 管理被控端文件 回显为绿色则,未变更,符合要求 黄色则改变 红色则报错 因为默认值为file,那么文件不存在,报错 改为touch则创建 将state改为directory变 ...
- Ansible Playbooks 常用模块
官网链接:https://docs.ansible.com/ansible/latest/modules/list_of_all_modules.html ansible python module ...
- ansible小结常用模块
根据官方的分类,将模块按功能分类为:云模块.命令模块.数据库模块.文件模块.资产模块.消息模块.监控模块.网络模块.通知模块.包管理模块.源码控制模块.系统模块.单元模块.web设施模块.window ...
- Ansible之常用模块(二)
1.hostname:此模块的主要作用是管理远端节点主机名 模块帮助: root@localhost ~]# ansible-doc -s hostname - name: Manage hostna ...
- Ansible之常用模块介绍
环境 ansible HOST-PATTERN -m MOD_NAME -a MOD_ARGS -C -f forks ssh-keygen -t rsa -P "" ssh-co ...
随机推荐
- 注册IIS的批处理
新建记事本 输入以下内容 @echo 开始注册Asp.net!%SystemDrive%\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_reg ...
- django系列8.5--使用装饰器(视图函数中)实现用户登录状态检验
views.py def session_auth(fn): def inner(request,*args,**kwargs): status = request.session.get('sess ...
- 深入了解java虚拟机(JVM) 第十二章 类加载器
一.什么是类加载器 类加载器是一个用来加载类文件的类,Java源代码通过javac编译器编译成类文件,然后JVM来执行类文件中的字节码来执行程序.需要注意的是,只有被同一个类加载器加载的类才可能会相等 ...
- LCS - Longest Common Substring(spoj1811) (sam(后缀自动机)+LCS)
A string is finite sequence of characters over a non-empty finite set \(\sum\). In this problem, \(\ ...
- BZOJ4283: 魔法少女伊莉雅(最短路径图+最短路径树)
题面 传送门 题解 太长了不想写了→_→ 题解 //minamoto #include<bits/stdc++.h> #define R register #define inf 0x3f ...
- 使用memcache或redis限制某个用户或者某ip用户一段时间内最大投票次数
实现每个用户在某网站10分钟内最多投票5次 function isFrequently($key){ $t = 60*10; $n = 5; $mem = new Memcache(); $mem-& ...
- rpm 安装卸载
安装命令 rpm -i example.rpm 安装 example.rpm 包: rpm -iv example.rpm 安装 example.rpm 包并在安装过程中显示正在安装的文件信息: rp ...
- Laravel5.5 引入并使用第三方类库操作
理论上,Laravel5系列都支持,各位可以一试.我这里使用5.5版本. 我这里引入了一个将汉字转化为拼音的类库测试,一起来看看吧! 首先,在laravel的app目录下自定义一个文件夹,我用的名字是 ...
- ArcGis10.2破解教程
ArcGis10.2下载地址: https://pan.baidu.com/s/15s5ki_8gf0_732br6h43Hw 破解步骤: 1.完成License Manager的安装. 2.将破解文 ...
- Service Discovery protocol(SDP)
locating services provided by Volume 3 , Part C , section 8 2.1sdp client-server architecture 2.2 se ...