docs: add fqcn to module examples (#73546)

Co-authored-by: Felix Fontein <felix@fontein.de>
pull/76858/head
Syed Ali Haider 4 years ago committed by GitHub
parent 29de2cccba
commit 6bca0a5dc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -343,6 +343,13 @@ In a playbook, you can control the collections Ansible searches for modules and
The ``collections`` keyword merely creates an ordered 'search path' for non-namespaced plugin and role references. It does not install content or otherwise change Ansible's behavior around the loading of plugins or roles. Note that an FQCN is still required for non-action or module plugins (for example, lookups, filters, tests). The ``collections`` keyword merely creates an ordered 'search path' for non-namespaced plugin and role references. It does not install content or otherwise change Ansible's behavior around the loading of plugins or roles. Note that an FQCN is still required for non-action or module plugins (for example, lookups, filters, tests).
When using the ``collections`` keyword, it is not necessary to add in ``ansible.builtin`` as part of the search list. When left omitted, the following content is available by default:
1. Standard ansible modules and plugins available through ``ansible-base``/``ansible-core``
2. Support for older 3rd party plugin paths
In general, it is preferable to use a module or plugin's FQCN over the ``collections`` keyword and the short name for all content in ``ansible-core``
Using a playbook from a collection Using a playbook from a collection
================================== ==================================

@ -54,31 +54,31 @@ seealso:
EXAMPLES = r''' EXAMPLES = r'''
- hosts: localhost - hosts: localhost
tasks: tasks:
- debug: - ansible.builtin.debug:
msg: play1 msg: play1
- name: Include a play after another play - name: Include a play after another play
include: otherplays.yaml ansible.builtin.include: otherplays.yaml
- hosts: all - hosts: all
tasks: tasks:
- debug: - ansible.builtin.debug:
msg: task1 msg: task1
- name: Include task list in play - name: Include task list in play
include: stuff.yaml ansible.builtin.include: stuff.yaml
- debug: - ansible.builtin.debug:
msg: task10 msg: task10
- hosts: all - hosts: all
tasks: tasks:
- debug: - ansible.builtin.debug:
msg: task1 msg: task1
- name: Include task list in play only if the condition is true - name: Include task list in play only if the condition is true
include: "{{ hostvar }}.yaml" ansible.builtin.include: "{{ hostvar }}.yaml"
static: no static: no
when: hostvar is defined when: hostvar is defined
''' '''

@ -73,41 +73,41 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
- name: Add host to group 'just_created' with variable foo=42 - name: Add host to group 'just_created' with variable foo=42
add_host: ansible.builtin.add_host:
name: '{{ ip_from_ec2 }}' name: '{{ ip_from_ec2 }}'
groups: just_created groups: just_created
foo: 42 foo: 42
- name: Add host to multiple groups - name: Add host to multiple groups
add_host: ansible.builtin.add_host:
hostname: '{{ new_ip }}' hostname: '{{ new_ip }}'
groups: groups:
- group1 - group1
- group2 - group2
- name: Add a host with a non-standard port local to your machines - name: Add a host with a non-standard port local to your machines
add_host: ansible.builtin.add_host:
name: '{{ new_ip }}:{{ new_port }}' name: '{{ new_ip }}:{{ new_port }}'
- name: Add a host alias that we reach through a tunnel (Ansible 1.9 and older) - name: Add a host alias that we reach through a tunnel (Ansible 1.9 and older)
add_host: ansible.builtin.add_host:
hostname: '{{ new_ip }}' hostname: '{{ new_ip }}'
ansible_ssh_host: '{{ inventory_hostname }}' ansible_ssh_host: '{{ inventory_hostname }}'
ansible_ssh_port: '{{ new_port }}' ansible_ssh_port: '{{ new_port }}'
- name: Add a host alias that we reach through a tunnel (Ansible 2.0 and newer) - name: Add a host alias that we reach through a tunnel (Ansible 2.0 and newer)
add_host: ansible.builtin.add_host:
hostname: '{{ new_ip }}' hostname: '{{ new_ip }}'
ansible_host: '{{ inventory_hostname }}' ansible_host: '{{ inventory_hostname }}'
ansible_port: '{{ new_port }}' ansible_port: '{{ new_port }}'
- name: Ensure inventory vars are set to the same value as the inventory_hostname has (close to pre Ansible 2.4 behaviour) - name: Ensure inventory vars are set to the same value as the inventory_hostname has (close to pre Ansible 2.4 behaviour)
add_host: ansible.builtin.add_host:
hostname: charlie hostname: charlie
inventory_dir: '{{ inventory_dir }}' inventory_dir: '{{ inventory_dir }}'
- name: Add all hosts running this playbook to the done group - name: Add all hosts running this playbook to the done group
add_host: ansible.builtin.add_host:
name: '{{ item }}' name: '{{ item }}'
groups: done groups: done
loop: "{{ ansible_play_hosts }}" loop: "{{ ansible_play_hosts }}"

@ -206,102 +206,102 @@ notes:
EXAMPLES = ''' EXAMPLES = '''
- name: Install apache httpd (state=present is optional) - name: Install apache httpd (state=present is optional)
apt: ansible.builtin.apt:
name: apache2 name: apache2
state: present state: present
- name: Update repositories cache and install "foo" package - name: Update repositories cache and install "foo" package
apt: ansible.builtin.apt:
name: foo name: foo
update_cache: yes update_cache: yes
- name: Remove "foo" package - name: Remove "foo" package
apt: ansible.builtin.apt:
name: foo name: foo
state: absent state: absent
- name: Install the package "foo" - name: Install the package "foo"
apt: ansible.builtin.apt:
name: foo name: foo
- name: Install a list of packages - name: Install a list of packages
apt: ansible.builtin.apt:
pkg: pkg:
- foo - foo
- foo-tools - foo-tools
- name: Install the version '1.00' of package "foo" - name: Install the version '1.00' of package "foo"
apt: ansible.builtin.apt:
name: foo=1.00 name: foo=1.00
- name: Update the repository cache and update package "nginx" to latest version using default release squeeze-backport - name: Update the repository cache and update package "nginx" to latest version using default release squeeze-backport
apt: ansible.builtin.apt:
name: nginx name: nginx
state: latest state: latest
default_release: squeeze-backports default_release: squeeze-backports
update_cache: yes update_cache: yes
- name: Install the version '1.18.0' of package "nginx" and allow potential downgrades - name: Install the version '1.18.0' of package "nginx" and allow potential downgrades
apt: ansible.builtin.apt:
name: nginx=1.18.0 name: nginx=1.18.0
state: present state: present
allow_downgrade: yes allow_downgrade: yes
- name: Install zfsutils-linux with ensuring conflicted packages (e.g. zfs-fuse) will not be removed. - name: Install zfsutils-linux with ensuring conflicted packages (e.g. zfs-fuse) will not be removed.
apt: ansible.builtin.apt:
name: zfsutils-linux name: zfsutils-linux
state: latest state: latest
fail_on_autoremove: yes fail_on_autoremove: yes
- name: Install latest version of "openjdk-6-jdk" ignoring "install-recommends" - name: Install latest version of "openjdk-6-jdk" ignoring "install-recommends"
apt: ansible.builtin.apt:
name: openjdk-6-jdk name: openjdk-6-jdk
state: latest state: latest
install_recommends: no install_recommends: no
- name: Update all packages to their latest version - name: Update all packages to their latest version
apt: ansible.builtin.apt:
name: "*" name: "*"
state: latest state: latest
- name: Upgrade the OS (apt-get dist-upgrade) - name: Upgrade the OS (apt-get dist-upgrade)
apt: ansible.builtin.apt:
upgrade: dist upgrade: dist
- name: Run the equivalent of "apt-get update" as a separate step - name: Run the equivalent of "apt-get update" as a separate step
apt: ansible.builtin.apt:
update_cache: yes update_cache: yes
- name: Only run "update_cache=yes" if the last one is more than 3600 seconds ago - name: Only run "update_cache=yes" if the last one is more than 3600 seconds ago
apt: ansible.builtin.apt:
update_cache: yes update_cache: yes
cache_valid_time: 3600 cache_valid_time: 3600
- name: Pass options to dpkg on run - name: Pass options to dpkg on run
apt: ansible.builtin.apt:
upgrade: dist upgrade: dist
update_cache: yes update_cache: yes
dpkg_options: 'force-confold,force-confdef' dpkg_options: 'force-confold,force-confdef'
- name: Install a .deb package - name: Install a .deb package
apt: ansible.builtin.apt:
deb: /tmp/mypackage.deb deb: /tmp/mypackage.deb
- name: Install the build dependencies for package "foo" - name: Install the build dependencies for package "foo"
apt: ansible.builtin.apt:
pkg: foo pkg: foo
state: build-dep state: build-dep
- name: Install a .deb package from the internet - name: Install a .deb package from the internet
apt: ansible.builtin.apt:
deb: https://example.com/python-ppq_0.1-1_all.deb deb: https://example.com/python-ppq_0.1-1_all.deb
- name: Remove useless packages from the cache - name: Remove useless packages from the cache
apt: ansible.builtin.apt:
autoclean: yes autoclean: yes
- name: Remove dependencies that are no longer required - name: Remove dependencies that are no longer required
apt: ansible.builtin.apt:
autoremove: yes autoremove: yes
''' '''

@ -105,7 +105,7 @@ EXAMPLES = '''
# Use armored file since utf-8 string is expected. Must be of "PGP PUBLIC KEY BLOCK" type. # Use armored file since utf-8 string is expected. Must be of "PGP PUBLIC KEY BLOCK" type.
- name: Add a key from a file on the Ansible server - name: Add a key from a file on the Ansible server
ansible.builtin.apt_key: ansible.builtin.apt_key:
data: "{{ lookup('file', 'apt.asc') }}" data: "{{ lookup('ansible.builtin.file', 'apt.asc') }}"
state: present state: present
- name: Add an Apt signing key to a specific keyring file - name: Add an Apt signing key to a specific keyring file

@ -73,15 +73,15 @@ author:
''' '''
EXAMPLES = r''' EXAMPLES = r'''
- assert: { that: "ansible_os_family != 'RedHat'" } - ansible.builtin.assert: { that: "ansible_os_family != 'RedHat'" }
- assert: - ansible.builtin.assert:
that: that:
- "'foo' in some_command_result.stdout" - "'foo' in some_command_result.stdout"
- number_of_the_counting == 3 - number_of_the_counting == 3
- name: After version 2.7 both 'msg' and 'fail_msg' can customize failing assertion message - name: After version 2.7 both 'msg' and 'fail_msg' can customize failing assertion message
assert: ansible.builtin.assert:
that: that:
- my_param <= 100 - my_param <= 100
- my_param >= 0 - my_param >= 0
@ -89,14 +89,14 @@ EXAMPLES = r'''
success_msg: "'my_param' is between 0 and 100" success_msg: "'my_param' is between 0 and 100"
- name: Please use 'msg' when ansible version is smaller than 2.7 - name: Please use 'msg' when ansible version is smaller than 2.7
assert: ansible.builtin.assert:
that: that:
- my_param <= 100 - my_param <= 100
- my_param >= 0 - my_param >= 0
msg: "'my_param' must be between 0 and 100" msg: "'my_param' must be between 0 and 100"
- name: Use quiet to avoid verbose output - name: Use quiet to avoid verbose output
assert: ansible.builtin.assert:
that: that:
- my_param <= 100 - my_param <= 100
- my_param >= 0 - my_param >= 0

@ -56,7 +56,7 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
--- ---
- name: Asynchronous yum task - name: Asynchronous yum task
yum: ansible.builtin.yum:
name: docker-io name: docker-io
state: present state: present
async: 1000 async: 1000
@ -64,7 +64,7 @@ EXAMPLES = r'''
register: yum_sleeper register: yum_sleeper
- name: Wait for asynchronous job to end - name: Wait for asynchronous job to end
async_status: ansible.builtin.async_status:
jid: '{{ yum_sleeper.ansible_job_id }}' jid: '{{ yum_sleeper.ansible_job_id }}'
register: job_result register: job_result
until: job_result.finished until: job_result.finished

@ -111,7 +111,7 @@ attributes:
EXAMPLES = r''' EXAMPLES = r'''
# Before Ansible 2.3, option 'dest' or 'name' was used instead of 'path' # Before Ansible 2.3, option 'dest' or 'name' was used instead of 'path'
- name: Insert/Update "Match User" configuration block in /etc/ssh/sshd_config - name: Insert/Update "Match User" configuration block in /etc/ssh/sshd_config
blockinfile: ansible.builtin.blockinfile:
path: /etc/ssh/sshd_config path: /etc/ssh/sshd_config
block: | block: |
Match User ansible-agent Match User ansible-agent
@ -119,7 +119,7 @@ EXAMPLES = r'''
- name: Insert/Update eth0 configuration stanza in /etc/network/interfaces - name: Insert/Update eth0 configuration stanza in /etc/network/interfaces
(it might be better to copy files into /etc/network/interfaces.d/) (it might be better to copy files into /etc/network/interfaces.d/)
blockinfile: ansible.builtin.blockinfile:
path: /etc/network/interfaces path: /etc/network/interfaces
block: | block: |
iface eth0 inet static iface eth0 inet static
@ -127,14 +127,14 @@ EXAMPLES = r'''
netmask 255.255.255.0 netmask 255.255.255.0
- name: Insert/Update configuration using a local file and validate it - name: Insert/Update configuration using a local file and validate it
blockinfile: ansible.builtin.blockinfile:
block: "{{ lookup('file', './local/sshd_config') }}" block: "{{ lookup('ansible.builtin.file', './local/sshd_config') }}"
path: /etc/ssh/sshd_config path: /etc/ssh/sshd_config
backup: yes backup: yes
validate: /usr/sbin/sshd -T -f %s validate: /usr/sbin/sshd -T -f %s
- name: Insert/Update HTML surrounded by custom markers after <body> line - name: Insert/Update HTML surrounded by custom markers after <body> line
blockinfile: ansible.builtin.blockinfile:
path: /var/www/html/index.html path: /var/www/html/index.html
marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->" marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->"
insertafter: "<body>" insertafter: "<body>"
@ -143,13 +143,13 @@ EXAMPLES = r'''
<p>Last updated on {{ ansible_date_time.iso8601 }}</p> <p>Last updated on {{ ansible_date_time.iso8601 }}</p>
- name: Remove HTML as well as surrounding markers - name: Remove HTML as well as surrounding markers
blockinfile: ansible.builtin.blockinfile:
path: /var/www/html/index.html path: /var/www/html/index.html
marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->" marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->"
block: "" block: ""
- name: Add mappings to /etc/hosts - name: Add mappings to /etc/hosts
blockinfile: ansible.builtin.blockinfile:
path: /etc/hosts path: /etc/hosts
block: | block: |
{{ item.ip }} {{ item.name }} {{ item.ip }} {{ item.name }}

@ -94,6 +94,6 @@ EXAMPLES = r'''
- name: Prints two lines of messages, but only if there is an environment value set - name: Prints two lines of messages, but only if there is an environment value set
ansible.builtin.debug: ansible.builtin.debug:
msg: msg:
- "Provisioning based on YOUR_KEY which is: {{ lookup('env', 'YOUR_KEY') }}" - "Provisioning based on YOUR_KEY which is: {{ lookup('ansible.builtin.env', 'YOUR_KEY') }}"
- "These servers were built using the password of '{{ password_used }}'. Please retain this for later use." - "These servers were built using the password of '{{ password_used }}'. Please retain this for later use."
''' '''

@ -279,80 +279,80 @@ author:
EXAMPLES = ''' EXAMPLES = '''
- name: Install the latest version of Apache - name: Install the latest version of Apache
dnf: ansible.builtin.dnf:
name: httpd name: httpd
state: latest state: latest
- name: Install Apache >= 2.4 - name: Install Apache >= 2.4
dnf: ansible.builtin.dnf:
name: httpd>=2.4 name: httpd>=2.4
state: present state: present
- name: Install the latest version of Apache and MariaDB - name: Install the latest version of Apache and MariaDB
dnf: ansible.builtin.dnf:
name: name:
- httpd - httpd
- mariadb-server - mariadb-server
state: latest state: latest
- name: Remove the Apache package - name: Remove the Apache package
dnf: ansible.builtin.dnf:
name: httpd name: httpd
state: absent state: absent
- name: Install the latest version of Apache from the testing repo - name: Install the latest version of Apache from the testing repo
dnf: ansible.builtin.dnf:
name: httpd name: httpd
enablerepo: testing enablerepo: testing
state: present state: present
- name: Upgrade all packages - name: Upgrade all packages
dnf: ansible.builtin.dnf:
name: "*" name: "*"
state: latest state: latest
- name: Install the nginx rpm from a remote repo - name: Install the nginx rpm from a remote repo
dnf: ansible.builtin.dnf:
name: 'http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm' name: 'http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm'
state: present state: present
- name: Install nginx rpm from a local file - name: Install nginx rpm from a local file
dnf: ansible.builtin.dnf:
name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
state: present state: present
- name: Install Package based upon the file it provides - name: Install Package based upon the file it provides
dnf: ansible.builtin.dnf:
name: /usr/bin/cowsay name: /usr/bin/cowsay
state: present state: present
- name: Install the 'Development tools' package group - name: Install the 'Development tools' package group
dnf: ansible.builtin.dnf:
name: '@Development tools' name: '@Development tools'
state: present state: present
- name: Autoremove unneeded packages installed as dependencies - name: Autoremove unneeded packages installed as dependencies
dnf: ansible.builtin.dnf:
autoremove: yes autoremove: yes
- name: Uninstall httpd but keep its dependencies - name: Uninstall httpd but keep its dependencies
dnf: ansible.builtin.dnf:
name: httpd name: httpd
state: absent state: absent
autoremove: no autoremove: no
- name: Install a modularity appstream with defined stream and profile - name: Install a modularity appstream with defined stream and profile
dnf: ansible.builtin.dnf:
name: '@postgresql:9.6/client' name: '@postgresql:9.6/client'
state: present state: present
- name: Install a modularity appstream with defined stream - name: Install a modularity appstream with defined stream
dnf: ansible.builtin.dnf:
name: '@postgresql:9.6' name: '@postgresql:9.6'
state: present state: present
- name: Install a modularity appstream with defined profile - name: Install a modularity appstream with defined profile
dnf: ansible.builtin.dnf:
name: '@postgresql/client' name: '@postgresql/client'
state: present state: present
''' '''

@ -43,7 +43,7 @@ notes:
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: Prevent python from being upgraded - name: Prevent python from being upgraded
dpkg_selections: ansible.builtin.dpkg_selections:
name: python name: python
selection: hold selection: hold
''' '''

@ -90,7 +90,7 @@ author: "Matt Martz (@sivel)"
EXAMPLES = r''' EXAMPLES = r'''
- name: Case insensitive password string match - name: Case insensitive password string match
ansible.builtin.expect: ansible.builtin.expect:
command: passwd username ansible.builtin.command: passwd username
responses: responses:
(?i)password: "MySekretPa$$word" (?i)password: "MySekretPa$$word"
# you don't want to show passwords in your logs # you don't want to show passwords in your logs
@ -98,7 +98,7 @@ EXAMPLES = r'''
- name: Generic question with multiple different responses - name: Generic question with multiple different responses
ansible.builtin.expect: ansible.builtin.expect:
command: /path/to/custom/command ansible.builtin.command: /path/to/custom/command
responses: responses:
Question: Question:
- response1 - response1

@ -57,7 +57,7 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
- name: Example using fail and when together - name: Example using fail and when together
fail: ansible.builtin.fail:
msg: The system may not be provisioned according to the CMDB status. msg: The system may not be provisioned according to the CMDB status.
when: cmdb_status != "to-be-staged" when: cmdb_status != "to-be-staged"
''' '''

@ -144,41 +144,41 @@ seealso:
EXAMPLES = r''' EXAMPLES = r'''
- name: Recursively find /tmp files older than 2 days - name: Recursively find /tmp files older than 2 days
find: ansible.builtin.find:
paths: /tmp paths: /tmp
age: 2d age: 2d
recurse: yes recurse: yes
- name: Recursively find /tmp files older than 4 weeks and equal or greater than 1 megabyte - name: Recursively find /tmp files older than 4 weeks and equal or greater than 1 megabyte
find: ansible.builtin.find:
paths: /tmp paths: /tmp
age: 4w age: 4w
size: 1m size: 1m
recurse: yes recurse: yes
- name: Recursively find /var/tmp files with last access time greater than 3600 seconds - name: Recursively find /var/tmp files with last access time greater than 3600 seconds
find: ansible.builtin.find:
paths: /var/tmp paths: /var/tmp
age: 3600 age: 3600
age_stamp: atime age_stamp: atime
recurse: yes recurse: yes
- name: Find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz - name: Find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz
find: ansible.builtin.find:
paths: /var/log paths: /var/log
patterns: '*.old,*.log.gz' patterns: '*.old,*.log.gz'
size: 10m size: 10m
# Note that YAML double quotes require escaping backslashes but yaml single quotes do not. # Note that YAML double quotes require escaping backslashes but yaml single quotes do not.
- name: Find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz via regex - name: Find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz via regex
find: ansible.builtin.find:
paths: /var/log paths: /var/log
patterns: "^.*?\\.(?:old|log\\.gz)$" patterns: "^.*?\\.(?:old|log\\.gz)$"
size: 10m size: 10m
use_regex: yes use_regex: yes
- name: Find /var/log all directories, exclude nginx and mysql - name: Find /var/log all directories, exclude nginx and mysql
find: ansible.builtin.find:
paths: /var/log paths: /var/log
recurse: no recurse: no
file_type: directory file_type: directory
@ -186,14 +186,14 @@ EXAMPLES = r'''
# When using patterns that contain a comma, make sure they are formatted as lists to avoid splitting the pattern # When using patterns that contain a comma, make sure they are formatted as lists to avoid splitting the pattern
- name: Use a single pattern that contains a comma formatted as a list - name: Use a single pattern that contains a comma formatted as a list
find: ansible.builtin.find:
paths: /var/log paths: /var/log
file_type: file file_type: file
use_regex: yes use_regex: yes
patterns: ['^_[0-9]{2,4}_.*.log$'] patterns: ['^_[0-9]{2,4}_.*.log$']
- name: Use multiple patterns that contain a comma formatted as a YAML list - name: Use multiple patterns that contain a comma formatted as a YAML list
find: ansible.builtin.find:
paths: /var/log paths: /var/log
file_type: file file_type: file
use_regex: yes use_regex: yes

@ -60,5 +60,5 @@ RETURN = """
EXAMPLES = """ EXAMPLES = """
# Display facts from all hosts and store them indexed by hostname at /tmp/facts. # Display facts from all hosts and store them indexed by hostname at /tmp/facts.
# ansible all -m gather_facts --tree /tmp/facts # ansible all -m ansible.builtin.gather_facts --tree /tmp/facts
""" """

@ -206,19 +206,19 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
- name: Download foo.conf - name: Download foo.conf
get_url: ansible.builtin.get_url:
url: http://example.com/path/file.conf url: http://example.com/path/file.conf
dest: /etc/foo.conf dest: /etc/foo.conf
mode: '0440' mode: '0440'
- name: Download file and force basic auth - name: Download file and force basic auth
get_url: ansible.builtin.get_url:
url: http://example.com/path/file.conf url: http://example.com/path/file.conf
dest: /etc/foo.conf dest: /etc/foo.conf
force_basic_auth: yes force_basic_auth: yes
- name: Download file with custom HTTP headers - name: Download file with custom HTTP headers
get_url: ansible.builtin.get_url:
url: http://example.com/path/file.conf url: http://example.com/path/file.conf
dest: /etc/foo.conf dest: /etc/foo.conf
headers: headers:
@ -226,31 +226,31 @@ EXAMPLES = r'''
key2: two key2: two
- name: Download file with check (sha256) - name: Download file with check (sha256)
get_url: ansible.builtin.get_url:
url: http://example.com/path/file.conf url: http://example.com/path/file.conf
dest: /etc/foo.conf dest: /etc/foo.conf
checksum: sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c checksum: sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
- name: Download file with check (md5) - name: Download file with check (md5)
get_url: ansible.builtin.get_url:
url: http://example.com/path/file.conf url: http://example.com/path/file.conf
dest: /etc/foo.conf dest: /etc/foo.conf
checksum: md5:66dffb5228a211e61d6d7ef4a86f5758 checksum: md5:66dffb5228a211e61d6d7ef4a86f5758
- name: Download file with checksum url (sha256) - name: Download file with checksum url (sha256)
get_url: ansible.builtin.get_url:
url: http://example.com/path/file.conf url: http://example.com/path/file.conf
dest: /etc/foo.conf dest: /etc/foo.conf
checksum: sha256:http://example.com/path/sha256sum.txt checksum: sha256:http://example.com/path/sha256sum.txt
- name: Download file from a file path - name: Download file from a file path
get_url: ansible.builtin.get_url:
url: file:///tmp/afile.txt url: file:///tmp/afile.txt
dest: /tmp/afilecopy.txt dest: /tmp/afilecopy.txt
- name: < Fetch file that requires authentication. - name: < Fetch file that requires authentication.
username/password only available since 2.8, in older versions you need to use url_username/url_password username/password only available since 2.8, in older versions you need to use url_username/url_password
get_url: ansible.builtin.get_url:
url: http://example.com/path/file.conf url: http://example.com/path/file.conf
dest: /etc/foo.conf dest: /etc/foo.conf
username: bar username: bar

@ -63,39 +63,39 @@ author:
EXAMPLES = ''' EXAMPLES = '''
- name: Get root user info - name: Get root user info
getent: ansible.builtin.getent:
database: passwd database: passwd
key: root key: root
- debug: - ansible.builtin.debug:
var: ansible_facts.getent_passwd var: ansible_facts.getent_passwd
- name: Get all groups - name: Get all groups
getent: ansible.builtin.getent:
database: group database: group
split: ':' split: ':'
- debug: - ansible.builtin.debug:
var: ansible_facts.getent_group var: ansible_facts.getent_group
- name: Get all hosts, split by tab - name: Get all hosts, split by tab
getent: ansible.builtin.getent:
database: hosts database: hosts
- debug: - ansible.builtin.debug:
var: ansible_facts.getent_hosts var: ansible_facts.getent_hosts
- name: Get http service info, no error if missing - name: Get http service info, no error if missing
getent: ansible.builtin.getent:
database: services database: services
key: http key: http
fail_key: False fail_key: False
- debug: - ansible.builtin.debug:
var: ansible_facts.getent_services var: ansible_facts.getent_services
- name: Get user password hash (requires sudo/root) - name: Get user password hash (requires sudo/root)
getent: ansible.builtin.getent:
database: shadow database: shadow
key: www-data key: www-data
split: ':' split: ':'
- debug: - ansible.builtin.debug:
var: ansible_facts.getent_shadow var: ansible_facts.getent_shadow
''' '''

@ -48,25 +48,25 @@ seealso:
EXAMPLES = r''' EXAMPLES = r'''
- hosts: localhost - hosts: localhost
tasks: tasks:
- debug: - ansible.builtin.debug:
msg: play1 msg: play1
- name: Include a play after another play - name: Include a play after another play
import_playbook: otherplays.yaml ansible.builtin.import_playbook: otherplays.yaml
- name: Set variables on an imported playbook - name: Set variables on an imported playbook
import_playbook: otherplays.yml ansible.builtin.import_playbook: otherplays.yml
vars: vars:
service: httpd service: httpd
- name: This DOES NOT WORK - name: This DOES NOT WORK
hosts: all hosts: all
tasks: tasks:
- debug: - ansible.builtin.debug:
msg: task1 msg: task1
- name: This fails because I'm inside a play already - name: This fails because I'm inside a play already
import_playbook: stuff.yaml ansible.builtin.import_playbook: stuff.yaml
''' '''
RETURN = r''' RETURN = r'''

@ -85,22 +85,22 @@ seealso:
EXAMPLES = r''' EXAMPLES = r'''
- hosts: all - hosts: all
tasks: tasks:
- import_role: - ansible.builtin.import_role:
name: myrole name: myrole
- name: Run tasks/other.yaml instead of 'main' - name: Run tasks/other.yaml instead of 'main'
import_role: ansible.builtin.import_role:
name: myrole name: myrole
tasks_from: other tasks_from: other
- name: Pass variables to role - name: Pass variables to role
import_role: ansible.builtin.import_role:
name: myrole name: myrole
vars: vars:
rolevar1: value from task rolevar1: value from task
- name: Apply condition to each task in role - name: Apply condition to each task in role
import_role: ansible.builtin.import_role:
name: myrole name: myrole
when: not idontwanttorun when: not idontwanttorun
''' '''

@ -46,22 +46,22 @@ seealso:
EXAMPLES = r''' EXAMPLES = r'''
- hosts: all - hosts: all
tasks: tasks:
- debug: - ansible.builtin.debug:
msg: task1 msg: task1
- name: Include task list in play - name: Include task list in play
import_tasks: stuff.yaml ansible.builtin.import_tasks: stuff.yaml
- debug: - ansible.builtin.debug:
msg: task10 msg: task10
- hosts: all - hosts: all
tasks: tasks:
- debug: - ansible.builtin.debug:
msg: task1 msg: task1
- name: Apply conditional to all imported tasks - name: Apply conditional to all imported tasks
import_tasks: stuff.yaml ansible.builtin.import_tasks: stuff.yaml
when: hostvar is defined when: hostvar is defined
''' '''

@ -96,22 +96,22 @@ seealso:
''' '''
EXAMPLES = r''' EXAMPLES = r'''
- include_role: - ansible.builtin.include_role:
name: myrole name: myrole
- name: Run tasks/other.yaml instead of 'main' - name: Run tasks/other.yaml instead of 'main'
include_role: ansible.builtin.include_role:
name: myrole name: myrole
tasks_from: other tasks_from: other
- name: Pass variables to role - name: Pass variables to role
include_role: ansible.builtin.include_role:
name: myrole name: myrole
vars: vars:
rolevar1: value from task rolevar1: value from task
- name: Use role in loop - name: Use role in loop
include_role: ansible.builtin.include_role:
name: '{{ roleinputvar }}' name: '{{ roleinputvar }}'
loop: loop:
- '{{ roleinput1 }}' - '{{ roleinput1 }}'
@ -120,12 +120,12 @@ EXAMPLES = r'''
loop_var: roleinputvar loop_var: roleinputvar
- name: Conditional role - name: Conditional role
include_role: ansible.builtin.include_role:
name: myrole name: myrole
when: not idontwanttorun when: not idontwanttorun
- name: Apply tags to tasks within included file - name: Apply tags to tasks within included file
include_role: ansible.builtin.include_role:
name: install name: install
apply: apply:
tags: tags:

@ -56,26 +56,26 @@ seealso:
EXAMPLES = r''' EXAMPLES = r'''
- hosts: all - hosts: all
tasks: tasks:
- debug: - ansible.builtin.debug:
msg: task1 msg: task1
- name: Include task list in play - name: Include task list in play
include_tasks: stuff.yaml ansible.builtin.include_tasks: stuff.yaml
- debug: - ansible.builtin.debug:
msg: task10 msg: task10
- hosts: all - hosts: all
tasks: tasks:
- debug: - ansible.builtin.debug:
msg: task1 msg: task1
- name: Include task list in play only if the condition is true - name: Include task list in play only if the condition is true
include_tasks: "{{ hostvar }}.yaml" ansible.builtin.include_tasks: "{{ hostvar }}.yaml"
when: hostvar is defined when: hostvar is defined
- name: Apply tags to tasks within included file - name: Apply tags to tasks within included file
include_tasks: ansible.builtin.include_tasks:
file: install.yml file: install.yml
apply: apply:
tags: tags:
@ -84,7 +84,7 @@ EXAMPLES = r'''
- always - always
- name: Apply tags to tasks within included file when using free-form - name: Apply tags to tasks within included file when using free-form
include_tasks: install.yml ansible.builtin.include_tasks: install.yml
args: args:
apply: apply:
tags: tags:

@ -114,18 +114,18 @@ seealso:
EXAMPLES = r''' EXAMPLES = r'''
- name: Include vars of stuff.yaml into the 'stuff' variable (2.2). - name: Include vars of stuff.yaml into the 'stuff' variable (2.2).
include_vars: ansible.builtin.include_vars:
file: stuff.yaml file: stuff.yaml
name: stuff name: stuff
- name: Conditionally decide to load in variables into 'plans' when x is 0, otherwise do not. (2.2) - name: Conditionally decide to load in variables into 'plans' when x is 0, otherwise do not. (2.2)
include_vars: ansible.builtin.include_vars:
file: contingency_plan.yaml file: contingency_plan.yaml
name: plans name: plans
when: x == 0 when: x == 0
- name: Load a variable file based on the OS type, or a default if not found. Using free-form to specify the file. - name: Load a variable file based on the OS type, or a default if not found. Using free-form to specify the file.
include_vars: "{{ lookup('first_found', params) }}" ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', params) }}"
vars: vars:
params: params:
files: files:
@ -136,32 +136,32 @@ EXAMPLES = r'''
- 'vars' - 'vars'
- name: Bare include (free-form) - name: Bare include (free-form)
include_vars: myvars.yaml ansible.builtin.include_vars: myvars.yaml
- name: Include all .json and .jsn files in vars/all and all nested directories (2.3) - name: Include all .json and .jsn files in vars/all and all nested directories (2.3)
include_vars: ansible.builtin.include_vars:
dir: vars/all dir: vars/all
extensions: extensions:
- 'json' - 'json'
- 'jsn' - 'jsn'
- name: Include all default extension files in vars/all and all nested directories and save the output in test. (2.2) - name: Include all default extension files in vars/all and all nested directories and save the output in test. (2.2)
include_vars: ansible.builtin.include_vars:
dir: vars/all dir: vars/all
name: test name: test
- name: Include default extension files in vars/services (2.2) - name: Include default extension files in vars/services (2.2)
include_vars: ansible.builtin.include_vars:
dir: vars/services dir: vars/services
depth: 1 depth: 1
- name: Include only files matching bastion.yaml (2.2) - name: Include only files matching bastion.yaml (2.2)
include_vars: ansible.builtin.include_vars:
dir: vars dir: vars
files_matching: bastion.yaml files_matching: bastion.yaml
- name: Include all .yaml files except bastion.yaml (2.3) - name: Include all .yaml files except bastion.yaml (2.3)
include_vars: ansible.builtin.include_vars:
dir: vars dir: vars
ignore_files: ignore_files:
- 'bastion.yaml' - 'bastion.yaml'
@ -169,7 +169,7 @@ EXAMPLES = r'''
- 'yaml' - 'yaml'
- name: Ignore warnings raised for files with unknown extensions while loading (2.7) - name: Ignore warnings raised for files with unknown extensions while loading (2.7)
include_vars: ansible.builtin.include_vars:
dir: vars dir: vars
ignore_unknown_extensions: True ignore_unknown_extensions: True
extensions: extensions:

@ -70,20 +70,20 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
- name: Tell the host about our servers it might want to ssh to - name: Tell the host about our servers it might want to ssh to
known_hosts: ansible.builtin.known_hosts:
path: /etc/ssh/ssh_known_hosts path: /etc/ssh/ssh_known_hosts
name: foo.com.invalid name: foo.com.invalid
key: "{{ lookup('file', 'pubkeys/foo.com.invalid') }}" key: "{{ lookup('ansible.builtin.file', 'pubkeys/foo.com.invalid') }}"
- name: Another way to call known_hosts - name: Another way to call known_hosts
known_hosts: ansible.builtin.known_hosts:
name: host1.example.com # or 10.9.8.77 name: host1.example.com # or 10.9.8.77
key: host1.example.com,10.9.8.77 ssh-rsa ASDeararAIUHI324324 # some key gibberish key: host1.example.com,10.9.8.77 ssh-rsa ASDeararAIUHI324324 # some key gibberish
path: /etc/ssh/ssh_known_hosts path: /etc/ssh/ssh_known_hosts
state: present state: present
- name: Add host with custom SSH port - name: Add host with custom SSH port
known_hosts: ansible.builtin.known_hosts:
name: '[host1.example.com]:2222' name: '[host1.example.com]:2222'
key: '[host1.example.com]:2222 ssh-rsa ASDeararAIUHI324324' # some key gibberish key: '[host1.example.com]:2222 ssh-rsa ASDeararAIUHI324324' # some key gibberish
path: /etc/ssh/ssh_known_hosts path: /etc/ssh/ssh_known_hosts

@ -186,7 +186,7 @@ EXAMPLES = r'''
mode: '0644' mode: '0644'
- name: Replace a localhost entry searching for a literal string to avoid escaping - name: Replace a localhost entry searching for a literal string to avoid escaping
lineinfile: ansible.builtin.lineinfile:
path: /etc/hosts path: /etc/hosts
search_string: '127.0.0.1' search_string: '127.0.0.1'
line: 127.0.0.1 localhost line: 127.0.0.1 localhost
@ -202,7 +202,7 @@ EXAMPLES = r'''
line: Listen 8080 line: Listen 8080
- name: Ensure php extension matches new pattern - name: Ensure php extension matches new pattern
lineinfile: ansible.builtin.lineinfile:
path: /etc/httpd/conf/httpd.conf path: /etc/httpd/conf/httpd.conf
search_string: '<FilesMatch ".php[45]?$">' search_string: '<FilesMatch ".php[45]?$">'
insertafter: '^\t<Location \/>\n' insertafter: '^\t<Location \/>\n'

@ -76,13 +76,13 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
# Example showing flushing handlers on demand, not at end of play # Example showing flushing handlers on demand, not at end of play
- template: - ansible.builtin.template:
src: new.j2 src: new.j2
dest: /etc/config.txt dest: /etc/config.txt
notify: myhandler notify: myhandler
- name: Force all notified handlers to run at this point, not waiting for normal sync points - name: Force all notified handlers to run at this point, not waiting for normal sync points
meta: flush_handlers ansible.builtin.meta: flush_handlers
# Example showing how to refresh inventory during play # Example showing how to refresh inventory during play
- name: Reload inventory, useful with dynamic inventories when play makes changes to the existing hosts - name: Reload inventory, useful with dynamic inventories when play makes changes to the existing hosts
@ -91,32 +91,32 @@ EXAMPLES = r'''
state: present state: present
- name: Refresh inventory to ensure new instances exist in inventory - name: Refresh inventory to ensure new instances exist in inventory
meta: refresh_inventory ansible.builtin.meta: refresh_inventory
# Example showing how to clear all existing facts of targetted hosts # Example showing how to clear all existing facts of targetted hosts
- name: Clear gathered facts from all currently targeted hosts - name: Clear gathered facts from all currently targeted hosts
meta: clear_facts ansible.builtin.meta: clear_facts
# Example showing how to continue using a failed target # Example showing how to continue using a failed target
- name: Bring host back to play after failure - name: Bring host back to play after failure
copy: ansible.builtin.copy:
src: file src: file
dest: /etc/file dest: /etc/file
remote_user: imightnothavepermission remote_user: imightnothavepermission
- meta: clear_host_errors - ansible.builtin.meta: clear_host_errors
# Example showing how to reset an existing connection # Example showing how to reset an existing connection
- user: - ansible.builtin.user:
name: '{{ ansible_user }}' name: '{{ ansible_user }}'
groups: input groups: input
- name: Reset ssh connection to allow user changes to affect 'current login user' - name: Reset ssh connection to allow user changes to affect 'current login user'
meta: reset_connection ansible.builtin.meta: reset_connection
# Example showing how to end the play for specific targets # Example showing how to end the play for specific targets
- name: End the play for hosts that run CentOS 6 - name: End the play for hosts that run CentOS 6
meta: end_host ansible.builtin.meta: end_host
when: when:
- ansible_distribution == 'CentOS' - ansible_distribution == 'CentOS'
- ansible_distribution_major_version == '6' - ansible_distribution_major_version == '6'

@ -67,18 +67,18 @@ notes:
EXAMPLES = ''' EXAMPLES = '''
- name: Pause for 5 minutes to build app cache - name: Pause for 5 minutes to build app cache
pause: ansible.builtin.pause:
minutes: 5 minutes: 5
- name: Pause until you can verify updates to an application were successful - name: Pause until you can verify updates to an application were successful
pause: ansible.builtin.pause:
- name: A helpful reminder of what to look out for post-update - name: A helpful reminder of what to look out for post-update
pause: ansible.builtin.pause:
prompt: "Make sure org.foo.FooOverload exception is not present" prompt: "Make sure org.foo.FooOverload exception is not present"
- name: Pause to get some sensitive input - name: Pause to get some sensitive input
pause: ansible.builtin.pause:
prompt: "Enter a secret" prompt: "Enter a secret"
echo: no echo: no
''' '''

@ -46,7 +46,7 @@ author:
EXAMPLES = ''' EXAMPLES = '''
# Test we can logon to 'webservers' and execute python with json lib. # Test we can logon to 'webservers' and execute python with json lib.
# ansible webservers -m ping # ansible webservers -m ansible.builtin.ping
- name: Example from an Ansible Playbook - name: Example from an Ansible Playbook
ansible.builtin.ping: ansible.builtin.ping:

@ -141,26 +141,26 @@ author:
EXAMPLES = ''' EXAMPLES = '''
- name: Install bottle python package - name: Install bottle python package
pip: ansible.builtin.pip:
name: bottle name: bottle
- name: Install bottle python package on version 0.11 - name: Install bottle python package on version 0.11
pip: ansible.builtin.pip:
name: bottle==0.11 name: bottle==0.11
- name: Install bottle python package with version specifiers - name: Install bottle python package with version specifiers
pip: ansible.builtin.pip:
name: bottle>0.10,<0.20,!=0.11 name: bottle>0.10,<0.20,!=0.11
- name: Install multi python packages with version specifiers - name: Install multi python packages with version specifiers
pip: ansible.builtin.pip:
name: name:
- django>1.11.0,<1.12.0 - django>1.11.0,<1.12.0
- bottle>0.10,<0.20,!=0.11 - bottle>0.10,<0.20,!=0.11
- name: Install python package using a proxy - name: Install python package using a proxy
# Pip doesn't use the standard environment variables, please use the CAPITALIZED ones below # Pip doesn't use the standard environment variables, please use the CAPITALIZED ones below
pip: ansible.builtin.pip:
name: six name: six
environment: environment:
HTTP_PROXY: '127.0.0.1:8080' HTTP_PROXY: '127.0.0.1:8080'
@ -168,70 +168,70 @@ EXAMPLES = '''
# You do not have to supply '-e' option in extra_args # You do not have to supply '-e' option in extra_args
- name: Install MyApp using one of the remote protocols (bzr+,hg+,git+,svn+) - name: Install MyApp using one of the remote protocols (bzr+,hg+,git+,svn+)
pip: ansible.builtin.pip:
name: svn+http://myrepo/svn/MyApp#egg=MyApp name: svn+http://myrepo/svn/MyApp#egg=MyApp
- name: Install MyApp using one of the remote protocols (bzr+,hg+,git+) - name: Install MyApp using one of the remote protocols (bzr+,hg+,git+)
pip: ansible.builtin.pip:
name: git+http://myrepo/app/MyApp name: git+http://myrepo/app/MyApp
- name: Install MyApp from local tarball - name: Install MyApp from local tarball
pip: ansible.builtin.pip:
name: file:///path/to/MyApp.tar.gz name: file:///path/to/MyApp.tar.gz
- name: Install bottle into the specified (virtualenv), inheriting none of the globally installed modules - name: Install bottle into the specified (virtualenv), inheriting none of the globally installed modules
pip: ansible.builtin.pip:
name: bottle name: bottle
virtualenv: /my_app/venv virtualenv: /my_app/venv
- name: Install bottle into the specified (virtualenv), inheriting globally installed modules - name: Install bottle into the specified (virtualenv), inheriting globally installed modules
pip: ansible.builtin.pip:
name: bottle name: bottle
virtualenv: /my_app/venv virtualenv: /my_app/venv
virtualenv_site_packages: yes virtualenv_site_packages: yes
- name: Install bottle into the specified (virtualenv), using Python 2.7 - name: Install bottle into the specified (virtualenv), using Python 2.7
pip: ansible.builtin.pip:
name: bottle name: bottle
virtualenv: /my_app/venv virtualenv: /my_app/venv
virtualenv_command: virtualenv-2.7 virtualenv_command: virtualenv-2.7
- name: Install bottle within a user home directory - name: Install bottle within a user home directory
pip: ansible.builtin.pip:
name: bottle name: bottle
extra_args: --user extra_args: --user
- name: Install specified python requirements - name: Install specified python requirements
pip: ansible.builtin.pip:
requirements: /my_app/requirements.txt requirements: /my_app/requirements.txt
- name: Install specified python requirements in indicated (virtualenv) - name: Install specified python requirements in indicated (virtualenv)
pip: ansible.builtin.pip:
requirements: /my_app/requirements.txt requirements: /my_app/requirements.txt
virtualenv: /my_app/venv virtualenv: /my_app/venv
- name: Install specified python requirements and custom Index URL - name: Install specified python requirements and custom Index URL
pip: ansible.builtin.pip:
requirements: /my_app/requirements.txt requirements: /my_app/requirements.txt
extra_args: -i https://example.com/pypi/simple extra_args: -i https://example.com/pypi/simple
- name: Install specified python requirements offline from a local directory with downloaded packages - name: Install specified python requirements offline from a local directory with downloaded packages
pip: ansible.builtin.pip:
requirements: /my_app/requirements.txt requirements: /my_app/requirements.txt
extra_args: "--no-index --find-links=file:///my_downloaded_packages_dir" extra_args: "--no-index --find-links=file:///my_downloaded_packages_dir"
- name: Install bottle for Python 3.3 specifically, using the 'pip3.3' executable - name: Install bottle for Python 3.3 specifically, using the 'pip3.3' executable
pip: ansible.builtin.pip:
name: bottle name: bottle
executable: pip3.3 executable: pip3.3
- name: Install bottle, forcing reinstallation if it's already installed - name: Install bottle, forcing reinstallation if it's already installed
pip: ansible.builtin.pip:
name: bottle name: bottle
state: forcereinstall state: forcereinstall
- name: Install bottle while ensuring the umask is 0022 (to ensure other users can use it) - name: Install bottle while ensuring the umask is 0022 (to ensure other users can use it)
pip: ansible.builtin.pip:
name: bottle name: bottle
umask: "0022" umask: "0022"
become: True become: True

@ -73,16 +73,16 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
- name: Bootstrap a host without python2 installed - name: Bootstrap a host without python2 installed
raw: dnf install -y python2 python2-dnf libselinux-python ansible.builtin.raw: dnf install -y python2 python2-dnf libselinux-python
- name: Run a command that uses non-posix shell-isms (in this example /bin/sh doesn't handle redirection and wildcards together but bash does) - name: Run a command that uses non-posix shell-isms (in this example /bin/sh doesn't handle redirection and wildcards together but bash does)
raw: cat < /tmp/*txt ansible.builtin.raw: cat < /tmp/*txt
args: args:
executable: /bin/bash executable: /bin/bash
- name: Safely use templated variables. Always use quote filter to avoid injection issues. - name: Safely use templated variables. Always use quote filter to avoid injection issues.
raw: "{{ package_mgr|quote }} {{ pkg_flags|quote }} install {{ python|quote }}" ansible.builtin.raw: "{{ package_mgr|quote }} {{ pkg_flags|quote }} install {{ python|quote }}"
- name: List user accounts on a Windows system - name: List user accounts on a Windows system
raw: Get-WmiObject -Class Win32_UserAccount ansible.builtin.raw: Get-WmiObject -Class Win32_UserAccount
''' '''

@ -104,19 +104,19 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
- name: Unconditionally reboot the machine with all defaults - name: Unconditionally reboot the machine with all defaults
reboot: ansible.builtin.reboot:
- name: Reboot a slow machine that might have lots of updates to apply - name: Reboot a slow machine that might have lots of updates to apply
reboot: ansible.builtin.reboot:
reboot_timeout: 3600 reboot_timeout: 3600
- name: Reboot a machine with shutdown command in unusual place - name: Reboot a machine with shutdown command in unusual place
reboot: ansible.builtin.reboot:
search_paths: search_paths:
- '/lib/molly-guard' - '/lib/molly-guard'
- name: Reboot machine using a custom reboot command - name: Reboot machine using a custom reboot command
reboot: ansible.builtin.reboot:
reboot_command: launchctl reboot userspace reboot_command: launchctl reboot userspace
boot_time_command: uptime | cut -d ' ' -f 5 boot_time_command: uptime | cut -d ' ' -f 5

@ -82,22 +82,22 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
- name: Setting host facts using key=value pairs, this format can only create strings or booleans - name: Setting host facts using key=value pairs, this format can only create strings or booleans
set_fact: one_fact="something" other_fact="{{ local_var }}" ansible.builtin.set_fact: one_fact="something" other_fact="{{ local_var }}"
- name: Setting host facts using complex arguments - name: Setting host facts using complex arguments
set_fact: ansible.builtin.set_fact:
one_fact: something one_fact: something
other_fact: "{{ local_var * 2 }}" other_fact: "{{ local_var * 2 }}"
another_fact: "{{ some_registered_var.results | map(attribute='ansible_facts.some_fact') | list }}" another_fact: "{{ some_registered_var.results | map(attribute='ansible_facts.some_fact') | list }}"
- name: Setting facts so that they will be persisted in the fact cache - name: Setting facts so that they will be persisted in the fact cache
set_fact: ansible.builtin.set_fact:
one_fact: something one_fact: something
other_fact: "{{ local_var * 2 }}" other_fact: "{{ local_var * 2 }}"
cacheable: yes cacheable: yes
- name: Creating list and dictionary variables - name: Creating list and dictionary variables
set_fact: ansible.builtin.set_fact:
one_dict: one_dict:
something: here something: here
other: there other: there
@ -105,9 +105,16 @@ EXAMPLES = r'''
- a - a
- b - b
- c - c
# As of Ansible 1.8, Ansible will convert boolean strings ('true', 'false', 'yes', 'no')
# to proper boolean values when using the key=value syntax, however it is still
# recommended that booleans be set using the complex argument style:
- name: Setting booleans using complex argument style
ansible.builtin.set_fact:
one_fact: yes
other_fact: no
- name: Creating list and dictionary variables using 'shorthand' YAML - name: Creating list and dictionary variables using 'shorthand' YAML
set_fact: ansible.builtin.set_fact:
two_dict: {'something': here2, 'other': somewhere} two_dict: {'something': here2, 'other': somewhere}
two_list: [1,2,3] two_list: [1,2,3]
''' '''

@ -53,7 +53,7 @@ EXAMPLES = r'''
msg: "{{ mounts['content'] | b64decode }}" msg: "{{ mounts['content'] | b64decode }}"
# From the commandline, find the pid of the remote machine's sshd # From the commandline, find the pid of the remote machine's sshd
# $ ansible host -m slurp -a 'src=/var/run/sshd.pid' # $ ansible host -m ansible.builtin.slurp -a 'src=/var/run/sshd.pid'
# host | SUCCESS => { # host | SUCCESS => {
# "changed": false, # "changed": false,
# "content": "MjE3OQo=", # "content": "MjE3OQo=",

@ -82,13 +82,13 @@ requirements:
EXAMPLES = ''' EXAMPLES = '''
- name: Make sure apache2 is started - name: Make sure apache2 is started
sysvinit: ansible.builtin.sysvinit:
name: apache2 name: apache2
state: started state: started
enabled: yes enabled: yes
- name: Make sure apache2 is started on runlevels 3 and 5 - name: Make sure apache2 is started on runlevels 3 and 5
sysvinit: ansible.builtin.sysvinit:
name: apache2 name: apache2
state: started state: started
enabled: yes enabled: yes

@ -221,29 +221,29 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
- name: Check that you can connect (GET) to a page and it returns a status 200 - name: Check that you can connect (GET) to a page and it returns a status 200
uri: ansible.builtin.uri:
url: http://www.example.com url: http://www.example.com
- name: Check that a page returns a status 200 and fail if the word AWESOME is not in the page contents - name: Check that a page returns a status 200 and fail if the word AWESOME is not in the page contents
uri: ansible.builtin.uri:
url: http://www.example.com url: http://www.example.com
return_content: yes return_content: yes
register: this register: this
failed_when: "'AWESOME' not in this.content" failed_when: "'AWESOME' not in this.content"
- name: Create a JIRA issue - name: Create a JIRA issue
uri: ansible.builtin.uri:
url: https://your.jira.example.com/rest/api/2/issue/ url: https://your.jira.example.com/rest/api/2/issue/
user: your_username user: your_username
password: your_pass password: your_pass
method: POST method: POST
body: "{{ lookup('file','issue.json') }}" body: "{{ lookup('ansible.builtin.file','issue.json') }}"
force_basic_auth: yes force_basic_auth: yes
status_code: 201 status_code: 201
body_format: json body_format: json
- name: Login to a form based webpage, then use the returned cookie to access the app in later tasks - name: Login to a form based webpage, then use the returned cookie to access the app in later tasks
uri: ansible.builtin.uri:
url: https://your.form.based.auth.example.com/index.php url: https://your.form.based.auth.example.com/index.php
method: POST method: POST
body_format: form-urlencoded body_format: form-urlencoded
@ -255,7 +255,7 @@ EXAMPLES = r'''
register: login register: login
- name: Login to a form based webpage using a list of tuples - name: Login to a form based webpage using a list of tuples
uri: ansible.builtin.uri:
url: https://your.form.based.auth.example.com/index.php url: https://your.form.based.auth.example.com/index.php
method: POST method: POST
body_format: form-urlencoded body_format: form-urlencoded
@ -267,7 +267,7 @@ EXAMPLES = r'''
register: login register: login
- name: Upload a file via multipart/form-multipart - name: Upload a file via multipart/form-multipart
uri: ansible.builtin.uri:
url: https://httpbin.org/post url: https://httpbin.org/post
method: POST method: POST
body_format: form-multipart body_format: form-multipart
@ -282,7 +282,7 @@ EXAMPLES = r'''
text_form_field: value text_form_field: value
- name: Connect to website using a previously stored cookie - name: Connect to website using a previously stored cookie
uri: ansible.builtin.uri:
url: https://your.form.based.auth.example.com/dashboard.php url: https://your.form.based.auth.example.com/dashboard.php
method: GET method: GET
return_content: yes return_content: yes
@ -290,7 +290,7 @@ EXAMPLES = r'''
Cookie: "{{ login.cookies_string }}" Cookie: "{{ login.cookies_string }}"
- name: Queue build of a project in Jenkins - name: Queue build of a project in Jenkins
uri: ansible.builtin.uri:
url: http://{{ jenkins.host }}/job/{{ jenkins.job }}/build?token={{ jenkins.token }} url: http://{{ jenkins.host }}/job/{{ jenkins.job }}/build?token={{ jenkins.token }}
user: "{{ jenkins.user }}" user: "{{ jenkins.user }}"
password: "{{ jenkins.password }}" password: "{{ jenkins.password }}"
@ -299,20 +299,20 @@ EXAMPLES = r'''
status_code: 201 status_code: 201
- name: POST from contents of local file - name: POST from contents of local file
uri: ansible.builtin.uri:
url: https://httpbin.org/post url: https://httpbin.org/post
method: POST method: POST
src: file.json src: file.json
- name: POST from contents of remote file - name: POST from contents of remote file
uri: ansible.builtin.uri:
url: https://httpbin.org/post url: https://httpbin.org/post
method: POST method: POST
src: /path/to/my/file.json src: /path/to/my/file.json
remote_src: yes remote_src: yes
- name: Create workspaces in Log analytics Azure - name: Create workspaces in Log analytics Azure
uri: ansible.builtin.uri:
url: https://www.mms.microsoft.com/Embedded/Api/ConfigDataSources/LogManagementData/Save url: https://www.mms.microsoft.com/Embedded/Api/ConfigDataSources/LogManagementData/Save
method: POST method: POST
body_format: json body_format: json
@ -326,7 +326,7 @@ EXAMPLES = r'''
body: body:
- name: Pause play until a URL is reachable from this host - name: Pause play until a URL is reachable from this host
uri: ansible.builtin.uri:
url: "http://192.0.2.1/some/test" url: "http://192.0.2.1/some/test"
follow_redirects: none follow_redirects: none
method: GET method: GET
@ -339,7 +339,7 @@ EXAMPLES = r'''
# https://github.com/ansible/ansible/issues/52705 where a proxy is defined # https://github.com/ansible/ansible/issues/52705 where a proxy is defined
# but you want to bypass proxy use on CIDR masks by using no_proxy # but you want to bypass proxy use on CIDR masks by using no_proxy
- name: Work around a python issue that doesn't support no_proxy envvar - name: Work around a python issue that doesn't support no_proxy envvar
uri: ansible.builtin.uri:
follow_redirects: none follow_redirects: none
validate_certs: false validate_certs: false
timeout: 5 timeout: 5
@ -351,7 +351,7 @@ EXAMPLES = r'''
ip_address: 192.0.2.1 ip_address: 192.0.2.1
environment: | environment: |
{ {
{% for no_proxy in (lookup('env', 'no_proxy') | regex_replace('\s*,\s*', ' ') ).split() %} {% for no_proxy in (lookup('ansible.builtin.env', 'no_proxy') | regex_replace('\s*,\s*', ' ') ).split() %}
{% if no_proxy | regex_search('\/') and {% if no_proxy | regex_search('\/') and
no_proxy | ipaddr('net') != '' and no_proxy | ipaddr('net') != '' and
no_proxy | ipaddr('net') != false and no_proxy | ipaddr('net') != false and

@ -329,12 +329,12 @@ EXAMPLES = r'''
expires: -1 expires: -1
- name: Set maximum expiration date for password - name: Set maximum expiration date for password
user: ansible.builtin.user:
name: ram19 name: ram19
password_expire_max: 10 password_expire_max: 10
- name: Set minimum expiration date for password - name: Set minimum expiration date for password
user: ansible.builtin.user:
name: pushkar15 name: pushkar15
password_expire_min: 5 password_expire_min: 5
''' '''

@ -51,7 +51,7 @@ attributes:
EXAMPLES = r''' EXAMPLES = r'''
- name: verify vars needed for this task file are present when included - name: verify vars needed for this task file are present when included
validate_argument_spec: ansible.builtin.validate_argument_spec:
argument_spec: '{{required_data}}' argument_spec: '{{required_data}}'
vars: vars:
required_data: required_data:
@ -68,14 +68,14 @@ EXAMPLES = r'''
- name: verify vars needed for this task file are present when included, with spec from a spec file - name: verify vars needed for this task file are present when included, with spec from a spec file
validate_argument_spec: ansible.builtin.validate_argument_spec:
argument_spec: "{{lookup('file', 'myargspec.yml')['specname']['options']}}" argument_spec: "{{lookup('ansible.builtin.file', 'myargspec.yml')['specname']['options']}}"
- name: verify vars needed for next include and not from inside it, also with params i'll only define there - name: verify vars needed for next include and not from inside it, also with params i'll only define there
block: block:
- validate_argument_spec: - ansible.builtin.validate_argument_spec:
argument_spec: "{{lookup('file', 'nakedoptions.yml'}}" argument_spec: "{{lookup('ansible.builtin.file', 'nakedoptions.yml'}}"
provided_arguments: provided_arguments:
but: "that i can define on the include itself, like in it's C(vars:) keyword" but: "that i can define on the include itself, like in it's C(vars:) keyword"

@ -125,65 +125,65 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
- name: Sleep for 300 seconds and continue with play - name: Sleep for 300 seconds and continue with play
wait_for: ansible.builtin.wait_for:
timeout: 300 timeout: 300
delegate_to: localhost delegate_to: localhost
- name: Wait for port 8000 to become open on the host, don't start checking for 10 seconds - name: Wait for port 8000 to become open on the host, don't start checking for 10 seconds
wait_for: ansible.builtin.wait_for:
port: 8000 port: 8000
delay: 10 delay: 10
- name: Waits for port 8000 of any IP to close active connections, don't start checking for 10 seconds - name: Waits for port 8000 of any IP to close active connections, don't start checking for 10 seconds
wait_for: ansible.builtin.wait_for:
host: 0.0.0.0 host: 0.0.0.0
port: 8000 port: 8000
delay: 10 delay: 10
state: drained state: drained
- name: Wait for port 8000 of any IP to close active connections, ignoring connections for specified hosts - name: Wait for port 8000 of any IP to close active connections, ignoring connections for specified hosts
wait_for: ansible.builtin.wait_for:
host: 0.0.0.0 host: 0.0.0.0
port: 8000 port: 8000
state: drained state: drained
exclude_hosts: 10.2.1.2,10.2.1.3 exclude_hosts: 10.2.1.2,10.2.1.3
- name: Wait until the file /tmp/foo is present before continuing - name: Wait until the file /tmp/foo is present before continuing
wait_for: ansible.builtin.wait_for:
path: /tmp/foo path: /tmp/foo
- name: Wait until the string "completed" is in the file /tmp/foo before continuing - name: Wait until the string "completed" is in the file /tmp/foo before continuing
wait_for: ansible.builtin.wait_for:
path: /tmp/foo path: /tmp/foo
search_regex: completed search_regex: completed
- name: Wait until regex pattern matches in the file /tmp/foo and print the matched group - name: Wait until regex pattern matches in the file /tmp/foo and print the matched group
wait_for: ansible.builtin.wait_for:
path: /tmp/foo path: /tmp/foo
search_regex: completed (?P<task>\w+) search_regex: completed (?P<task>\w+)
register: waitfor register: waitfor
- debug: - ansible.builtin.debug:
msg: Completed {{ waitfor['match_groupdict']['task'] }} msg: Completed {{ waitfor['match_groupdict']['task'] }}
- name: Wait until the lock file is removed - name: Wait until the lock file is removed
wait_for: ansible.builtin.wait_for:
path: /var/lock/file.lock path: /var/lock/file.lock
state: absent state: absent
- name: Wait until the process is finished and pid was destroyed - name: Wait until the process is finished and pid was destroyed
wait_for: ansible.builtin.wait_for:
path: /proc/3466/status path: /proc/3466/status
state: absent state: absent
- name: Output customized message when failed - name: Output customized message when failed
wait_for: ansible.builtin.wait_for:
path: /tmp/foo path: /tmp/foo
state: present state: present
msg: Timeout to find file /tmp/foo msg: Timeout to find file /tmp/foo
# Do not assume the inventory_hostname is resolvable and delay 10 seconds at start # Do not assume the inventory_hostname is resolvable and delay 10 seconds at start
- name: Wait 300 seconds for port 22 to become open and contain "OpenSSH" - name: Wait 300 seconds for port 22 to become open and contain "OpenSSH"
wait_for: ansible.builtin.wait_for:
port: 22 port: 22
host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}' host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
search_regex: OpenSSH search_regex: OpenSSH
@ -192,7 +192,7 @@ EXAMPLES = r'''
# Same as above but you normally have ansible_connection set in inventory, which overrides 'connection' # Same as above but you normally have ansible_connection set in inventory, which overrides 'connection'
- name: Wait 300 seconds for port 22 to become open and contain "OpenSSH" - name: Wait 300 seconds for port 22 to become open and contain "OpenSSH"
wait_for: ansible.builtin.wait_for:
port: 22 port: 22
host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}' host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
search_regex: OpenSSH search_regex: OpenSSH

@ -66,10 +66,10 @@ author:
EXAMPLES = r''' EXAMPLES = r'''
- name: Wait 600 seconds for target connection to become reachable/usable - name: Wait 600 seconds for target connection to become reachable/usable
wait_for_connection: ansible.builtin.wait_for_connection:
- name: Wait 300 seconds, but only start checking after 60 seconds - name: Wait 300 seconds, but only start checking after 60 seconds
wait_for_connection: ansible.builtin.wait_for_connection:
delay: 60 delay: 60
timeout: 300 timeout: 300
@ -78,23 +78,23 @@ EXAMPLES = r'''
gather_facts: no gather_facts: no
tasks: tasks:
- name: Send magic Wake-On-Lan packet to turn on individual systems - name: Send magic Wake-On-Lan packet to turn on individual systems
wakeonlan: community.general.wakeonlan:
mac: '{{ mac }}' mac: '{{ mac }}'
broadcast: 192.168.0.255 broadcast: 192.168.0.255
delegate_to: localhost delegate_to: localhost
- name: Wait for system to become reachable - name: Wait for system to become reachable
wait_for_connection: ansible.builtin.wait_for_connection:
- name: Gather facts for first time - name: Gather facts for first time
setup: ansible.builtin.setup:
# Build a new VM, wait for it to become ready and continue playbook # Build a new VM, wait for it to become ready and continue playbook
- hosts: all - hosts: all
gather_facts: no gather_facts: no
tasks: tasks:
- name: Clone new VM, if missing - name: Clone new VM, if missing
vmware_guest: community.vmware.vmware_guest:
hostname: '{{ vcenter_ipaddress }}' hostname: '{{ vcenter_ipaddress }}'
name: '{{ inventory_hostname_short }}' name: '{{ inventory_hostname_short }}'
template: Windows 2012R2 template: Windows 2012R2
@ -105,11 +105,11 @@ EXAMPLES = r'''
delegate_to: localhost delegate_to: localhost
- name: Wait for system to become reachable over WinRM - name: Wait for system to become reachable over WinRM
wait_for_connection: ansible.builtin.wait_for_connection:
timeout: 900 timeout: 900
- name: Gather facts for first time - name: Gather facts for first time
setup: ansible.builtin.setup:
''' '''
RETURN = r''' RETURN = r'''

@ -303,17 +303,17 @@ author:
EXAMPLES = ''' EXAMPLES = '''
- name: Install the latest version of Apache - name: Install the latest version of Apache
yum: ansible.builtin.yum:
name: httpd name: httpd
state: latest state: latest
- name: Install Apache >= 2.4 - name: Install Apache >= 2.4
yum: ansible.builtin.yum:
name: httpd>=2.4 name: httpd>=2.4
state: present state: present
- name: Install a list of packages (suitable replacement for 2.11 loop deprecation warning) - name: Install a list of packages (suitable replacement for 2.11 loop deprecation warning)
yum: ansible.builtin.yum:
name: name:
- nginx - nginx
- postgresql - postgresql
@ -321,7 +321,7 @@ EXAMPLES = '''
state: present state: present
- name: Install a list of packages with a list variable - name: Install a list of packages with a list variable
yum: ansible.builtin.yum:
name: "{{ packages }}" name: "{{ packages }}"
vars: vars:
packages: packages:
@ -329,69 +329,69 @@ EXAMPLES = '''
- httpd-tools - httpd-tools
- name: Remove the Apache package - name: Remove the Apache package
yum: ansible.builtin.yum:
name: httpd name: httpd
state: absent state: absent
- name: Install the latest version of Apache from the testing repo - name: Install the latest version of Apache from the testing repo
yum: ansible.builtin.yum:
name: httpd name: httpd
enablerepo: testing enablerepo: testing
state: present state: present
- name: Install one specific version of Apache - name: Install one specific version of Apache
yum: ansible.builtin.yum:
name: httpd-2.2.29-1.4.amzn1 name: httpd-2.2.29-1.4.amzn1
state: present state: present
- name: Upgrade all packages - name: Upgrade all packages
yum: ansible.builtin.yum:
name: '*' name: '*'
state: latest state: latest
- name: Upgrade all packages, excluding kernel & foo related packages - name: Upgrade all packages, excluding kernel & foo related packages
yum: ansible.builtin.yum:
name: '*' name: '*'
state: latest state: latest
exclude: kernel*,foo* exclude: kernel*,foo*
- name: Install the nginx rpm from a remote repo - name: Install the nginx rpm from a remote repo
yum: ansible.builtin.yum:
name: http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm name: http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
state: present state: present
- name: Install nginx rpm from a local file - name: Install nginx rpm from a local file
yum: ansible.builtin.yum:
name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
state: present state: present
- name: Install the 'Development tools' package group - name: Install the 'Development tools' package group
yum: ansible.builtin.yum:
name: "@Development tools" name: "@Development tools"
state: present state: present
- name: Install the 'Gnome desktop' environment group - name: Install the 'Gnome desktop' environment group
yum: ansible.builtin.yum:
name: "@^gnome-desktop-environment" name: "@^gnome-desktop-environment"
state: present state: present
- name: List ansible packages and register result to print with debug later - name: List ansible packages and register result to print with debug later
yum: ansible.builtin.yum:
list: ansible list: ansible
register: result register: result
- name: Install package with multiple repos enabled - name: Install package with multiple repos enabled
yum: ansible.builtin.yum:
name: sos name: sos
enablerepo: "epel,ol7_latest" enablerepo: "epel,ol7_latest"
- name: Install package with multiple repos disabled - name: Install package with multiple repos disabled
yum: ansible.builtin.yum:
name: sos name: sos
disablerepo: "epel,ol7_latest" disablerepo: "epel,ol7_latest"
- name: Download the nginx package but do not install it - name: Download the nginx package but do not install it
yum: ansible.builtin.yum:
name: name:
- nginx - nginx
state: latest state: latest

@ -378,13 +378,13 @@ notes:
EXAMPLES = ''' EXAMPLES = '''
- name: Add repository - name: Add repository
yum_repository: ansible.builtin.yum_repository:
name: epel name: epel
description: EPEL YUM repo description: EPEL YUM repo
baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/ baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
- name: Add multiple repositories into the same file (1/2) - name: Add multiple repositories into the same file (1/2)
yum_repository: ansible.builtin.yum_repository:
name: epel name: epel
description: EPEL YUM repo description: EPEL YUM repo
file: external_repos file: external_repos
@ -392,7 +392,7 @@ EXAMPLES = '''
gpgcheck: no gpgcheck: no
- name: Add multiple repositories into the same file (2/2) - name: Add multiple repositories into the same file (2/2)
yum_repository: ansible.builtin.yum_repository:
name: rpmforge name: rpmforge
description: RPMforge YUM repo description: RPMforge YUM repo
file: external_repos file: external_repos
@ -402,19 +402,19 @@ EXAMPLES = '''
# Handler showing how to clean yum metadata cache # Handler showing how to clean yum metadata cache
- name: yum-clean-metadata - name: yum-clean-metadata
command: yum clean metadata ansible.builtin.command: yum clean metadata
args: args:
warn: no warn: no
# Example removing a repository and cleaning up metadata cache # Example removing a repository and cleaning up metadata cache
- name: Remove repository (and clean up left-over metadata) - name: Remove repository (and clean up left-over metadata)
yum_repository: ansible.builtin.yum_repository:
name: epel name: epel
state: absent state: absent
notify: yum-clean-metadata notify: yum-clean-metadata
- name: Remove repository from a specific repo file - name: Remove repository from a specific repo file
yum_repository: ansible.builtin.yum_repository:
name: epel name: epel
file: external_repos file: external_repos
state: absent state: absent

@ -37,31 +37,31 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: Show configured default become user - name: Show configured default become user
debug: msg="{{ lookup('config', 'DEFAULT_BECOME_USER')}}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.config', 'DEFAULT_BECOME_USER')}}"
- name: print out role paths - name: print out role paths
debug: ansible.builtin.debug:
msg: "These are the configured role paths: {{lookup('config', 'DEFAULT_ROLES_PATH')}}" msg: "These are the configured role paths: {{lookup('ansible.builtin.config', 'DEFAULT_ROLES_PATH')}}"
- name: find retry files, skip if missing that key - name: find retry files, skip if missing that key
find: ansible.builtin.find:
paths: "{{lookup('config', 'RETRY_FILES_SAVE_PATH')|default(playbook_dir, True)}}" paths: "{{lookup('ansible.builtin.config', 'RETRY_FILES_SAVE_PATH')|default(playbook_dir, True)}}"
patterns: "*.retry" patterns: "*.retry"
- name: see the colors - name: see the colors
debug: msg="{{item}}" ansible.builtin.debug: msg="{{item}}"
loop: "{{lookup('config', 'COLOR_OK', 'COLOR_CHANGED', 'COLOR_SKIP', wantlist=True)}}" loop: "{{lookup('ansible.builtin.config', 'COLOR_OK', 'COLOR_CHANGED', 'COLOR_SKIP', wantlist=True)}}"
- name: skip if bad value in var - name: skip if bad value in var
debug: msg="{{ lookup('config', config_in_var, on_missing='skip')}}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.config', config_in_var, on_missing='skip')}}"
var: var:
config_in_var: UNKNOWN config_in_var: UNKNOWN
- name: show remote user and port for ssh connection - name: show remote user and port for ssh connection
debug: msg={{q("config", "remote_user", "port", plugin_type="connection", plugin_name="ssh", on_missing='skip')}} ansible.builtin.debug: msg={{q("ansible.builtin.config", "remote_user", "port", plugin_type="connection", plugin_name="ssh", on_missing='skip')}}
- name: show remote_tmp setting for shell (sh) plugin - name: show remote_tmp setting for shell (sh) plugin
debug: msg={{q("config", "remote_tmp", plugin_type="shell", plugin_name="sh")}} ansible.builtin.debug: msg={{q("ansible.builtin.config", "remote_tmp", plugin_type="shell", plugin_name="sh")}}
""" """
RETURN = """ RETURN = """

@ -39,13 +39,13 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: Match 'Li' on the first column, return the second column (0 based index) - name: Match 'Li' on the first column, return the second column (0 based index)
debug: msg="The atomic number of Lithium is {{ lookup('csvfile', 'Li', file='elements.csv', delimiter=',') }}" 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)" - name: msg="Match 'Li' on the first column, but return the 3rd column (columns start counting after the match)"
debug: msg="The atomic mass of Lithium is {{ lookup('csvfile', 'Li', file='elements.csv', delimiter=',', col=2) }}" 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. - 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.
set_fact: ansible.builtin.set_fact:
loop_ip: "{{ csvline[0] }}" loop_ip: "{{ csvline[0] }}"
int_ip: "{{ csvline[1] }}" int_ip: "{{ csvline[1] }}"
int_mask: "{{ csvline[2] }}" int_mask: "{{ csvline[2] }}"
@ -54,7 +54,7 @@ EXAMPLES = """
neighbor_as: "{{ csvline[5] }}" neighbor_as: "{{ csvline[5] }}"
neigh_int_ip: "{{ csvline[6] }}" neigh_int_ip: "{{ csvline[6] }}"
vars: vars:
csvline = "{{ lookup('csvfile', bgp_neighbor_ip, file='bgp_neighbors.csv', delimiter=',') }}" csvline = "{{ lookup('ansible.builtin.csvfile', bgp_neighbor_ip, file='bgp_neighbors.csv', delimiter=',') }}"
delegate_to: localhost delegate_to: localhost
""" """

@ -30,19 +30,19 @@ vars:
tasks: tasks:
# with predefined vars # with predefined vars
- name: Print phone records - name: Print phone records
debug: ansible.builtin.debug:
msg: "User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})" msg: "User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
loop: "{{ lookup('dict', users) }}" loop: "{{ lookup('ansible.builtin.dict', users) }}"
# with inline dictionary # with inline dictionary
- name: show dictionary - name: show dictionary
debug: ansible.builtin.debug:
msg: "{{item.key}}: {{item.value}}" msg: "{{item.key}}: {{item.value}}"
with_dict: {a: 1, b: 2, c: 3} with_dict: {a: 1, b: 2, c: 3}
# Items from loop can be used in when: statements # Items from loop can be used in when: statements
- name: set_fact when alice in key - name: set_fact when alice in key
set_fact: ansible.builtin.set_fact:
alice_exists: true alice_exists: true
loop: "{{ lookup('dict', users) }}" loop: "{{ lookup('ansible.builtin.dict', users) }}"
when: "'alice' in item.key" when: "'alice' in item.key"
""" """

@ -28,25 +28,25 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: Basic usage - name: Basic usage
debug: ansible.builtin.debug:
msg: "{{ lookup('env', 'HOME') }} is the HOME environment variable." 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. - name: Before 2.13, how to set default value if the variable is not defined.
This cannot distinguish between USR undefined and USR=''. This cannot distinguish between USR undefined and USR=''.
debug: ansible.builtin.debug:
msg: "{{ lookup('env', 'USR')|default('nobody', True) }} is the user." 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='' - name: Example how to set default value if the variable is not defined, ignores USR=''
debug: ansible.builtin.debug:
msg: "{{ lookup('env', 'USR', default='nobody') }} is the user." msg: "{{ lookup('ansible.builtin.env', 'USR', default='nobody') }} is the user."
- name: Set default value to Undefined, if the variable is not defined - name: Set default value to Undefined, if the variable is not defined
debug: ansible.builtin.debug:
msg: "{{ lookup('env', 'USR', default=Undefined) }} is the user." msg: "{{ lookup('ansible.builtin.env', 'USR', default=Undefined) }} is the user."
- name: Set default value to undef(), if the variable is not defined - name: Set default value to undef(), if the variable is not defined
debug: ansible.builtin.debug:
msg: "{{ lookup('env', 'USR', default=undef()) }} is the user." msg: "{{ lookup('ansible.builtin.env', 'USR', default=undef()) }} is the user."
""" """
RETURN = """ RETURN = """

@ -31,10 +31,11 @@ DOCUMENTATION = """
""" """
EXAMPLES = """ EXAMPLES = """
- debug: msg="the value of foo.txt is {{lookup('file', '/etc/foo.txt') }}" - ansible.builtin.debug:
msg: "the value of foo.txt is {{lookup('ansible.builtin.file', '/etc/foo.txt') }}"
- name: display multiple file contents - name: display multiple file contents
debug: var=item ansible.builtin.debug: var=item
with_file: with_file:
- "/path/to/foo.txt" - "/path/to/foo.txt"
- "bar.txt" # will be looked in files/ dir relative to play or in role - "bar.txt" # will be looked in files/ dir relative to play or in role

@ -25,10 +25,10 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: Display paths of all .txt files in dir - name: Display paths of all .txt files in dir
debug: msg={{ lookup('fileglob', '/my/path/*.txt') }} ansible.builtin.debug: msg={{ lookup('ansible.builtin.fileglob', '/my/path/*.txt') }}
- name: Copy each file over that matches the given pattern - name: Copy each file over that matches the given pattern
copy: ansible.builtin.copy:
src: "{{ item }}" src: "{{ item }}"
dest: "/etc/fooapp/" dest: "/etc/fooapp/"
owner: "root" owner: "root"

@ -47,8 +47,8 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: Set _found_file to the first existing file, raising an error if a file is not found - name: Set _found_file to the first existing file, raising an error if a file is not found
set_fact: ansible.builtin.set_fact:
_found_file: "{{ lookup('first_found', findme) }}" _found_file: "{{ lookup('ansible.builtin.first_found', findme) }}"
vars: vars:
findme: findme:
- /path/to/foo.txt - /path/to/foo.txt
@ -56,15 +56,15 @@ EXAMPLES = """
- /path/to/biz.txt - /path/to/biz.txt
- name: Set _found_file to the first existing file, or an empty list if no files found - name: Set _found_file to the first existing file, or an empty list if no files found
set_fact: ansible.builtin.set_fact:
_found_file: "{{ lookup('first_found', files, paths=['/extra/path'], skip=True) }}" _found_file: "{{ lookup('ansible.builtin.first_found', files, paths=['/extra/path'], skip=True) }}"
vars: vars:
files: files:
- /path/to/foo.txt - /path/to/foo.txt
- /path/to/bar.txt - /path/to/bar.txt
- name: Include tasks only if one of the files exist, otherwise skip the task - name: Include tasks only if one of the files exist, otherwise skip the task
include_tasks: ansible.builtin.include_tasks:
file: "{{ item }}" file: "{{ item }}"
with_first_found: with_first_found:
files: files:
@ -73,17 +73,17 @@ EXAMPLES = """
skip: True skip: True
- name: Include tasks only if one of the files exists, otherwise skip - name: Include tasks only if one of the files exists, otherwise skip
include_tasks: '{{ tasks_file }}' ansible.builtin.include_tasks: '{{ tasks_file }}'
when: tasks_file != "" when: tasks_file != ""
vars: vars:
tasks_file: "{{ lookup('first_found', files=['tasks.yaml', 'other_tasks.yaml'], errors='ignore') }}" tasks_file: "{{ lookup('ansible.builtin.first_found', files=['tasks.yaml', 'other_tasks.yaml'], errors='ignore') }}"
- name: | - name: |
copy first existing file found to /some/file, copy first existing file found to /some/file,
looking in relative directories from where the task is defined and looking in relative directories from where the task is defined and
including any play objects that contain it including any play objects that contain it
copy: ansible.builtin.copy:
src: "{{ lookup('first_found', findme) }}" src: "{{ lookup('ansible.builtin.first_found', findme) }}"
dest: /some/file dest: /some/file
vars: vars:
findme: findme:
@ -92,8 +92,8 @@ EXAMPLES = """
- bar - bar
- name: same copy but specific paths - name: same copy but specific paths
copy: ansible.builtin.copy:
src: "{{ lookup('first_found', params) }}" src: "{{ lookup('ansible.builtin.first_found', params) }}"
dest: /some/file dest: /some/file
vars: vars:
params: params:
@ -106,8 +106,8 @@ EXAMPLES = """
- /tmp/staging - /tmp/staging
- name: INTERFACES | Create Ansible header for /etc/network/interfaces - name: INTERFACES | Create Ansible header for /etc/network/interfaces
template: ansible.builtin.template:
src: "{{ lookup('first_found', findme) }}" src: "{{ lookup('ansible.builtin.first_found', findme)}}"
dest: "/etc/foo.conf" dest: "/etc/foo.conf"
vars: vars:
findme: findme:
@ -115,7 +115,7 @@ EXAMPLES = """
- "default_foo.conf" - "default_foo.conf"
- name: read vars from first file found, use 'vars/' relative subdir - name: read vars from first file found, use 'vars/' relative subdir
include_vars: "{{ lookup('first_found', params) }}" ansible.builtin.include_vars: "{{lookup('ansible.builtin.first_found', params)}}"
vars: vars:
params: params:
files: files:

@ -20,7 +20,7 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: indexed loop demo - name: indexed loop demo
debug: ansible.builtin.debug:
msg: "at array position {{ item.0 }} there is a value {{ item.1 }}" msg: "at array position {{ item.0 }} there is a value {{ item.1 }}"
with_indexed_items: with_indexed_items:
- "{{ some_list }}" - "{{ some_list }}"

@ -53,19 +53,19 @@ DOCUMENTATION = """
""" """
EXAMPLES = """ EXAMPLES = """
- debug: msg="User in integration is {{ lookup('ini', 'user', section='integration', file='users.ini') }}" - ansible.builtin.debug: msg="User in integration is {{ lookup('ansible.builtin.ini', 'user', section='integration', file='users.ini') }}"
- debug: msg="User in production is {{ lookup('ini', 'user', section='production', file='users.ini') }}" - ansible.builtin.debug: msg="User in production is {{ lookup('ansible.builtin.ini', 'user', section='production', file='users.ini') }}"
- debug: msg="user.name is {{ lookup('ini', 'user.name', type='properties', file='user.properties') }}" - ansible.builtin.debug: msg="user.name is {{ lookup('ansible.builtin.ini', 'user.name', type='properties', file='user.properties') }}"
- debug: - ansible.builtin.debug:
msg: "{{ item }}" msg: "{{ item }}"
loop: "{{ q('ini', '.*', section='section1', file='test.ini', re=True) }}" loop: "{{ q('ansible.builtin.ini', '.*', section='section1', file='test.ini', re=True) }}"
- name: Read an ini file with allow_no_value - name: Read an ini file with allow_no_value
debug: ansible.builtin.debug:
msg: "{{ lookup('ini', 'user', file='mysql.ini', section='mysqld', allow_no_value=True) }}" msg: "{{ lookup('ansible.builtin.ini', 'user', file='mysql.ini', section='mysqld', allow_no_value=True) }}"
""" """
RETURN = """ RETURN = """

@ -22,7 +22,7 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: show all the hosts matching the pattern, i.e. all but the group www - name: show all the hosts matching the pattern, i.e. all but the group www
debug: ansible.builtin.debug:
msg: "{{ item }}" msg: "{{ item }}"
with_inventory_hostnames: with_inventory_hostnames:
- all:!www - all:!www

@ -23,7 +23,7 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: "loop through list" - name: "loop through list"
debug: ansible.builtin.debug:
msg: "An item: {{ item }}" msg: "An item: {{ item }}"
with_items: with_items:
- 1 - 1
@ -31,7 +31,7 @@ EXAMPLES = """
- 3 - 3
- name: add several users - name: add several users
user: ansible.builtin.user:
name: "{{ item }}" name: "{{ item }}"
groups: "wheel" groups: "wheel"
state: present state: present
@ -40,12 +40,12 @@ EXAMPLES = """
- testuser2 - testuser2
- name: "loop through list from a variable" - name: "loop through list from a variable"
debug: ansible.builtin.debug:
msg: "An item: {{ item }}" msg: "An item: {{ item }}"
with_items: "{{ somelist }}" with_items: "{{ somelist }}"
- name: more complex items to add several users - name: more complex items to add several users
user: ansible.builtin.user:
name: "{{ item.name }}" name: "{{ item.name }}"
uid: "{{ item.uid }}" uid: "{{ item.uid }}"
groups: "{{ item.groups }}" groups: "{{ item.groups }}"

@ -24,11 +24,11 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: We could read the file directly, but this shows output from command - name: We could read the file directly, but this shows output from command
debug: msg="{{ item }} is an output line from running cat on /etc/motd" ansible.builtin.debug: msg="{{ item }} is an output line from running cat on /etc/motd"
with_lines: cat /etc/motd with_lines: cat /etc/motd
- name: More useful example of looping over a command result - name: More useful example of looping over a command result
shell: "/usr/bin/frobnicate {{ item }}" ansible.builtin.shell: "/usr/bin/frobnicate {{ item }}"
with_lines: with_lines:
- "/usr/bin/frobnications_per_host --param {{ inventory_hostname }}" - "/usr/bin/frobnications_per_host --param {{ inventory_hostname }}"
""" """

@ -17,7 +17,7 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: unlike with_items you will get 3 items from this loop, the 2nd one being a list - name: unlike with_items you will get 3 items from this loop, the 2nd one being a list
debug: var=item ansible.builtin.debug: var=item
with_list: with_list:
- 1 - 1
- [2,3] - [2,3]

@ -19,7 +19,7 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: give users access to multiple databases - name: give users access to multiple databases
mysql_user: community.mysql.mysql_user:
name: "{{ item[0] }}" name: "{{ item[0] }}"
priv: "{{ item[1] }}.*:ALL" priv: "{{ item[1] }}.*:ALL"
append_privs: yes append_privs: yes
@ -30,7 +30,7 @@ EXAMPLES = """
# As with the case of 'with_items' above, you can use previously defined variables.: # As with the case of 'with_items' above, you can use previously defined variables.:
- name: here, 'users' contains the above list of employees - name: here, 'users' contains the above list of employees
mysql_user: community.mysql.mysql_user:
name: "{{ item[0] }}" name: "{{ item[0] }}"
priv: "{{ item[1] }}.*:ALL" priv: "{{ item[1] }}.*:ALL"
append_privs: yes append_privs: yes

@ -81,36 +81,36 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: create a mysql user with a random password - name: create a mysql user with a random password
mysql_user: community.mysql.mysql_user:
name: "{{ client }}" name: "{{ client }}"
password: "{{ lookup('password', 'credentials/' + client + '/' + tier + '/' + role + '/mysqlpassword length=15') }}" password: "{{ lookup('ansible.builtin.password', 'credentials/' + client + '/' + tier + '/' + role + '/mysqlpassword length=15') }}"
priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL" priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL"
- name: create a mysql user with a random password using only ascii letters - name: create a mysql user with a random password using only ascii letters
mysql_user: community.mysql.mysql_user:
name: "{{ client }}" name: "{{ client }}"
password: "{{ lookup('password', '/tmp/passwordfile chars=ascii_letters') }}" password: "{{ lookup('ansible.builtin.password', '/tmp/passwordfile chars=ascii_letters') }}"
priv: '{{ client }}_{{ tier }}_{{ role }}.*:ALL' priv: '{{ client }}_{{ tier }}_{{ role }}.*:ALL'
- name: create a mysql user with an 8 character random password using only digits - name: create a mysql user with an 8 character random password using only digits
mysql_user: community.mysql.mysql_user:
name: "{{ client }}" name: "{{ client }}"
password: "{{ lookup('password', '/tmp/passwordfile length=8 chars=digits') }}" password: "{{ lookup('ansible.builtin.password', '/tmp/passwordfile length=8 chars=digits') }}"
priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL" priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL"
- name: create a mysql user with a random password using many different char sets - name: create a mysql user with a random password using many different char sets
mysql_user: community.mysql.mysql_user:
name: "{{ client }}" name: "{{ client }}"
password: "{{ lookup('password', '/tmp/passwordfile chars=ascii_letters,digits,punctuation') }}" password: "{{ lookup('ansible.builtin.password', '/tmp/passwordfile chars=ascii_letters,digits,punctuation') }}"
priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL" priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL"
- name: create lowercase 8 character name for Kubernetes pod name - name: create lowercase 8 character name for Kubernetes pod name
set_fact: ansible.builtin.set_fact:
random_pod_name: "web-{{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=8') }}" random_pod_name: "web-{{ lookup('ansible.builtin.password', '/dev/null chars=ascii_lowercase,digits length=8') }}"
- name: create random but idempotent password - name: create random but idempotent password
set_fact: ansible.builtin.set_fact:
password: "{{ lookup('password', '/dev/null', seed=inventory_hostname) }}" password: "{{ lookup('ansible.builtin.password', '/dev/null', seed=inventory_hostname) }}"
""" """
RETURN = """ RETURN = """

@ -28,12 +28,12 @@ DOCUMENTATION = r"""
EXAMPLES = r""" EXAMPLES = r"""
- name: raw result of running date command" - name: raw result of running date command"
debug: ansible.builtin.debug:
msg: "{{ lookup('pipe', 'date') }}" msg: "{{ lookup('ansible.builtin.pipe', 'date') }}"
- name: Always use quote filter to make sure your variables are safe to use with shell - name: Always use quote filter to make sure your variables are safe to use with shell
debug: ansible.builtin.debug:
msg: "{{ lookup('pipe', 'getent passwd ' + myuser | quote ) }}" msg: "{{ lookup('ansible.builtin.pipe', 'getent passwd ' + myuser | quote ) }}"
""" """
RETURN = r""" RETURN = r"""

@ -17,7 +17,7 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: Magic 8 ball for MUDs - name: Magic 8 ball for MUDs
debug: ansible.builtin.debug:
msg: "{{ item }}" msg: "{{ item }}"
with_random_choice: with_random_choice:
- "go through the door" - "go through the door"

@ -39,31 +39,31 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: create some test users - name: create some test users
user: ansible.builtin.user:
name: "{{ item }}" name: "{{ item }}"
state: present state: present
groups: "evens" groups: "evens"
with_sequence: start=0 end=32 format=testuser%02x with_sequence: start=0 end=32 format=testuser%02x
- name: create a series of directories with even numbers for some reason - name: create a series of directories with even numbers for some reason
file: ansible.builtin.file:
dest: "/var/stuff/{{ item }}" dest: "/var/stuff/{{ item }}"
state: directory state: directory
with_sequence: start=4 end=16 stride=2 with_sequence: start=4 end=16 stride=2
- name: a simpler way to use the sequence plugin create 4 groups - name: a simpler way to use the sequence plugin create 4 groups
group: ansible.builtin.group:
name: "group{{ item }}" name: "group{{ item }}"
state: present state: present
with_sequence: count=4 with_sequence: count=4
- name: the final countdown - name: the final countdown
debug: ansible.builtin.debug:
msg: "{{item}} seconds to detonation" msg: "{{item}} seconds to detonation"
with_sequence: start=10 end=0 stride=-1 with_sequence: start=10 end=0 stride=-1
- name: Use of variable - name: Use of variable
debug: ansible.builtin.debug:
msg: "{{ item }}" msg: "{{ item }}"
with_sequence: start=1 end="{{ end_at }}" with_sequence: start=1 end="{{ end_at }}"
vars: vars:

@ -56,7 +56,7 @@ EXAMPLES = """
- "DB2.*:ALL" - "DB2.*:ALL"
tasks: tasks:
- name: Set authorized ssh key, extracting just that data from 'users' - name: Set authorized ssh key, extracting just that data from 'users'
authorized_key: ansible.posix.authorized_key:
user: "{{ item.0.name }}" user: "{{ item.0.name }}"
key: "{{ lookup('file', item.1) }}" key: "{{ lookup('file', item.1) }}"
with_subelements: with_subelements:
@ -64,7 +64,7 @@ EXAMPLES = """
- authorized - authorized
- name: Setup MySQL users, given the mysql hosts and privs subkey lists - name: Setup MySQL users, given the mysql hosts and privs subkey lists
mysql_user: community.mysql.mysql_user:
name: "{{ item.0.name }}" name: "{{ item.0.name }}"
password: "{{ item.0.mysql.password }}" password: "{{ item.0.mysql.password }}"
host: "{{ item.1 }}" host: "{{ item.1 }}"
@ -74,8 +74,8 @@ EXAMPLES = """
- mysql.hosts - mysql.hosts
- name: list groups for users that have them, don't error if groups key is missing - name: list groups for users that have them, don't error if groups key is missing
debug: var=item ansible.builtin.debug: var=item
loop: "{{ q('subelements', users, 'groups', {'skip_missing': True}) }}" loop: "{{ q('ansible.builtin.subelements', users, 'groups', {'skip_missing': True}) }}"
""" """
RETURN = """ RETURN = """

@ -57,16 +57,16 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: show templating results - name: show templating results
debug: ansible.builtin.debug:
msg: "{{ lookup('template', './some_template.j2') }}" msg: "{{ lookup('ansible.builtin.template', './some_template.j2') }}"
- name: show templating results with different variable start and end string - name: show templating results with different variable start and end string
debug: ansible.builtin.debug:
msg: "{{ lookup('template', './some_template.j2', variable_start_string='[%', variable_end_string='%]') }}" 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 - name: show templating results with different comment start and end string
debug: ansible.builtin.debug:
msg: "{{ lookup('template', './some_template.j2', comment_start_string='[#', comment_end_string='#]') }}" msg: "{{ lookup('ansible.builtin.template', './some_template.j2', comment_start_string='[#', comment_end_string='#]') }}"
""" """
RETURN = """ RETURN = """

@ -22,7 +22,7 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: item.0 returns from the 'a' list, item.1 returns from the '1' list - name: item.0 returns from the 'a' list, item.1 returns from the '1' list
debug: ansible.builtin.debug:
msg: "{{ item.0 }} and {{ item.1 }}" msg: "{{ item.0 }} and {{ item.1 }}"
with_together: with_together:
- ['a', 'b', 'c', 'd'] - ['a', 'b', 'c', 'd']

@ -19,7 +19,7 @@ DOCUMENTATION = """
""" """
EXAMPLES = """ EXAMPLES = """
- debug: msg="the value of foo.txt is {{lookup('unvault', '/etc/foo.txt')|to_string }}" - ansible.builtin.debug: msg="the value of foo.txt is {{lookup('ansible.builtin.unvault', '/etc/foo.txt')|to_string }}"
""" """
RETURN = """ RETURN = """

@ -150,20 +150,22 @@ options:
EXAMPLES = """ EXAMPLES = """
- name: url lookup splits lines by default - name: url lookup splits lines by default
debug: msg="{{item}}" ansible.builtin.debug: msg="{{item}}"
loop: "{{ lookup('url', 'https://github.com/gremlin.keys', wantlist=True) }}" loop: "{{ lookup('ansible.builtin.url', 'https://github.com/gremlin.keys', wantlist=True) }}"
- name: display ip ranges - name: display ip ranges
debug: msg="{{ lookup('url', 'https://ip-ranges.amazonaws.com/ip-ranges.json', split_lines=False) }}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.url', 'https://ip-ranges.amazonaws.com/ip-ranges.json', split_lines=False) }}"
- name: url lookup using authentication - name: url lookup using authentication
debug: msg="{{ lookup('url', 'https://some.private.site.com/file.txt', username='bob', password='hunter2') }}" 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 - name: url lookup using basic authentication
debug: msg="{{ lookup('url', 'https://some.private.site.com/file.txt', username='bob', password='hunter2', force_basic_auth='True') }}" 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 - name: url lookup using headers
debug: msg="{{ lookup('url', 'https://some.private.site.com/api/service', headers={'header1':'value1', 'header2':'value2'} ) }}" ansible.builtin.debug:
msg: "{{ lookup('ansible.builtin.url', 'https://some.private.site.com/api/service', headers={'header1':'value1', 'header2':'value2'} ) }}"
""" """
RETURN = """ RETURN = """

@ -18,7 +18,7 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: List variables that start with qz_ - name: List variables that start with qz_
debug: msg="{{ lookup('varnames', '^qz_.+')}}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.varnames', '^qz_.+')}}"
vars: vars:
qz_1: hello qz_1: hello
qz_2: world qz_2: world
@ -26,13 +26,13 @@ EXAMPLES = """
qz_: "I won't show either" qz_: "I won't show either"
- name: Show all variables - name: Show all variables
debug: msg="{{ lookup('varnames', '.+')}}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.varnames', '.+')}}"
- name: Show variables with 'hosts' in their names - name: Show variables with 'hosts' in their names
debug: msg="{{ lookup('varnames', 'hosts')}}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.varnames', 'hosts')}}"
- name: Find several related variables that end specific way - name: Find several related variables that end specific way
debug: msg="{{ lookup('varnames', '.+_zone$', '.+_location$') }}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.varnames', '.+_zone$', '.+_location$') }}"
""" """

@ -22,29 +22,29 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: Show value of 'variablename' - name: Show value of 'variablename'
debug: msg="{{ lookup('vars', 'variabl' + myvar) }}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'variabl' + myvar) }}"
vars: vars:
variablename: hello variablename: hello
myvar: ename myvar: ename
- name: Show default empty since i dont have 'variablnotename' - name: Show default empty since i dont have 'variablnotename'
debug: msg="{{ lookup('vars', 'variabl' + myvar, default='')}}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'variabl' + myvar, default='')}}"
vars: vars:
variablename: hello variablename: hello
myvar: notename myvar: notename
- name: Produce an error since i dont have 'variablnotename' - name: Produce an error since i dont have 'variablnotename'
debug: msg="{{ lookup('vars', 'variabl' + myvar)}}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'variabl' + myvar)}}"
ignore_errors: True ignore_errors: True
vars: vars:
variablename: hello variablename: hello
myvar: notename myvar: notename
- name: find several related variables - name: find several related variables
debug: msg="{{ lookup('vars', 'ansible_play_hosts', 'ansible_play_batch', 'ansible_play_hosts_all') }}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'ansible_play_hosts', 'ansible_play_batch', 'ansible_play_hosts_all') }}"
- name: Access nested variables - name: Access nested variables
debug: msg="{{ lookup('vars', 'variabl' + myvar).sub_var }}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'variabl' + myvar).sub_var }}"
ignore_errors: True ignore_errors: True
vars: vars:
variablename: variablename:
@ -52,7 +52,7 @@ EXAMPLES = """
myvar: ename myvar: ename
- name: alternate way to find some 'prefixed vars' in loop - name: alternate way to find some 'prefixed vars' in loop
debug: msg="{{ lookup('vars', 'ansible_play_' + item) }}" ansible.builtin.debug: msg="{{ lookup('ansible.builtin.vars', 'ansible_play_' + item) }}"
loop: loop:
- hosts - hosts
- batch - batch

Loading…
Cancel
Save