Fix example format in Ansible modules (#69509)

* Fix example format in several Ansible modules
* Update lib/ansible/modules/fail.py
* Update lib/ansible/modules/pip.py

Co-authored-by: Felix Fontein <felix@fontein.de>
pull/69751/head
Andrew Klychkov 4 years ago committed by GitHub
parent d0a25f004c
commit 323d2adfcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -236,7 +236,7 @@ EXAMPLES = '''
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: apt:
deb: https://example.com/python-ppq_0.1-1_all.deb deb: https://example.com/python-ppq_0.1-1_all.deb

@ -82,34 +82,33 @@ requirements:
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Add specified repository into sources list. - name: Add specified repository into sources list
- apt_repository: apt_repository:
repo: deb http://archive.canonical.com/ubuntu hardy partner repo: deb http://archive.canonical.com/ubuntu hardy partner
state: present state: present
# Add specified repository into sources list using specified filename. - name: Add specified repository into sources list using specified filename
- apt_repository: apt_repository:
repo: deb http://dl.google.com/linux/chrome/deb/ stable main repo: deb http://dl.google.com/linux/chrome/deb/ stable main
state: present state: present
filename: google-chrome filename: google-chrome
# Add source repository into sources list. - name: Add source repository into sources list
- apt_repository: apt_repository:
repo: deb-src http://archive.canonical.com/ubuntu hardy partner repo: deb-src http://archive.canonical.com/ubuntu hardy partner
state: present state: present
# Remove specified repository from sources list. - name: Remove specified repository from sources list
- apt_repository: apt_repository:
repo: deb http://archive.canonical.com/ubuntu hardy partner repo: deb http://archive.canonical.com/ubuntu hardy partner
state: absent state: absent
# Add nginx stable repository from PPA and install its signing key. - name: Add nginx stable repository from PPA and install its signing key on Ubuntu target
# On Ubuntu target: apt_repository:
- apt_repository:
repo: ppa:nginx/stable repo: ppa:nginx/stable
# On Debian target - name: Add nginx stable repository from PPA and install its signing key on Debian target
- apt_repository: apt_repository:
repo: 'ppa:nginx/stable' repo: 'ppa:nginx/stable'
codename: trusty codename: trusty
''' '''

@ -77,7 +77,7 @@ EXAMPLES = r'''
- 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: assert:
that: that:
- my_param <= 100 - my_param <= 100

@ -104,28 +104,28 @@ author:
''' '''
EXAMPLES = r''' EXAMPLES = r'''
- name: return motd to registered var - name: Return motd to registered var
command: cat /etc/motd command: cat /etc/motd
register: mymotd register: mymotd
# free-form (string) arguments, all arguments on one line # free-form (string) arguments, all arguments on one line
- name: Run command if /path/to/database does not exist (without 'args'). - name: Run command if /path/to/database does not exist (without 'args')
command: /usr/bin/make_database.sh db_user db_name creates=/path/to/database command: /usr/bin/make_database.sh db_user db_name creates=/path/to/database
# free-form (string) arguments, some arguments on separate lines with the 'args' keyword # free-form (string) arguments, some arguments on separate lines with the 'args' keyword
# 'args' is a task keyword, passed at the same level as the module # 'args' is a task keyword, passed at the same level as the module
- name: Run command if /path/to/database does not exist (with 'args' keyword). - name: Run command if /path/to/database does not exist (with 'args' keyword)
command: /usr/bin/make_database.sh db_user db_name command: /usr/bin/make_database.sh db_user db_name
args: args:
creates: /path/to/database creates: /path/to/database
# 'cmd' is module parameter # 'cmd' is module parameter
- name: Run command if /path/to/database does not exist (with 'cmd' parameter). - name: Run command if /path/to/database does not exist (with 'cmd' parameter)
command: command:
cmd: /usr/bin/make_database.sh db_user db_name cmd: /usr/bin/make_database.sh db_user db_name
creates: /path/to/database creates: /path/to/database
- name: Change the working directory to somedir/ and run the command as db_owner if /path/to/database does not exist. - name: Change the working directory to somedir/ and run the command as db_owner if /path/to/database does not exist
command: /usr/bin/make_database.sh db_user db_name command: /usr/bin/make_database.sh db_user db_name
become: yes become: yes
become_user: db_owner become_user: db_owner
@ -143,7 +143,7 @@ EXAMPLES = r'''
- dbname with whitespace - dbname with whitespace
creates: /path/to/database creates: /path/to/database
- name: safely use templated variable to run command. Always use the quote filter to avoid injection issues. - name: Safely use templated variable to run command. Always use the quote filter to avoid injection issues
command: cat {{ myfile|quote }} command: cat {{ myfile|quote }}
register: myoutput register: myoutput
''' '''

@ -68,7 +68,7 @@ EXAMPLES = r'''
value: fr_FR.UTF-8 value: fr_FR.UTF-8
vtype: select vtype: select
- name: set to generate locales - name: Set to generate locales
debconf: debconf:
name: locales name: locales
question: locales/locales_to_be_generated question: locales/locales_to_be_generated

@ -221,45 +221,45 @@ author:
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: install the latest version of Apache - name: Install the latest version of Apache
dnf: dnf:
name: httpd name: httpd
state: latest state: latest
- name: install the latest version of Apache and MariaDB - name: Install the latest version of Apache and MariaDB
dnf: dnf:
name: name:
- httpd - httpd
- mariadb-server - mariadb-server
state: latest state: latest
- name: remove the Apache package - name: Remove the Apache package
dnf: 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: dnf:
name: httpd name: httpd
enablerepo: testing enablerepo: testing
state: present state: present
- name: upgrade all packages - name: Upgrade all packages
dnf: 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: 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: 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 the 'Development tools' package group - name: Install the 'Development tools' package group
dnf: dnf:
name: '@Development tools' name: '@Development tools'
state: present state: present
@ -274,17 +274,17 @@ EXAMPLES = '''
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: 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: 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: dnf:
name: '@postgresql/client' name: '@postgresql/client'
state: present state: present

@ -36,8 +36,8 @@ notes:
- This module won't cause any packages to be installed/removed/purged, use the C(apt) module for that. - This module won't cause any packages to be installed/removed/purged, use the C(apt) module for that.
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Prevent python from being upgraded. - name: Prevent python from being upgraded
- dpkg_selections: dpkg_selections:
name: python name: python
selection: hold selection: hold
''' '''

@ -38,8 +38,8 @@ author:
''' '''
EXAMPLES = r''' EXAMPLES = r'''
# Example playbook using fail and when together - name: Example using fail and when together
- fail: 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"
''' '''

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

@ -196,45 +196,44 @@ notes:
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Example git checkout from Ansible Playbooks - name: Git checkout
- git: git:
repo: 'https://foosball.example.org/path/to/repo.git' repo: 'https://foosball.example.org/path/to/repo.git'
dest: /srv/checkout dest: /srv/checkout
version: release-0.22 version: release-0.22
# Example read-write git checkout from github - name: Read-write git checkout from github
- git: git:
repo: git@github.com:mylogin/hello.git repo: git@github.com:mylogin/hello.git
dest: /home/mylogin/hello dest: /home/mylogin/hello
# Example just ensuring the repo checkout exists - name: Just ensuring the repo checkout exists
- git: git:
repo: 'https://foosball.example.org/path/to/repo.git' repo: 'https://foosball.example.org/path/to/repo.git'
dest: /srv/checkout dest: /srv/checkout
update: no update: no
# Example just get information about the repository whether or not it has - name: Just get information about the repository whether or not it has already been cloned locally
# already been cloned locally. git:
- git:
repo: 'https://foosball.example.org/path/to/repo.git' repo: 'https://foosball.example.org/path/to/repo.git'
dest: /srv/checkout dest: /srv/checkout
clone: no clone: no
update: no update: no
# Example checkout a github repo and use refspec to fetch all pull requests - name: Checkout a github repo and use refspec to fetch all pull requests
- git: git:
repo: https://github.com/ansible/ansible-examples.git repo: https://github.com/ansible/ansible-examples.git
dest: /src/ansible-examples dest: /src/ansible-examples
refspec: '+refs/pull/*:refs/heads/*' refspec: '+refs/pull/*:refs/heads/*'
# Example Create git archive from repo - name: Create git archive from repo
- git: git:
repo: https://github.com/ansible/ansible-examples.git repo: https://github.com/ansible/ansible-examples.git
dest: /src/ansible-examples dest: /src/ansible-examples
archive: /tmp/ansible-examples.zip archive: /tmp/ansible-examples.zip
# Example clone a repo with separate git directory - name: Clone a repo with separate git directory
- git: git:
repo: https://github.com/ansible/ansible-examples.git repo: https://github.com/ansible/ansible-examples.git
dest: /src/ansible-examples dest: /src/ansible-examples
separate_git_dir: /src/ansible-examples.git separate_git_dir: /src/ansible-examples.git

@ -41,16 +41,16 @@ author:
''' '''
EXAMPLES = r''' EXAMPLES = r'''
# Create groups based on the machine architecture - name: Create groups based on the machine architecture
- group_by: group_by:
key: machine_{{ ansible_machine }} key: machine_{{ ansible_machine }}
# Create groups like 'virt_kvm_host' - name: Create groups like 'virt_kvm_host'
- group_by: group_by:
key: virt_{{ ansible_virtualization_type }}_{{ ansible_virtualization_role }} key: virt_{{ ansible_virtualization_type }}_{{ ansible_virtualization_role }}
# Create nested groups - name: Create nested groups
- group_by: group_by:
key: el{{ ansible_distribution_major_version }}-{{ ansible_architecture }} key: el{{ ansible_distribution_major_version }}-{{ ansible_architecture }}
parents: parents:
- el{{ ansible_distribution_major_version }} - el{{ ansible_distribution_major_version }}

@ -38,7 +38,8 @@ options:
''' '''
EXAMPLES = ''' EXAMPLES = '''
- hostname: - name: Set a hostname
hostname:
name: web01 name: web01
''' '''

@ -371,7 +371,7 @@ EXAMPLES = r'''
jump: ACCEPT jump: ACCEPT
become: yes become: yes
- name: Allow new incoming SYN packets on TCP port 22 (SSH). - name: Allow new incoming SYN packets on TCP port 22 (SSH)
iptables: iptables:
chain: INPUT chain: INPUT
protocol: tcp protocol: tcp
@ -438,13 +438,13 @@ EXAMPLES = r'''
- SYN - SYN
- FIN - FIN
- name: iptables flush filter - name: Iptables flush filter
iptables: iptables:
chain: "{{ item }}" chain: "{{ item }}"
flush: yes flush: yes
with_items: [ 'INPUT', 'FORWARD', 'OUTPUT' ] with_items: [ 'INPUT', 'FORWARD', 'OUTPUT' ]
- name: iptables flush nat - name: Iptables flush nat
iptables: iptables:
table: nat table: nat
chain: '{{ item }}' chain: '{{ item }}'

@ -59,7 +59,7 @@ author: "Matthew Vernon (@mcv21)"
''' '''
EXAMPLES = ''' EXAMPLES = '''
- 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: known_hosts:
path: /etc/ssh/ssh_known_hosts path: /etc/ssh/ssh_known_hosts
name: foo.com.invalid name: foo.com.invalid

@ -49,18 +49,18 @@ notes:
- For Windows targets, use the M(win_package) module instead. - For Windows targets, use the M(win_package) module instead.
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: install ntpdate - name: Install ntpdate
package: package:
name: ntpdate name: ntpdate
state: present state: present
# This uses a variable as this changes per distribution. # This uses a variable as this changes per distribution.
- name: remove the apache package - name: Remove the apache package
package: package:
name: "{{ apache }}" name: "{{ apache }}"
state: absent state: absent
- name: install the latest version of Apache and MariaDB - name: Install the latest version of Apache and MariaDB
package: package:
name: name:
- httpd - httpd

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

@ -44,11 +44,11 @@ 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 ping
# Example from an Ansible Playbook - name: Example from an Ansible Playbook
- ping: ping:
# Induce an exception to see what happens - name: Induce an exception to see what happens
- ping: ping:
data: crash data: crash
''' '''

@ -134,96 +134,98 @@ author:
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Install (Bottle) python package. - name: Install bottle python package
- pip: pip:
name: bottle name: bottle
# Install (Bottle) python package on version 0.11. - name: Install bottle python package on version 0.11
- pip: pip:
name: bottle==0.11 name: bottle==0.11
# Install (bottle) python package with version specifiers - name: Install bottle python package with version specifiers
- pip: pip:
name: bottle>0.10,<0.20,!=0.11 name: bottle>0.10,<0.20,!=0.11
# Install multi python packages with version specifiers - name: Install multi python packages with version specifiers
- pip: 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
# Install python package using a proxy - it doesn't use the standard environment variables, please use the CAPITALIZED ones below - name: Install python package using a proxy
- pip: # Pip doesn't use the standard environment variables, please use the CAPITALIZED ones below
pip:
name: six name: six
environment: environment:
HTTP_PROXY: '127.0.0.1:8080' HTTP_PROXY: '127.0.0.1:8080'
HTTPS_PROXY: '127.0.0.1:8080' HTTPS_PROXY: '127.0.0.1:8080'
# Install (MyApp) using one of the remote protocols (bzr+,hg+,git+,svn+). You do not have to supply '-e' option in extra_args. # You do not have to supply '-e' option in extra_args
- pip: - name: Install MyApp using one of the remote protocols (bzr+,hg+,git+,svn+)
pip:
name: svn+http://myrepo/svn/MyApp#egg=MyApp name: svn+http://myrepo/svn/MyApp#egg=MyApp
# Install MyApp using one of the remote protocols (bzr+,hg+,git+). - name: Install MyApp using one of the remote protocols (bzr+,hg+,git+)
- pip: pip:
name: git+http://myrepo/app/MyApp name: git+http://myrepo/app/MyApp
# Install (MyApp) from local tarball - name: Install MyApp from local tarball
- pip: pip:
name: file:///path/to/MyApp.tar.gz name: file:///path/to/MyApp.tar.gz
# 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: pip:
name: bottle name: bottle
virtualenv: /my_app/venv virtualenv: /my_app/venv
# Install (Bottle) into the specified (virtualenv), inheriting globally installed modules - name: Install bottle into the specified (virtualenv), inheriting globally installed modules
- pip: pip:
name: bottle name: bottle
virtualenv: /my_app/venv virtualenv: /my_app/venv
virtualenv_site_packages: yes virtualenv_site_packages: yes
# Install (Bottle) into the specified (virtualenv), using Python 2.7 - name: Install bottle into the specified (virtualenv), using Python 2.7
- pip: pip:
name: bottle name: bottle
virtualenv: /my_app/venv virtualenv: /my_app/venv
virtualenv_command: virtualenv-2.7 virtualenv_command: virtualenv-2.7
# Install (Bottle) within a user home directory. - name: Install bottle within a user home directory
- pip: pip:
name: bottle name: bottle
extra_args: --user extra_args: --user
# Install specified python requirements. - name: Install specified python requirements
- pip: pip:
requirements: /my_app/requirements.txt requirements: /my_app/requirements.txt
# Install specified python requirements in indicated (virtualenv). - name: Install specified python requirements in indicated (virtualenv)
- pip: pip:
requirements: /my_app/requirements.txt requirements: /my_app/requirements.txt
virtualenv: /my_app/venv virtualenv: /my_app/venv
# Install specified python requirements and custom Index URL. - name: Install specified python requirements and custom Index URL
- pip: 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
# 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: 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"
# 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: pip:
name: bottle name: bottle
executable: pip3.3 executable: pip3.3
# Install (Bottle), forcing reinstallation if it's already installed - name: Install bottle, forcing reinstallation if it's already installed
- pip: pip:
name: bottle name: bottle
state: forcereinstall state: forcereinstall
# 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: pip:
name: bottle name: bottle
umask: "0022" umask: "0022"
become: True become: True

@ -48,23 +48,23 @@ options:
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Example action to import a key from a url - name: Import a key from a url
- rpm_key: rpm_key:
state: present state: present
key: http://apt.sw.be/RPM-GPG-KEY.dag.txt key: http://apt.sw.be/RPM-GPG-KEY.dag.txt
# Example action to import a key from a file - name: Import a key from a file
- rpm_key: rpm_key:
state: present state: present
key: /path/to/key.gpg key: /path/to/key.gpg
# Example action to ensure a key is not present in the db - name: Ensure a key is not present in the db
- rpm_key: rpm_key:
state: absent state: absent
key: DEADB33F key: DEADB33F
# Verify the key, using a fingerprint, before import - name: Verify the key, using a fingerprint, before import
- rpm_key: rpm_key:
key: /path/to/RPM-GPG-KEY.dag.txt key: /path/to/RPM-GPG-KEY.dag.txt
fingerprint: EBC6 E12C 62B1 C734 026B 2122 A20E 5214 6B8D 79E6 fingerprint: EBC6 E12C 62B1 C734 026B 2122 A20E 5214 6B8D 79E6
''' '''

@ -35,7 +35,7 @@ author:
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: populate service facts - name: Populate service facts
service_facts: service_facts:
- debug: - debug:

@ -57,17 +57,17 @@ author:
''' '''
EXAMPLES = r''' EXAMPLES = r'''
# Example setting host facts using key=value pairs, note that this always creates strings or booleans - name: Setting host facts using key=value pairs, note that this always creates strings or booleans
- set_fact: one_fact="something" other_fact="{{ local_var }}" set_fact: one_fact="something" other_fact="{{ local_var }}"
# Example setting host facts using complex arguments - name: Setting host facts using complex arguments
- set_fact: 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 }}"
# Example 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: set_fact:
one_fact: something one_fact: something
other_fact: "{{ local_var * 2 }}" other_fact: "{{ local_var * 2 }}"
cacheable: yes cacheable: yes
@ -75,7 +75,8 @@ EXAMPLES = r'''
# As of Ansible 1.8, Ansible will convert boolean strings ('true', 'false', 'yes', 'no') # 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 # to proper boolean values when using the key=value syntax, however it is still
# recommended that booleans be set using the complex argument style: # recommended that booleans be set using the complex argument style:
- set_fact: - name: Setting booleans using complex argument style
set_fact:
one_fact: yes one_fact: yes
other_fact: no other_fact: no

@ -42,14 +42,14 @@ version_added: "2.3"
''' '''
EXAMPLES = r''' EXAMPLES = r'''
# Aggregating packages_installed stat per host - name: Aggregating packages_installed stat per host
- set_stats: set_stats:
data: data:
packages_installed: 31 packages_installed: 31
per_host: yes per_host: yes
# Aggregating random stats for all hosts using complex arguments - name: Aggregating random stats for all hosts using complex arguments
- set_stats: set_stats:
data: data:
one_stat: 11 one_stat: 11
other_stat: "{{ local_var * 2 }}" other_stat: "{{ local_var * 2 }}"
@ -57,8 +57,8 @@ EXAMPLES = r'''
per_host: no per_host: no
# setting stats (not aggregating) - name: Setting stats (not aggregating)
- set_stats: set_stats:
data: data:
the_answer: 42 the_answer: 42
aggregate: no aggregate: no

@ -103,23 +103,23 @@ author:
''' '''
EXAMPLES = r''' EXAMPLES = r'''
- name: Execute the command in remote shell; stdout goes to the specified file on the remote. - name: Execute the command in remote shell; stdout goes to the specified file on the remote
shell: somescript.sh >> somelog.txt shell: somescript.sh >> somelog.txt
- name: Change the working directory to somedir/ before executing the command. - name: Change the working directory to somedir/ before executing the command
shell: somescript.sh >> somelog.txt shell: somescript.sh >> somelog.txt
args: args:
chdir: somedir/ chdir: somedir/
# You can also use the 'args' form to provide the options. # You can also use the 'args' form to provide the options.
- name: This command will change the working directory to somedir/ and will only run when somedir/somelog.txt doesn't exist. - name: This command will change the working directory to somedir/ and will only run when somedir/somelog.txt doesn't exist
shell: somescript.sh >> somelog.txt shell: somescript.sh >> somelog.txt
args: args:
chdir: somedir/ chdir: somedir/
creates: somelog.txt creates: somelog.txt
# You can also use the 'cmd' parameter instead of free form format. # You can also use the 'cmd' parameter instead of free form format.
- name: This command will change the working directory to somedir/. - name: This command will change the working directory to somedir/
shell: shell:
cmd: ls -l | grep log cmd: ls -l | grep log
chdir: somedir/ chdir: somedir/
@ -153,7 +153,7 @@ EXAMPLES = r'''
delegate_to: localhost delegate_to: localhost
# Disabling warnings # Disabling warnings
- name: Using curl to connect to a host via SOCKS proxy (unsupported in uri). Ordinarily this would throw a warning. - name: Using curl to connect to a host via SOCKS proxy (unsupported in uri). Ordinarily this would throw a warning
shell: curl --socks5 localhost:9000 http://www.ansible.com shell: curl --socks5 localhost:9000 http://www.ansible.com
args: args:
warn: no warn: no

@ -73,7 +73,8 @@ author: Bruce Pennypacker (@bpennypacker)
EXAMPLES = r''' EXAMPLES = r'''
# Obtain the stats of /etc/foo.conf, and check that the file still belongs # Obtain the stats of /etc/foo.conf, and check that the file still belongs
# to 'root'. Fail otherwise. # to 'root'. Fail otherwise.
- stat: - name: Get stats of a file
stat:
path: /etc/foo.conf path: /etc/foo.conf
register: st register: st
- fail: - fail:
@ -85,7 +86,8 @@ EXAMPLES = r'''
# therefore, we must test whether it is defined. # therefore, we must test whether it is defined.
# Run this to understand the structure, the skipped ones do not pass the # Run this to understand the structure, the skipped ones do not pass the
# check performed by 'when' # check performed by 'when'
- stat: - name: Get stats of the FS object
stat:
path: /path/to/something path: /path/to/something
register: sym register: sym
@ -108,20 +110,21 @@ EXAMPLES = r'''
# Determine if a path exists and is a directory. Note that we need to test # Determine if a path exists and is a directory. Note that we need to test
# both that p.stat.isdir actually exists, and also that it's set to true. # both that p.stat.isdir actually exists, and also that it's set to true.
- stat: - name: Get stats of the FS object
stat:
path: /path/to/something path: /path/to/something
register: p register: p
- debug: - debug:
msg: "Path exists and is a directory" msg: "Path exists and is a directory"
when: p.stat.isdir is defined and p.stat.isdir when: p.stat.isdir is defined and p.stat.isdir
# Don't do checksum - name: Don't do checksum
- stat: stat:
path: /path/to/myhugefile path: /path/to/myhugefile
get_checksum: no get_checksum: no
# Use sha256 to calculate checksum - name: Use sha256 to calculate checksum
- stat: stat:
path: /path/to/something path: /path/to/something
checksum_algorithm: sha256 checksum_algorithm: sha256
''' '''

@ -96,39 +96,39 @@ EXAMPLES = '''
state: started state: started
name: httpd name: httpd
- name: stop service cron on debian, if running - name: Stop service cron on debian, if running
systemd: systemd:
name: cron name: cron
state: stopped state: stopped
- name: restart service cron on centos, in all cases, also issue daemon-reload to pick up config changes - name: Restart service cron on centos, in all cases, also issue daemon-reload to pick up config changes
systemd: systemd:
state: restarted state: restarted
daemon_reload: yes daemon_reload: yes
name: crond name: crond
- name: reload service httpd, in all cases - name: Reload service httpd, in all cases
systemd: systemd:
name: httpd name: httpd
state: reloaded state: reloaded
- name: enable service httpd and ensure it is not masked - name: Enable service httpd and ensure it is not masked
systemd: systemd:
name: httpd name: httpd
enabled: yes enabled: yes
masked: no masked: no
- name: enable a timer for dnf-automatic - name: Enable a timer for dnf-automatic
systemd: systemd:
name: dnf-automatic.timer name: dnf-automatic.timer
state: started state: started
enabled: yes enabled: yes
- name: just force systemd to reread configs (2.4 and above) - name: Just force systemd to reread configs (2.4 and above)
systemd: systemd:
daemon_reload: yes daemon_reload: yes
- name: just force systemd to re-execute itself (2.8 and above) - name: Just force systemd to re-execute itself (2.8 and above)
systemd: systemd:
daemon_reexec: yes daemon_reexec: yes
''' '''

@ -71,13 +71,13 @@ requirements:
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: make sure apache2 is started - name: Make sure apache2 is started
sysvinit: 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: sysvinit:
name: apache2 name: apache2
state: started state: started

@ -52,18 +52,18 @@ author:
''' '''
EXAMPLES = """ EXAMPLES = """
- name: create temporary build directory - name: Create temporary build directory
tempfile: tempfile:
state: directory state: directory
suffix: build suffix: build
- name: create temporary file - name: Create temporary file
tempfile: tempfile:
state: file state: file
suffix: temp suffix: temp
register: tempfile_1 register: tempfile_1
- name: use the registered var and the file module to remove the temporary file - name: Use the registered var and the file module to remove the temporary file
file: file:
path: "{{ tempfile_1.path }}" path: "{{ tempfile_1.path }}"
state: absent state: absent

@ -118,7 +118,7 @@ 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: wait_for:
timeout: 300 timeout: 300
delegate_to: localhost delegate_to: localhost

@ -241,12 +241,12 @@ author:
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: install the latest version of Apache - name: Install the latest version of Apache
yum: yum:
name: httpd name: httpd
state: latest state: latest
- 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: yum:
name: name:
- nginx - nginx
@ -254,7 +254,7 @@ EXAMPLES = '''
- postgresql-server - postgresql-server
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: yum:
name: "{{ packages }}" name: "{{ packages }}"
vars: vars:
@ -262,54 +262,54 @@ EXAMPLES = '''
- httpd - httpd
- httpd-tools - httpd-tools
- name: remove the Apache package - name: Remove the Apache package
yum: 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: 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: 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: 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: 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: 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: 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: 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: 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: yum:
list: ansible list: ansible
register: result register: result

Loading…
Cancel
Save