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 ...
随机推荐
- ADO.NET操作PostgreSQL:数据库操作类(未封装)
1.添加 /// <summary> /// 添加 /// </summary> /// <param name="newEntity">< ...
- C# 使用dynamic类型来访问JObject对象
dynamic是C#里面的动态类型,可在未知类型的情况访问对应的属性,非常灵活和方便. 使用Json.Net可以把一个Json字符串转换成一个JObject对象,如果有已知强类型,如果有已知对应的强类 ...
- php 编译代码
编译其实就是把所有的代码整合在于一个文件,减少文件包含时间,加快php解析,虽然优化后时间上提升了不多,但能优化便多多少少进行优化.下面给一个编译例子,从而引申. // 定义编译状态 define(' ...
- 【Oracle 12c】最新CUUG OCP-071考试题库(56题)
56.(14-14) choose the best answer: You need to create a table with the following column specificatio ...
- Nodejs Express模块server.address().address为::
来自 http://blog.csdn.net/medivhq/article/details/74171939 我按照菜鸟教程上的写法为:(http://www.runoob.com/nodejs/ ...
- Lucene.Net+盘古分词器(详细介绍)
本章阅读概要1.Lucenne.Net简介2.介绍盘古分词器3.Lucene.Net实例分析4.结束语(Demo下载)Lucene.Net简介 Lucene.net是Lucene的.net移植版本,是 ...
- nginx的几种负载均衡策略
转自https://www.cnblogs.com/1214804270hacker/p/9325150.html 一.关于Nginx的负载均衡 在服务器集群中,Nginx起到一个代理服务器的角色(即 ...
- linux进程查看及管理的工具
介绍Linux进程查看及管理的工具:pstree, ps, pidof, pgrep, top, htop, glance, pmap, vmstat, dstat, kill, pkill, jo ...
- python unittest框架理解与总结(二)
unittest基本原理: ♦整个平台的搭建使用的是python的unittest测试框架,这里简单介绍下unittest模块的简单应用. ♦unittest是python的标准测试库,相比于其他测试 ...
- 45.oracle表类型、数据拆分、表分区
不要做一些没有意义的事情,就比如说你要离职并不打算吃回头草,离职理由中完全没有必要说明“领导的水平太渣,人品太差”此类的原因,而是“个人原因”,当然实在不批准辞职另说. oracle表类型 表的类型分 ...