ansible的lookup
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.py
- DOCUMENTATION = """
- lookup: list
- author: Ansible core team
- version_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: localhost
- tasks:
- - name: unlike with_items you will get 3 items from this loop, the 2nd one being a list
- debug: var=item
- with_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.py
- DOCUMENTATION = """
- lookup: random_choice
- author: Michael DeHaan <michael.dehaan@gmail.com>
- version_added: "1.1"
- short_description: return random element from list
- description:
- - 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 MUDs
- debug:
- 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: env
- author: Jan-Piet Mens (@jpmens) <jpmens(at)gmail.com>
- version_added: "0.9"
- short_description: read the value of environment variables
- requirements:
- - 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 for
- required: 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.py
- DOCUMENTATION = '''
- author:
- - Juan Manuel Parrilla (@jparrill)
- lookup: hiera
- version_added: "2.4"
- short_description: get info from hiera data
- requirements:
- - hiera (command line utility)
- description:
- - Retrieves data from an Puppetmaster node using Hiera as ENC
- options:
- _hiera_key:
- description:
- - The list of keys to lookup on the Puppetmaster
- type: list
- element_type: string
- required: True
- _bin_file:
- description:
- - Binary file to execute Hiera
- default: '/usr/bin/hiera'
- env:
- - name: ANSIBLE_HIERA_BIN
- _hierarchy_file:
- description:
- - File that describes the hierarchy of Hiera
- default: '/etc/hiera.yaml'
- env:
- - name: ANSIBLE_HIERA_CFG
- FIXME:
- 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: file
- author: Daniel Hokka Zakrisson <daniel@hozac.com>
- version_added: "0.9"
- short_description: read lines from command
- description:
- - Run a commandi or more and split the output into lines returning them as a list
- options:
- _terms:
- description: command(s) to run
- required: True
- notes:
- - 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 command
- debug: msg="{{ item }} is a line running cat on /etc/motd"
- with_lines: cat /etc/motd
- - name: More useful example of looping over a command result
- shell: "/usr/bin/frobnicate {{ item }}"
- with_lines:
- - "/usr/bin/frobnications_per_host --param {{ inventory_hostname }}"
- """
- indexed_items.py
- DOCUMENTATION = """
- lookup: indexed_items
- author: 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.1
- options:
- _terms:
- description: list of items
- required: True
- """
- EXAMPLES = """
- - name: indexed loop demo
- debug:
- msg: "at array position {{ item.0 }} there is a value {{ item.1 }}"
- with_indexed_items:
- - "{{ some_list }}"
- """
- sequence.py
- DOCUMENTATION = """
- lookup: sequence
- author: Jayson Vantuyl <jayson@aggressive.ly>
- version_added: "1.0"
- short_description: generate a list based on a number sequence
- description:
- - generates a sequence of items. You can specify a start value, an end value, an optional "stride" value that specifies the number of steps
- to 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 sequence
- default: 0
- type: number
- end:
- description: number at which to end the sequence, dont use this with count
- type: number
- default: 0
- count:
- description: number of elements in the sequence, this is not to be used with end
- type: number
- default: 0
- stride:
- description: increments between sequence numbers, the default is 1 unless the end is less than the start, then it is -1.
- type: number
- format:
- description: return a string with the generated number formated in
- """
- EXAMPLES = """
- - name: create some test users
- user:
- name: "{{ item }}"
- state: present
- groups: "evens"
- with_sequence: start=0 end=32 format=testuser%02x
- - name: create a series of directories with even numbers for some reason
- file:
- dest: "/var/stuff/{{ item }}"
- state: directory
- with_sequence: start=4 end=16 stride=2
- - name: a simpler way to use the sequence plugin create 4 groups
- group:
- name: "group{{ item }}"
- state: present
- with_sequence: count=4
- - name: the final countdown
- debug: msg={{item}} seconds to detonation
- with_sequence: end=0 start=10
- """
ansible的lookup的更多相关文章
- 007.Ansible变量Fact,魔法变量和lookup生成变量
一 fact变量 1.1 fact简介 ansible有一个模块叫setup,用于获取远程主机的相关信息,并可以将这些信息作为变量在playbook里进行调用.而setup模块获取这些信息的方法就是 ...
- ansible配置文件详解
# ansible配置文件配置 配置项介绍 , 配置文件ansible.cfg, 运行playbook时,默认时在yaml文件所在路径寻找,然后再去/etc/ansible/下寻找 [defaults ...
- 初探ansible
Ansible 基于ssh的自动化运维工具 ansible 配置文件详解 ansible.cfg 文件 文件默认放置在/etc/ansible下,ansible读取配置文件的顺序是: 当前命令执行目录 ...
- 002. Ansible部署及配置介绍
一 Ansible的安装部署 1.1 PIP方式 安装PIP 略,可参考<001.Pip简介及使用>. 提示:建议将PIP升级到最新:pip install --upgrade pip. ...
- Ansible配置文件
官方配置文件文档 Ansible安装完成之后默认配置文件为:/etc/asnible/ansible.cfg Ansible配置文件内容: cat ansible.cfg # config file ...
- ansible Developing Plugins
Action plugins是模块的前端,可以在调用模块本身之前对控制器执行操作. Cache plugins用于保存“facts”的缓存,以避免代价高昂的fact-gathering操作. Call ...
- Ansible 小手册系列 四(详解配置文件)
[root@host-172-20-6-120 ansible]# ansible --version ansible 2.2.0.0 config file = /etc/ansible/ansib ...
- ansible 入门学习(一)
一,ansible 目录结构 (来自于ansible权威指南) 二,ansible.cfg 配置项说明 /etc/ansible/ansible.cfg --> ———————————————— ...
- ansible 2.1.0 api 编程
pdf文档 https://media.readthedocs.org/pdf/ansible/latest/ansible.pdf api介绍 http://blog.csdn.net/python ...
随机推荐
- Basic GC Tuning
Sizing the Heap -XmsN -XmxN Summary The JVM will attempt to find a reasonable minimum and maximum he ...
- Vue实现tab选项卡
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- LIS的O(nlogn)算法
出自蓝书<算法竞赛入门经典训练指南> 求最长上升子序列是很常见的可以用动态规划解决的问题…… 很容易根据最优子结构之类的东西得出 $\text{dp}[i]$为以第i个数结尾的最长上升子序 ...
- 下载图片没有关闭http输入流导致下载超时
在某次接入第三方厂商数据时,需要根据对方提供的URL地址下载图片,当数据量大时会遇到很多的下载图片超时问题,开始以为是第三方厂商的问题,对方排查了很久之后,说是我这边下载数据全部留在缓存区,导致缓存区 ...
- eclipse报错 : One or more constraints have not been satisfied.
当eclipse进行报错时,但是不影响运行时,这种错误一般是编译时的问题 进行修改3个地方,即可完成 一 : 进行修改这三个地方的配置文件,都改成你统一的jdk版本,和你用的Dynamic Web ...
- SQL 中左连接与右链接的区别
在微信公众号中看到的sql左连接与右链接的总结,这个图总结的很好,所以单独收藏下:
- WC2019滚粗记
什么?你问WC2019滚粗记在哪里? 抱歉,这篇文章鸽了. 原因? 引用神仙\(yyb\)的话. 恩,想了想还是更一点吧. Day 0 签到海星,我写了个大大的\(Cgod\)有没有人看见啊,然后被广 ...
- Short But Scary 解题报告
Short But Scary 正解的离线分治+虚树的做法太神奇...搞不到 搞一个菜一点的ddp写写,结果调了200年,下次一定写树剖不写lct了,太难调了... 大概就是按sub2那样维护 你每个 ...
- Python【第五篇】模块、包、常用模块
一.模块(Module) 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文 ...
- lesson03
3.1. 画 点 3.2. 基准平面 (重要) 1. 关于 点 的使用() 1.画一条直线,在线上画一个点(利用该点占该线段的百分比画出),通过该点画一条直线 2. 画一个长方体,定位到上表面.选择( ...