lookup路径: /usr/lib/python2.7/site-packages/ansible/plugins/lookup

所有的lookup插件列表cartesian.py
dnstxt.py
hashi_vault.py
lastpass.py
random_choice.py
chef_databag.py
env.py
hiera.py
lines.py
redis_kv.py
consul_kv.py
etcd.py
indexed_items.py
list.py
sequence.py
credstash.py
fileglob.py
ini.py
mongodb.py
shelvefile.py
csvfile.py
file.py
nested.py
subelements.py
cyberarkpassword.py
filetree.py
inventory_hostnames.py
password.py
template.py
dict.py
first_found.py
items.py
passwordstore.py
together.py
dig.py
flattened.py
keyring.py
pipe.py
url.py

list.pyDOCUMENTATION = """lookup: listauthor: Ansible core teamversion_added: "2.0"short_description: simply returns what it is given.description:- this is mostly a noop, to be used as a with_list loop when you dont want the content transformed in any way.
"""
EXAMPLES = """
---
- hosts: localhosttasks:- name: unlike with_items you will get 3 items from this loop, the 2nd one being a listdebug: var=itemwith_list:- 1- [2,3]- 4
...
输出如下:
[root@node-1 test_plays]# ansible-playbook test.yml PLAY [localhost] *******************************************************************************TASK [unlike with_items you will get 3 items from this loop, the 2nd one being a list] *********
ok: [localhost] => (item=1) => {"changed": false, "item": 1
}
ok: [localhost] => (item=[2, 3]) => {"changed": false, "item": [2, 3]
}
ok: [localhost] => (item=4) => {"changed": false, "item": 4
}PLAY RECAP *************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

random_choice.pyDOCUMENTATION = """lookup: random_choiceauthor: Michael DeHaan <michael.dehaan@gmail.com>version_added: "1.1"short_description: return random element from listdescription:- The 'random_choice' feature can be used to pick something at random. While it's not a load balancer (there are modules for those),it can somewhat be used as a poor man's load balancer in a MacGyver like situation.- At a more basic level, they can be used to add chaos and excitement to otherwise predictable automation environments.
"""
EXAMPLES = """
- name: Magic 8 ball for MUDsdebug:msg: "{{ item }}"with_random_choice:- "go through the door"- "drink from the goblet"- "press the red button"- "do nothing"
"""
脚本输出
[root@node-1 test_plays]# ansible-playbook test.yml 

PLAY [localhost] *******************************************************************************TASK [Magic 8 ball for MUDs] *******************************************************************
ok: [localhost] => (item=go through the door) => {"changed": false, "item": "go through the door", "msg": "go through the door"
}PLAY RECAP *************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

env.py DOCUMENTATION = """lookup: envauthor: Jan-Piet Mens (@jpmens) <jpmens(at)gmail.com>version_added: "0.9"short_description: read the value of environment variablesrequirements:- dns/dns.resolver (python library)description:- Allows you to query the environment variables available on the controller when you invoked Ansible.options:_terms:description: Environment variable or list of them to lookup the values forrequired: True
"""EXAMPLES = """
- debug: msg="{{ lookup('env','HOME') }} is an environment variable"
"""
[root@node-1 test_plays]# ansible-playbook test.yml 

PLAY [localhost] *******************************************************************************TASK [debug] ***********************************************************************************
ok: [localhost] => {"msg": "/root is an environment variable"
}PLAY RECAP *************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

hiera.pyDOCUMENTATION = '''author:- Juan Manuel Parrilla (@jparrill)lookup: hieraversion_added: "2.4"short_description: get info from hiera datarequirements:- hiera (command line utility)description:- Retrieves data from an Puppetmaster node using Hiera as ENCoptions:_hiera_key:description:- The list of keys to lookup on the Puppetmastertype: listelement_type: stringrequired: True_bin_file:description:- Binary file to execute Hieradefault: '/usr/bin/hiera'env:- name: ANSIBLE_HIERA_BIN_hierarchy_file:description:- File that describes the hierarchy of Hieradefault: '/etc/hiera.yaml'env:- name: ANSIBLE_HIERA_CFGFIXME:description: incomplete options .. _terms? environment/fqdn?  ANSIBLE_HIERA_CFG, ANSIBLE_HIERA_BIN
'''EXAMPLES = """
# All this examples depends on hiera.yml  that describes the hierarchy- name: "a value from Hiera 'DB'"debug: msg={{ lookup('hiera', 'foo') }}
- name: "a value from a Hiera 'DB' on other environment"debug: msg={{ lookup('hiera', 'foo environment=production') }}- name: "a value from a Hiera 'DB' for a concrete node"debug: msg={{ lookup('hiera', 'foo fqdn=puppet01.localdomain') }}
"""
脚本输出
[root@node-1 test_plays]# ansible-playbook test.yml 

PLAY [localhost] *******************************************************************************TASK [a value from Hiera 'DB'] *****************************************************************
ok: [localhost] => {"msg": "nil"
}TASK [a value from a Hiera 'DB' on other environment] ******************************************
ok: [localhost] => {"msg": "nil"
}TASK [a value from a Hiera 'DB' for a concrete node] *******************************************
ok: [localhost] => {"msg": "nil"
}PLAY RECAP *************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0   

lines.py
DOCUMENTATION = """lookup: fileauthor: Daniel Hokka Zakrisson <daniel@hozac.com>version_added: "0.9"short_description: read lines from commanddescription:- Run a commandi or more and split the output into lines returning them as a listoptions:_terms:description: command(s) to runrequired: Truenotes:- Like all lookups this runs on the Ansible controller and is unaffected by other keywords, such as become,so if you need to different permissions you must change the command or run Ansible as another user.- Alternatively you can use a shell/command task that runs against localhost and registers the result.
"""
EXAMPLES = """
- name: we could use file direclty, but this shows output from commanddebug: msg="{{ item }} is a line running cat on /etc/motd"with_lines: cat /etc/motd- name: More useful example of looping over a command resultshell: "/usr/bin/frobnicate {{ item }}"with_lines:- "/usr/bin/frobnications_per_host --param {{ inventory_hostname }}"
"""

indexed_items.pyDOCUMENTATION = """lookup: indexed_itemsauthor: Michael DeHaan <michael.dehaan@gmail.com>version_added: "1.3"short_description: rewrites lists to return 'indexed items'description:- use this lookup if you want to loop over an array and also get the numeric index of where you are in the array as you go- any list given will be transformed with each resulting element having the it's previous position in item.0 and its value in item.1options:_terms:description: list of itemsrequired: True
"""EXAMPLES = """
- name: indexed loop demodebug:msg: "at array position {{ item.0 }} there is a value {{ item.1 }}"with_indexed_items:- "{{ some_list }}"
"""

sequence.py

DOCUMENTATION = """lookup: sequenceauthor: Jayson Vantuyl <jayson@aggressive.ly>version_added: "1.0"short_description: generate a list based on a number sequencedescription:- generates a sequence of items. You can specify a start value, an end value, an optional "stride" value that specifies the number of stepsto increment the sequence, and an optional printf-style format string.- 'Arguments can be specified as key=value pair strings or as a shortcut form of the arguments string is also accepted: [start-]end[/stride][:format].'- 'Numerical values can be specified in decimal, hexadecimal (0x3f8) or octal (0600).'- Starting at version 1.9.2, negative strides are allowed.options:start:description: number at which to start the sequencedefault: 0type: numberend:description: number at which to end the sequence, dont use this with counttype: numberdefault: 0count:description: number of elements in the sequence, this is not to be used with endtype: numberdefault: 0stride:description: increments between sequence numbers, the default is 1 unless the end is less than the start, then it is -1.type: numberformat:description: return a string with the generated number formated in
"""EXAMPLES = """
- name: create some test usersuser:name: "{{ item }}"state: presentgroups: "evens"with_sequence: start=0 end=32 format=testuser%02x
- name: create a series of directories with even numbers for some reasonfile:dest: "/var/stuff/{{ item }}"state: directorywith_sequence: start=4 end=16 stride=2- name: a simpler way to use the sequence plugin create 4 groupsgroup:name: "group{{ item }}"state: presentwith_sequence: count=4- name: the final countdowndebug: msg={{item}} seconds to detonationwith_sequence: end=0 start=10
"""

转载于:https://www.cnblogs.com/wangl-blog/p/9008040.html

ansible的lookup相关推荐

  1. 《Ansible权威指南 》一第2章 Ansible基础元素介绍

    本节书摘来自华章出版社<Ansible权威指南 >一书中的第2章,第2.1节,李松涛 魏 巍 甘 捷 著更多章节内容可以访问云栖社区"华章计算机"公众号查看. 第2章 ...

  2. 自动化运维 -- 02 Ansible

    0参考资料 三度的ansible首页 http://www.cnblogs.com/sanduzxcvbnm/category/1036442.html kkblog的ansible首页 http:/ ...

  3. 一文学懂ansible

    目录 1. 文件模块 1.1 fetch 1.2 copy 1.3 file 1.4 blockinfile 1.5 lineinfile 1.6 find 1.7 replace 2. 命令模块 2 ...

  4. ansible Are you sure you want to continue connecting (yes/no)?

    如题中的问题修复: 修改文件 /etc/ansible/ansible.cfg 中的: host_key_checking = False 注:如果文件 /etc/ansible/ansible.cf ...

  5. 【Ansible自动化运维工具】Ansible变量之lookup生成变量方法

    [Ansible自动化运维工具]Ansible变量之lookup生成变量方法 一.lookup插件介绍 1.lookup简介 2.lookup使用场景 3.lookup获取的数据源 4.lookup的 ...

  6. Ansible :一个配置管理和IT自动化工具

    ========================================================================================== 一.基础介绍 == ...

  7. ansible基础-playbooks

    1. playbooks介绍 如果说ansible的modules是工具,inventory配置文件是原材料,那么playbook就是一封说明书,这里会记录任务是如何如何执行的,当然如果你愿意,这里也 ...

  8. Ansible之八:Playbook循环

    在使用ansible做自动化运维的时候,免不了的要重复执行某些操作,如:添加几个用户,创建几个MySQL用户并为之赋予权限,操作某个目录下所有文件等等.好在playbook支持循环语句,可以使得某些需 ...

  9. Ansible学习实战手记-你想要知道的可能都在这里了

    最近接触了ansible工具,查找了一些资料,也做了一些总结.希望能给刚接触的新手带来一些帮助. 此总结有实际例子,大部分也是从实践中用到才逐一总结的. 当然可能肯定一定会存在一些错误和纰漏,还望大家 ...

最新文章

  1. [20160303]显示bbed x命令格式.txt
  2. Git学习笔记05--git stash
  3. 计算机组成原理实验报告西华大学,计算机组成原理实验报告算术逻辑运算单元实验...
  4. 启明云端分享| sigmastar SSD201/ SSD202D _OTA升级使用参考
  5. 罗马数字转整数(C实现)
  6. wxpython使窗口重新显示出来_wxPython实现窗口在任务栏中闪烁
  7. content:\2b 是什么意义
  8. JVM 史上最最最完整深入解析(12000 字总结)
  9. The authors of these two monitoring tools
  10. 在WINDOWS 2003上运行Apache服务
  11. Visio风格源代码组件库,流程图,矢量图,图形编辑,打印,导入,导出,VC++源代码...
  12. 宝塔 python项目管理器2.0 部署django项目 uwsgi
  13. IntelliJ IDEA 如何设置黑色主题以及Java字体的大小与颜色
  14. java调用通用对话框_使用通用对话框
  15. 电脑桌面的计算机图双击打不开,win10双击电脑图标打不开必须右键打开
  16. 易班显示不能连接到服务器检查网络,易班站内应用、轻应用、网站接入、移动应用的区别...
  17. java debug命令_Mame DEBUG调试命令详细指令速查大全
  18. 邹城机器人产业园出租_华丰机器人产业园写字楼出租出售租赁出租我们是专
  19. 计算机算法可以用自然语言来描述吗,算法可以用自然语言描述吗
  20. Hadoop No FileSystem for scheme “hdfs“ 客户端环境变量配置

热门文章

  1. verilog 生成块_Verilog数字系统设计教程之学习摘要
  2. 联调测试是什么意思_功能模块提测前注意这几件事,再也不怕被测试diss了
  3. greenplum数据导入到mysql,将数据从DB2数据库传输到greenplum数据库
  4. 20200806:Java拓扑排序实现力扣210课程表Ⅱ
  5. 20200506:最低票价(leetcode983)
  6. 20191011:冒泡排序的改良版--Shaker排序
  7. 20191001:String,StringBuffer,StringBuilder类异同辨析
  8. python new init_python的new与init
  9. 大数据时代下的信息安全
  10. 物联网核心安全系列——物联网安全需求