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

  1. 所有的lookup插件列表
    cartesian.py
  2. dnstxt.py
  3. hashi_vault.py
  4. lastpass.py
  5. random_choice.py
  6. chef_databag.py
  7. env.py
  8. hiera.py
  9. lines.py
  10. redis_kv.py
  11. consul_kv.py
  12. etcd.py
  13. indexed_items.py
  14. list.py
  15. sequence.py
  16. credstash.py
  17. fileglob.py
  18. ini.py
  19. mongodb.py
  20. shelvefile.py
  21. csvfile.py
  22. file.py
  23. nested.py
  24. subelements.py
  25. cyberarkpassword.py
  26. filetree.py
  27. inventory_hostnames.py
  28. password.py
  29. template.py
  30. dict.py
  31. first_found.py
  32. items.py
  33. passwordstore.py
  34. together.py
  35. dig.py
  36. flattened.py
  37. keyring.py
  38. pipe.py
  39. url.py
  1. list.py
  2.  
  3. DOCUMENTATION = """
  4. lookup: list
  5. author: Ansible core team
  6. version_added: "2.0"
  7. short_description: simply returns what it is given.
  8. description:
  9. - this is mostly a noop, to be used as a with_list loop when you dont want the content transformed in any way.
  10. """
  11. EXAMPLES = """
  12. ---
  13. - hosts: localhost
  14. tasks:
  15. - name: unlike with_items you will get 3 items from this loop, the 2nd one being a list
  16. debug: var=item
  17. with_list:
  18. - 1
  19. - [2,3]
  20. - 4
  21. ...
  22. 输出如下:
  23. [root@node-1 test_plays]# ansible-playbook test.yml
  24.  
  25. PLAY [localhost] *******************************************************************************
  26.  
  27. TASK [unlike with_items you will get 3 items from this loop, the 2nd one being a list] *********
  28. ok: [localhost] => (item=1) => {
  29. "changed": false,
  30. "item": 1
  31. }
  32. ok: [localhost] => (item=[2, 3]) => {
  33. "changed": false,
  34. "item": [
  35. 2,
  36. 3
  37. ]
  38. }
  39. ok: [localhost] => (item=4) => {
  40. "changed": false,
  41. "item": 4
  42. }
  43.  
  44. PLAY RECAP *************************************************************************************
  45. localhost : ok=1 changed=0 unreachable=0 failed=0
  1. random_choice.py
  2.  
  3. DOCUMENTATION = """
  4. lookup: random_choice
  5. author: Michael DeHaan <michael.dehaan@gmail.com>
  6. version_added: "1.1"
  7. short_description: return random element from list
  8. description:
  9. - The 'random_choice' feature can be used to pick something at random. While it's not a load balancer (there are modules for those),
  10. it can somewhat be used as a poor man's load balancer in a MacGyver like situation.
  11. - At a more basic level, they can be used to add chaos and excitement to otherwise predictable automation environments.
  12. """
  13. EXAMPLES = """
  14. - name: Magic 8 ball for MUDs
  15. debug:
  16. msg: "{{ item }}"
  17. with_random_choice:
  18. - "go through the door"
  19. - "drink from the goblet"
  20. - "press the red button"
  21. - "do nothing"
  22. """
  23. 脚本输出
  24. [root@node-1 test_plays]# ansible-playbook test.yml
  25.  
  26. PLAY [localhost] *******************************************************************************
  27.  
  28. TASK [Magic 8 ball for MUDs] *******************************************************************
  29. ok: [localhost] => (item=go through the door) => {
  30. "changed": false,
  31. "item": "go through the door",
  32. "msg": "go through the door"
  33. }
  34.  
  35. PLAY RECAP *************************************************************************************
  36. localhost : ok=1 changed=0 unreachable=0 failed=0
  1. env.py
  2.  
  3. DOCUMENTATION = """
  4. lookup: env
  5. author: Jan-Piet Mens (@jpmens) <jpmens(at)gmail.com>
  6. version_added: "0.9"
  7. short_description: read the value of environment variables
  8. requirements:
  9. - dns/dns.resolver (python library)
  10. description:
  11. - Allows you to query the environment variables available on the controller when you invoked Ansible.
  12. options:
  13. _terms:
  14. description: Environment variable or list of them to lookup the values for
  15. required: True
  16. """
  17.  
  18. EXAMPLES = """
  19. - debug: msg="{{ lookup('env','HOME') }} is an environment variable"
  20. """
  21. [root@node-1 test_plays]# ansible-playbook test.yml
  22.  
  23. PLAY [localhost] *******************************************************************************
  24.  
  25. TASK [debug] ***********************************************************************************
  26. ok: [localhost] => {
  27. "msg": "/root is an environment variable"
  28. }
  29.  
  30. PLAY RECAP *************************************************************************************
  31. localhost : ok=1 changed=0 unreachable=0 failed=0
  1. hiera.py
  2.  
  3. DOCUMENTATION = '''
  4. author:
  5. - Juan Manuel Parrilla (@jparrill)
  6. lookup: hiera
  7. version_added: "2.4"
  8. short_description: get info from hiera data
  9. requirements:
  10. - hiera (command line utility)
  11. description:
  12. - Retrieves data from an Puppetmaster node using Hiera as ENC
  13. options:
  14. _hiera_key:
  15. description:
  16. - The list of keys to lookup on the Puppetmaster
  17. type: list
  18. element_type: string
  19. required: True
  20. _bin_file:
  21. description:
  22. - Binary file to execute Hiera
  23. default: '/usr/bin/hiera'
  24. env:
  25. - name: ANSIBLE_HIERA_BIN
  26. _hierarchy_file:
  27. description:
  28. - File that describes the hierarchy of Hiera
  29. default: '/etc/hiera.yaml'
  30. env:
  31. - name: ANSIBLE_HIERA_CFG
  32. FIXME:
  33. description: incomplete options .. _terms? environment/fqdn? ANSIBLE_HIERA_CFG, ANSIBLE_HIERA_BIN
  34. '''
  35.  
  36. EXAMPLES = """
  37. # All this examples depends on hiera.yml that describes the hierarchy
  38.  
  39. - name: "a value from Hiera 'DB'"
  40. debug: msg={{ lookup('hiera', 'foo') }}
  41. - name: "a value from a Hiera 'DB' on other environment"
  42. debug: msg={{ lookup('hiera', 'foo environment=production') }}
  43.  
  44. - name: "a value from a Hiera 'DB' for a concrete node"
  45. debug: msg={{ lookup('hiera', 'foo fqdn=puppet01.localdomain') }}
  46. """
  47. 脚本输出
  48. [root@node-1 test_plays]# ansible-playbook test.yml
  49.  
  50. PLAY [localhost] *******************************************************************************
  51.  
  52. TASK [a value from Hiera 'DB'] *****************************************************************
  53. ok: [localhost] => {
  54. "msg": "nil"
  55. }
  56.  
  57. TASK [a value from a Hiera 'DB' on other environment] ******************************************
  58. ok: [localhost] => {
  59. "msg": "nil"
  60. }
  61.  
  62. TASK [a value from a Hiera 'DB' for a concrete node] *******************************************
  63. ok: [localhost] => {
  64. "msg": "nil"
  65. }
  66.  
  67. PLAY RECAP *************************************************************************************
  68. localhost : ok=3 changed=0 unreachable=0 failed=0
  1. lines.py
  2. DOCUMENTATION = """
  3. lookup: file
  4. author: Daniel Hokka Zakrisson <daniel@hozac.com>
  5. version_added: "0.9"
  6. short_description: read lines from command
  7. description:
  8. - Run a commandi or more and split the output into lines returning them as a list
  9. options:
  10. _terms:
  11. description: command(s) to run
  12. required: True
  13. notes:
  14. - Like all lookups this runs on the Ansible controller and is unaffected by other keywords, such as become,
  15. so if you need to different permissions you must change the command or run Ansible as another user.
  16. - Alternatively you can use a shell/command task that runs against localhost and registers the result.
  17. """
  18. EXAMPLES = """
  19. - name: we could use file direclty, but this shows output from command
  20. debug: msg="{{ item }} is a line running cat on /etc/motd"
  21. with_lines: cat /etc/motd
  22.  
  23. - name: More useful example of looping over a command result
  24. shell: "/usr/bin/frobnicate {{ item }}"
  25. with_lines:
  26. - "/usr/bin/frobnications_per_host --param {{ inventory_hostname }}"
  27. """
  1. indexed_items.py
  2.  
  3. DOCUMENTATION = """
  4. lookup: indexed_items
  5. author: Michael DeHaan <michael.dehaan@gmail.com>
  6. version_added: "1.3"
  7. short_description: rewrites lists to return 'indexed items'
  8. description:
  9. - 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
  10. - 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
  11. options:
  12. _terms:
  13. description: list of items
  14. required: True
  15. """
  16.  
  17. EXAMPLES = """
  18. - name: indexed loop demo
  19. debug:
  20. msg: "at array position {{ item.0 }} there is a value {{ item.1 }}"
  21. with_indexed_items:
  22. - "{{ some_list }}"
  23. """
  1. sequence.py
  2.  
  3. DOCUMENTATION = """
  4. lookup: sequence
  5. author: Jayson Vantuyl <jayson@aggressive.ly>
  6. version_added: "1.0"
  7. short_description: generate a list based on a number sequence
  8. description:
  9. - generates a sequence of items. You can specify a start value, an end value, an optional "stride" value that specifies the number of steps
  10. to increment the sequence, and an optional printf-style format string.
  11. - '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].'
  12. - 'Numerical values can be specified in decimal, hexadecimal (0x3f8) or octal (0600).'
  13. - Starting at version 1.9.2, negative strides are allowed.
  14. options:
  15. start:
  16. description: number at which to start the sequence
  17. default: 0
  18. type: number
  19. end:
  20. description: number at which to end the sequence, dont use this with count
  21. type: number
  22. default: 0
  23. count:
  24. description: number of elements in the sequence, this is not to be used with end
  25. type: number
  26. default: 0
  27. stride:
  28. description: increments between sequence numbers, the default is 1 unless the end is less than the start, then it is -1.
  29. type: number
  30. format:
  31. description: return a string with the generated number formated in
  32. """
  33.  
  34. EXAMPLES = """
  35. - name: create some test users
  36. user:
  37. name: "{{ item }}"
  38. state: present
  39. groups: "evens"
  40. with_sequence: start=0 end=32 format=testuser%02x
  41. - name: create a series of directories with even numbers for some reason
  42. file:
  43. dest: "/var/stuff/{{ item }}"
  44. state: directory
  45. with_sequence: start=4 end=16 stride=2
  46.  
  47. - name: a simpler way to use the sequence plugin create 4 groups
  48. group:
  49. name: "group{{ item }}"
  50. state: present
  51. with_sequence: count=4
  52.  
  53. - name: the final countdown
  54. debug: msg={{item}} seconds to detonation
  55. with_sequence: end=0 start=10
  56. """

ansible的lookup的更多相关文章

  1. 007.Ansible变量Fact,魔法变量和lookup生成变量

    一 fact变量 1.1  fact简介 ansible有一个模块叫setup,用于获取远程主机的相关信息,并可以将这些信息作为变量在playbook里进行调用.而setup模块获取这些信息的方法就是 ...

  2. ansible配置文件详解

    # ansible配置文件配置 配置项介绍 , 配置文件ansible.cfg, 运行playbook时,默认时在yaml文件所在路径寻找,然后再去/etc/ansible/下寻找 [defaults ...

  3. 初探ansible

    Ansible 基于ssh的自动化运维工具 ansible 配置文件详解 ansible.cfg 文件 文件默认放置在/etc/ansible下,ansible读取配置文件的顺序是: 当前命令执行目录 ...

  4. 002. Ansible部署及配置介绍

    一 Ansible的安装部署 1.1 PIP方式 安装PIP 略,可参考<001.Pip简介及使用>. 提示:建议将PIP升级到最新:pip install --upgrade pip. ...

  5. Ansible配置文件

    官方配置文件文档 Ansible安装完成之后默认配置文件为:/etc/asnible/ansible.cfg Ansible配置文件内容: cat ansible.cfg # config file ...

  6. ansible Developing Plugins

    Action plugins是模块的前端,可以在调用模块本身之前对控制器执行操作. Cache plugins用于保存“facts”的缓存,以避免代价高昂的fact-gathering操作. Call ...

  7. Ansible 小手册系列 四(详解配置文件)

    [root@host-172-20-6-120 ansible]# ansible --version ansible 2.2.0.0 config file = /etc/ansible/ansib ...

  8. ansible 入门学习(一)

    一,ansible 目录结构 (来自于ansible权威指南) 二,ansible.cfg 配置项说明 /etc/ansible/ansible.cfg --> ———————————————— ...

  9. ansible 2.1.0 api 编程

    pdf文档 https://media.readthedocs.org/pdf/ansible/latest/ansible.pdf api介绍 http://blog.csdn.net/python ...

随机推荐

  1. Basic GC Tuning

    Sizing the Heap -XmsN -XmxN Summary The JVM will attempt to find a reasonable minimum and maximum he ...

  2. Vue实现tab选项卡

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. LIS的O(nlogn)算法

    出自蓝书<算法竞赛入门经典训练指南> 求最长上升子序列是很常见的可以用动态规划解决的问题…… 很容易根据最优子结构之类的东西得出 $\text{dp}[i]$为以第i个数结尾的最长上升子序 ...

  4. 下载图片没有关闭http输入流导致下载超时

    在某次接入第三方厂商数据时,需要根据对方提供的URL地址下载图片,当数据量大时会遇到很多的下载图片超时问题,开始以为是第三方厂商的问题,对方排查了很久之后,说是我这边下载数据全部留在缓存区,导致缓存区 ...

  5. eclipse报错 : One or more constraints have not been satisfied.

    当eclipse进行报错时,但是不影响运行时,这种错误一般是编译时的问题 进行修改3个地方,即可完成 一 :  进行修改这三个地方的配置文件,都改成你统一的jdk版本,和你用的Dynamic Web ...

  6. SQL 中左连接与右链接的区别

    在微信公众号中看到的sql左连接与右链接的总结,这个图总结的很好,所以单独收藏下:

  7. WC2019滚粗记

    什么?你问WC2019滚粗记在哪里? 抱歉,这篇文章鸽了. 原因? 引用神仙\(yyb\)的话. 恩,想了想还是更一点吧. Day 0 签到海星,我写了个大大的\(Cgod\)有没有人看见啊,然后被广 ...

  8. Short But Scary 解题报告

    Short But Scary 正解的离线分治+虚树的做法太神奇...搞不到 搞一个菜一点的ddp写写,结果调了200年,下次一定写树剖不写lct了,太难调了... 大概就是按sub2那样维护 你每个 ...

  9. Python【第五篇】模块、包、常用模块

    一.模块(Module) 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文 ...

  10. lesson03

    3.1. 画 点 3.2. 基准平面 (重要) 1. 关于 点 的使用() 1.画一条直线,在线上画一个点(利用该点占该线段的百分比画出),通过该点画一条直线 2. 画一个长方体,定位到上表面.选择( ...