init
This commit is contained in:
commit
c5cd492449
475 changed files with 27928 additions and 0 deletions
|
@ -0,0 +1,9 @@
|
|||
# Ansible Lookup Plugins
|
||||
Ansible lookup plugins allow you to query information with the `lookup()` function.
|
||||
|
||||
- [ansible.builtin.url](ansible.builtin.url.md)
|
||||
- [ansible.builtin.template](ansible.builtin.template.md)
|
||||
- [ansible.builtin.ini](ansible.builtin.ini.md)
|
||||
- [ansible.builtin.file](ansible.builtin.file.md)
|
||||
- [ansible.builtin.env](ansible.builtin.env.md)
|
||||
- [ansible.builtin.csvfile](ansible.builtin.csvfile.md)
|
32
technology/tools/Ansible/lookups/ansible.builtin.csvfile.md
Normal file
32
technology/tools/Ansible/lookups/ansible.builtin.csvfile.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
# ansible.builtin.csvfile
|
||||
The csvfile lookup reads the contents of a file in [CSV](../../../files/CSV.md) (comma-separated value) format. The lookup looks for the row where the first column matches keyname (which can be multiple words) and returns the value in the col column (default 1, which indexed from 0 means the second column in the file).
|
||||
|
||||
## Parameter
|
||||
| Parameter | Type | Description |
|
||||
| ------------- | ------ | --------------------------------------------------------------------- |
|
||||
| **col** | string | column to return (0 indexed). |
|
||||
| **default** | string | what to return if the value is not found in the file. |
|
||||
| **delimiter** | string | field separator in the file, for a tab you can specify `TAB` or `\t`. |
|
||||
| **file** | string | name of the CSV/TSV file to open. |
|
||||
|
||||
## Examples
|
||||
```yml
|
||||
- name: Match 'Li' on the first column, return the second column (0 based index)
|
||||
ansible.builtin.debug: msg="The atomic number of Lithium is {{ lookup('ansible.builtin.csvfile', 'Li file=elements.csv delimiter=,') }}"
|
||||
|
||||
- name: msg="Match 'Li' on the first column, but return the 3rd column (columns start counting after the match)"
|
||||
ansible.builtin.debug: msg="The atomic mass of Lithium is {{ lookup('ansible.builtin.csvfile', 'Li file=elements.csv delimiter=, col=2') }}"
|
||||
|
||||
- name: Define Values From CSV File, this reads file in one go, but you could also use col= to read each in it's own lookup.
|
||||
ansible.builtin.set_fact:
|
||||
loop_ip: "{{ csvline[0] }}"
|
||||
int_ip: "{{ csvline[1] }}"
|
||||
int_mask: "{{ csvline[2] }}"
|
||||
int_name: "{{ csvline[3] }}"
|
||||
local_as: "{{ csvline[4] }}"
|
||||
neighbor_as: "{{ csvline[5] }}"
|
||||
neigh_int_ip: "{{ csvline[6] }}"
|
||||
vars:
|
||||
csvline: "{{ lookup('ansible.builtin.csvfile', bgp_neighbor_ip, file='bgp_neighbors.csv', delimiter=',') }}"
|
||||
delegate_to: localhost
|
||||
```
|
26
technology/tools/Ansible/lookups/ansible.builtin.env.md
Normal file
26
technology/tools/Ansible/lookups/ansible.builtin.env.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
# ansible.builtin.env
|
||||
Allows you to query the environment variables available on the controller when you invoked Ansible.
|
||||
|
||||
## Examples
|
||||
```yml
|
||||
- name: Basic usage
|
||||
ansible.builtin.debug:
|
||||
msg: "'{{ lookup('ansible.builtin.env', 'HOME') }}' is the HOME environment variable."
|
||||
|
||||
- name: Before 2.13, how to set default value if the variable is not defined.
|
||||
This cannot distinguish between USR undefined and USR=''.
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('ansible.builtin.env', 'USR')|default('nobody', True) }} is the user."
|
||||
|
||||
- name: Example how to set default value if the variable is not defined, ignores USR=''
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('ansible.builtin.env', 'USR', default='nobody') }} is the user."
|
||||
|
||||
- name: Set default value to Undefined, if the variable is not defined
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('ansible.builtin.env', 'USR', default=Undefined) }} is the user."
|
||||
|
||||
- name: Set default value to undef(), if the variable is not defined
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('ansible.builtin.env', 'USR', default=undef()) }} is the user."
|
||||
```
|
22
technology/tools/Ansible/lookups/ansible.builtin.file.md
Normal file
22
technology/tools/Ansible/lookups/ansible.builtin.file.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
# ansible.builtin.file
|
||||
This lookup returns the contents from a file on the Ansible controller’s file system.
|
||||
|
||||
## Parameters
|
||||
| Parameter | Type | Description |
|
||||
| ---------- | ----------------- | ---------------------------------------------------------------------------- |
|
||||
| **Input** | string / required | path(s) of files to read |
|
||||
| **lstrip** | boolean | whether or not to remove whitespace from the beginning of the looked-up file |
|
||||
| **rstrip** | boolean | whether or not to remove whitespace from the ending of the looked-up file |
|
||||
|
||||
## Examples
|
||||
```yml
|
||||
- ansible.builtin.debug:
|
||||
msg: "the value of foo.txt is {{ lookup('ansible.builtin.file', '/etc/foo.txt') }}"
|
||||
|
||||
- name: display multiple file contents
|
||||
ansible.builtin.debug: var=item
|
||||
with_file:
|
||||
- "/path/to/foo.txt"
|
||||
- "bar.txt" # will be looked in files/ dir relative to play or in role
|
||||
- "/path/to/biz.txt"
|
||||
```
|
28
technology/tools/Ansible/lookups/ansible.builtin.ini.md
Normal file
28
technology/tools/Ansible/lookups/ansible.builtin.ini.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
# ansible.builtin.ini
|
||||
The ini lookup reads the contents of a file in INI format `key1=value1`. This plugin retrieves the value on the right side after the equal sign `'='` of a given section `[section]`.
|
||||
|
||||
## Parameters
|
||||
| Parameter | Type | Description |
|
||||
| ----------- | ----------------- | ------------------------------------------------- |
|
||||
| **Input** | string / required | The key(s) to look up. |
|
||||
| **default** | string | Return value if the key is not in the ini file. |
|
||||
| **file** | string | Name of the file to load. |
|
||||
| **re** | boolean | Flag to indicate if the key supplied is a regexp. |
|
||||
| **section** | string | Section where to lookup the key. |
|
||||
|
||||
## Examples
|
||||
```yml
|
||||
- ansible.builtin.debug: msg="User in integration is {{ lookup('ansible.builtin.ini', 'user', section='integration', file='users.ini') }}"
|
||||
|
||||
- ansible.builtin.debug: msg="User in production is {{ lookup('ansible.builtin.ini', 'user', section='production', file='users.ini') }}"
|
||||
|
||||
- ansible.builtin.debug: msg="user.name is {{ lookup('ansible.builtin.ini', 'user.name', type='properties', file='user.properties') }}"
|
||||
|
||||
- ansible.builtin.debug:
|
||||
msg: "{{ item }}"
|
||||
loop: "{{ q('ansible.builtin.ini', '.*', section='section1', file='test.ini', re=True) }}"
|
||||
|
||||
- name: Read an ini file with allow_no_value
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('ansible.builtin.ini', 'user', file='mysql.ini', section='mysqld', allow_no_value=True) }}"
|
||||
```
|
22
technology/tools/Ansible/lookups/ansible.builtin.template.md
Normal file
22
technology/tools/Ansible/lookups/ansible.builtin.template.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
# ansible.builtin.template
|
||||
Returns a list of strings; for each template in the list of templates you pass in, returns a string containing the results of processing that template.
|
||||
|
||||
## Parameters
|
||||
| Parameter | Type | Description |
|
||||
| ----------------- | ---------- | ---------------------------------------------------------------------------- |
|
||||
| **template_vars** | dictionary | A dictionary, the keys become additional variables available for templating. |
|
||||
|
||||
## Examples
|
||||
```yml
|
||||
- name: show templating results
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('ansible.builtin.template', './some_template.j2') }}"
|
||||
|
||||
- name: show templating results with different variable start and end string
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('ansible.builtin.template', './some_template.j2', variable_start_string='[%', variable_end_string='%]') }}"
|
||||
|
||||
- name: show templating results with different comment start and end string
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('ansible.builtin.template', './some_template.j2', comment_start_string='[#', comment_end_string='#]') }}"
|
||||
```
|
32
technology/tools/Ansible/lookups/ansible.builtin.url.md
Normal file
32
technology/tools/Ansible/lookups/ansible.builtin.url.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
# ansible.builtin.url
|
||||
Returns the content of the URL requested to be used as data in play.
|
||||
|
||||
## Parameters
|
||||
| Parameter | Type | Description |
|
||||
| ------------------ | ------------------------- | ---------------------------------------------------------------------------------- |
|
||||
| **headers** | dictionary | HTTP request headers |
|
||||
| **password** | string | Password to use for HTTP authentication. |
|
||||
| **split_lines** | boolean (Default: `true`) | Flag to control if content is returned as a list of lines or as a single text blob |
|
||||
| **username** | string | Username to use for HTTP authentication. |
|
||||
| **validate_certs** | boolean (Default: `true`) | Flag to control SSL certificate validation |
|
||||
|
||||
## Examples
|
||||
```yml
|
||||
- name: url lookup splits lines by default
|
||||
ansible.builtin.debug: msg="{{item}}"
|
||||
loop: "{{ lookup('ansible.builtin.url', 'https://github.com/gremlin.keys', wantlist=True) }}"
|
||||
|
||||
- name: display ip ranges
|
||||
ansible.builtin.debug: msg="{{ lookup('ansible.builtin.url', 'https://ip-ranges.amazonaws.com/ip-ranges.json', split_lines=False) }}"
|
||||
|
||||
- name: url lookup using authentication
|
||||
ansible.builtin.debug: msg="{{ lookup('ansible.builtin.url', 'https://some.private.site.com/file.txt', username='bob', password='hunter2') }}"
|
||||
|
||||
- name: url lookup using basic authentication
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('ansible.builtin.url', 'https://some.private.site.com/file.txt', username='bob', password='hunter2', force_basic_auth='True') }}"
|
||||
|
||||
- name: url lookup using headers
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('ansible.builtin.url', 'https://some.private.site.com/api/service', headers={'header1':'value1', 'header2':'value2'} ) }}"
|
||||
```
|
|
@ -0,0 +1,78 @@
|
|||
# community.mongodb.mongodb
|
||||
The [MongoDB](../../../applications/MongoDB.md) lookup runs the *find()* command on a given *collection* on a given *MongoDB* server.
|
||||
|
||||
The result is a list of jsons, so slightly different from what PyMongo returns. In particular, *timestamps* are converted to epoch integers.
|
||||
|
||||
## Parameters
|
||||
| Parameter | Type | Description |
|
||||
| ------------------ | -------------------- | ----------------------------------------------------------------------------------------- |
|
||||
| **collection** | string / required | Name of the collection which the query will be made |
|
||||
| **connect_string** | string | Can be any valid MongoDB connection string, supporting authentication, replica sets, etc. |
|
||||
| **database** | string / required | Name of the database which the query will be made |
|
||||
| **filter** | dictionary | Criteria of the output |
|
||||
| **limit** | integer | How many results should be shown |
|
||||
| **projection** | dictionary | Fields you want returned |
|
||||
| **skip** | integer | How many results should be skipped |
|
||||
| **sort** | list / elements=list | Sorting rules. |
|
||||
|
||||
## Examples
|
||||
```yml
|
||||
- hosts: localhost
|
||||
gather_facts: false
|
||||
vars:
|
||||
mongodb_parameters:
|
||||
#mandatory parameters
|
||||
database: 'local'
|
||||
collection: "startup_log"
|
||||
#optional
|
||||
connection_string: "mongodb://localhost/"
|
||||
# connection_string: "mongodb://username:password@my.server.com:27017/"
|
||||
# extra_connection_parameters: { "ssl" : True , "ssl_certfile": /etc/self_signed_certificate.pem" }
|
||||
#optional query parameters, we accept any parameter from the normal mongodb query.
|
||||
# filter: { "hostname": "u18" }
|
||||
projection: { "pid": True , "_id" : False , "hostname" : True }
|
||||
skip: 0
|
||||
limit: 1
|
||||
sort: [ [ "startTime" , "ASCENDING" ] , [ "age", "DESCENDING" ] ]
|
||||
tasks:
|
||||
- debug: msg="The PID from MongoDB is {{ lookup('mongodb', mongodb_parameters ).pid }}"
|
||||
|
||||
- debug: msg="The HostName from the MongoDB server is {{ lookup('mongodb', mongodb_parameters ).hostname }}"
|
||||
|
||||
- debug: msg="Mongo DB is stored at {{ lookup('mongodb', mongodb_parameters_inline )}}"
|
||||
vars:
|
||||
mongodb_parameters_inline:
|
||||
database: 'local'
|
||||
collection: "startup_log"
|
||||
connection_string: "mongodb://localhost/"
|
||||
limit: 1
|
||||
projection: { "cmdline.storage": True }
|
||||
|
||||
# lookup syntax, does the same as below
|
||||
- debug: msg="The hostname is {{ item.hostname }} and the pid is {{ item.pid }}"
|
||||
loop: "{{ lookup('mongodb', mongodb_parameters, wantlist=True) }}"
|
||||
|
||||
# query syntax, does the same as above
|
||||
- debug: msg="The hostname is {{ item.hostname }} and the pid is {{ item.pid }}"
|
||||
loop: "{{ query('mongodb', mongodb_parameters) }}"
|
||||
|
||||
- name: "Raw output from the mongodb lookup (a json with pid and hostname )"
|
||||
debug: msg="{{ lookup('mongodb', mongodb_parameters) }}"
|
||||
|
||||
- name: "Yet another mongodb query, now with the parameters on the task itself"
|
||||
debug: msg="pid={{item.pid}} hostname={{item.hostname}} version={{ item.buildinfo.version }}"
|
||||
with_mongodb:
|
||||
- database: 'local'
|
||||
collection: "startup_log"
|
||||
connection_string: "mongodb://localhost/"
|
||||
limit: 1
|
||||
projection: { "pid": True , "hostname": True , "buildinfo.version": True }
|
||||
|
||||
# Please notice this specific query may result more than one result. This is expected
|
||||
- name: "Shows the whole output from mongodb"
|
||||
debug: msg="{{ item }}"
|
||||
with_mongodb:
|
||||
- database: 'local'
|
||||
collection: "startup_log"
|
||||
connection_string: "mongodb://localhost/"
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue