Examples syntax batch4 (#5620)

* Change example syntax on authorized_key module

* Change example syntax on cron module

* Change example syntax on group module

* Change example syntax on hostname module

* Change example syntax on seboolean module

* Change example syntax on selinux module

* Change example syntax on service module

* Change example syntax on sysctl module

* Change example syntax on systemd module

* Change example syntax on user module

* Change example syntax on debug module

* Change example syntax on fail module

* Change example syntax on include module

* Change example syntax on include_role module

* Change example syntax on include_vars module

* Change example syntax on pause module

* Change example syntax on wait_for module

* Change example syntax on apache2_module module

* > Change example syntax on django_manage module

* Change example syntax on htpasswd module
This commit is contained in:
Sam Doran 2016-11-15 15:21:47 -05:00 committed by Matt Clay
parent ad6999e2eb
commit b56a9852ee
20 changed files with 261 additions and 87 deletions

View file

@ -99,18 +99,20 @@ EXAMPLES = '''
# Using github url as key source # Using github url as key source
- authorized_key: - authorized_key:
user: charlie user: charlie
key: https://github.com/charlie.keys key: 'https://github.com/charlie.keys'
# Using alternate directory locations: # Using alternate directory locations:
- authorized_key: - authorized_key:
user: charlie user: charlie
key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}" key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}"
path: '/etc/ssh/authorized_keys/charlie' path: /etc/ssh/authorized_keys/charlie
manage_dir: no manage_dir: no
# Using with_file # Using with_file
- name: Set up authorized_keys for the deploy user - name: Set up authorized_keys for the deploy user
authorized_key: user=deploy key="{{ item }}" authorized_key:
user: deploy
key: "{{ item }}"
with_file: with_file:
- public_keys/doe-jane - public_keys/doe-jane
- public_keys/doe-john - public_keys/doe-john
@ -124,13 +126,13 @@ EXAMPLES = '''
# Using validate_certs: # Using validate_certs:
- authorized_key: - authorized_key:
user: charlie user: charlie
key: https://github.com/user.keys key: 'https://github.com/user.keys'
validate_certs: no validate_certs: no
# Set up authorized_keys exclusively with one key # Set up authorized_keys exclusively with one key
- authorized_key: - authorized_key:
user: root user: root
key: '{{ item }}' key: "{{ item }}"
state: present state: present
exclusive: yes exclusive: yes
with_file: with_file:

View file

@ -171,32 +171,59 @@ author:
EXAMPLES = ''' EXAMPLES = '''
# Ensure a job that runs at 2 and 5 exists. # Ensure a job that runs at 2 and 5 exists.
# Creates an entry like "0 5,2 * * ls -alh > /dev/null" # Creates an entry like "0 5,2 * * ls -alh > /dev/null"
- cron: name="check dirs" minute="0" hour="5,2" job="ls -alh > /dev/null" - cron:
name: "check dirs"
minute: "0"
hour: "5,2"
job: "ls -alh > /dev/null"
# Ensure an old job is no longer present. Removes any job that is prefixed # Ensure an old job is no longer present. Removes any job that is prefixed
# by "#Ansible: an old job" from the crontab # by "#Ansible: an old job" from the crontab
- cron: name="an old job" state=absent - cron:
name: "an old job"
state: absent
# Creates an entry like "@reboot /some/job.sh" # Creates an entry like "@reboot /some/job.sh"
- cron: name="a job for reboot" special_time=reboot job="/some/job.sh" - cron:
name: "a job for reboot"
special_time: reboot
job: "/some/job.sh"
# Creates an entry like "PATH=/opt/bin" on top of crontab # Creates an entry like "PATH=/opt/bin" on top of crontab
- cron: name=PATH env=yes value=/opt/bin - cron:
name: PATH
env: yes
value: /opt/bin
# Creates an entry like "APP_HOME=/srv/app" and insert it after PATH # Creates an entry like "APP_HOME=/srv/app" and insert it after PATH
# declaration # declaration
- cron: name=APP_HOME env=yes value=/srv/app insertafter=PATH - cron:
name: APP_HOME
env: yes
value: /srv/app
insertafter: PATH
# Creates a cron file under /etc/cron.d # Creates a cron file under /etc/cron.d
- cron: name="yum autoupdate" weekday="2" minute=0 hour=12 - cron:
user="root" job="YUMINTERACTIVE=0 /usr/sbin/yum-autoupdate" name: yum autoupdate
cron_file=ansible_yum-autoupdate weekday: 2
minute: 0
hour: 12
user: root
job: "YUMINTERACTIVE: 0 /usr/sbin/yum-autoupdate"
cron_file: ansible_yum-autoupdate
# Removes a cron file from under /etc/cron.d # Removes a cron file from under /etc/cron.d
- cron: name="yum autoupdate" cron_file=ansible_yum-autoupdate state=absent - cron:
name: "yum autoupdate"
cron_file: ansible_yum-autoupdate
state: absent
# Removes "APP_HOME" environment variable from crontab # Removes "APP_HOME" environment variable from crontab
- cron: name=APP_HOME env=yes state=absent - cron:
name: APP_HOME
env: yes
state: absent
''' '''
import os import os

View file

@ -53,7 +53,9 @@ options:
EXAMPLES = ''' EXAMPLES = '''
# Example group command from Ansible Playbooks # Example group command from Ansible Playbooks
- group: name=somegroup state=present - group:
name: somegroup
state: present
''' '''
import grp import grp

View file

@ -40,7 +40,8 @@ options:
''' '''
EXAMPLES = ''' EXAMPLES = '''
- hostname: name=web01 - hostname:
name: web01
''' '''
import socket import socket

View file

@ -50,7 +50,10 @@ author: "Stephen Fromm (@sfromm)"
EXAMPLES = ''' EXAMPLES = '''
# Set (httpd_can_network_connect) flag on and keep it persistent across reboots # Set (httpd_can_network_connect) flag on and keep it persistent across reboots
- seboolean: name=httpd_can_network_connect state=yes persistent=yes - seboolean:
name: httpd_can_network_connect
state: yes
persistent: yes
''' '''
try: try:

View file

@ -49,9 +49,19 @@ author: "Derek Carter (@goozbach) <goozbach@friocorte.com>"
''' '''
EXAMPLES = ''' EXAMPLES = '''
- selinux: policy=targeted state=enforcing # Enable SELinux
- selinux: policy=targeted state=permissive - selinux:
- selinux: state=disabled policy: targeted
state: enforcing
# Put SELinux in permissive mode, logging actions that would be blocked.
- selinux:
policy: targeted
state: permissive
# Disable SELinux
- selinux:
state: disabled
''' '''
import os import os

View file

@ -78,25 +78,41 @@ options:
EXAMPLES = ''' EXAMPLES = '''
# Example action to start service httpd, if not running # Example action to start service httpd, if not running
- service: name=httpd state=started - service:
name: httpd
state: started
# Example action to stop service httpd, if running # Example action to stop service httpd, if running
- service: name=httpd state=stopped - service:
name: httpd
state: stopped
# Example action to restart service httpd, in all cases # Example action to restart service httpd, in all cases
- service: name=httpd state=restarted - service:
name: httpd
state: restarted
# Example action to reload service httpd, in all cases # Example action to reload service httpd, in all cases
- service: name=httpd state=reloaded - service:
name: httpd
state: reloaded
# Example action to enable service httpd, and not touch the running state # Example action to enable service httpd, and not touch the running state
- service: name=httpd enabled=yes - service:
name: httpd
enabled: yes
# Example action to start service foo, based on running process /usr/bin/foo # Example action to start service foo, based on running process /usr/bin/foo
- service: name=foo pattern=/usr/bin/foo state=started - service:
name: foo
pattern: /usr/bin/foo
state: started
# Example action to restart network service for interface eth0 # Example action to restart network service for interface eth0
- service: name=network state=restarted args=eth0 - service:
name: network
state: restarted
args: eth0
''' '''

View file

@ -88,13 +88,25 @@ EXAMPLES = '''
sysctl_file: /etc/sysctl.conf sysctl_file: /etc/sysctl.conf
# Set kernel.panic to 3 in /tmp/test_sysctl.conf # Set kernel.panic to 3 in /tmp/test_sysctl.conf
- sysctl: name=kernel.panic value=3 sysctl_file=/tmp/test_sysctl.conf reload=no - sysctl:
name: kernel.panic
value: 3
sysctl_file: /tmp/test_sysctl.conf
reload: no
# Set ip forwarding on in /proc and do not reload the sysctl file # Set ip forwarding on in /proc and do not reload the sysctl file
- sysctl: name="net.ipv4.ip_forward" value=1 sysctl_set=yes - sysctl:
name: net.ipv4.ip_forward
value: 1
sysctl_set: yes
# Set ip forwarding on in /proc and in the sysctl file and reload if necessary # Set ip forwarding on in /proc and in the sysctl file and reload if necessary
- sysctl: name="net.ipv4.ip_forward" value=1 sysctl_set=yes state=present reload=yes - sysctl:
name: net.ipv4.ip_forward
value: 1
sysctl_set: yes
state: present
reload: yes
''' '''
# ============================================================== # ==============================================================

View file

@ -72,18 +72,32 @@ requirements:
EXAMPLES = ''' EXAMPLES = '''
# Example action to start service httpd, if not running # Example action to start service httpd, if not running
- systemd: state=started name=httpd - systemd:
state: started
name: httpd
# Example action to stop service cron on debian, if running # Example action to stop service cron on debian, if running
- systemd: name=cron state=stopped - systemd:
name: cron
state: stopped
# Example action to restart service cron on centos, in all cases, also issue daemon-reload to pick up config changes # Example action to restart service cron on centos, in all cases, also issue daemon-reload to pick up config changes
- systemd: state=restarted daemon_reload=yes name=crond - systemd:
state: restarted
daemon_reload: yes
name: crond
# Example action to reload service httpd, in all cases # Example action to reload service httpd, in all cases
- systemd: name=httpd state=reloaded - systemd:
name: httpd
state: reloaded
# Example action to enable service httpd and ensure it is not masked # Example action to enable service httpd and ensure it is not masked
- systemd: - systemd:
name: httpd name: httpd
enabled: yes enabled: yes
masked: no masked: no
# Example action to enable a timer for dnf-automatic # Example action to enable a timer for dnf-automatic
- systemd: - systemd:
name: dnf-automatic.timer name: dnf-automatic.timer

View file

@ -200,19 +200,38 @@ options:
EXAMPLES = ''' EXAMPLES = '''
# Add the user 'johnd' with a specific uid and a primary group of 'admin' # Add the user 'johnd' with a specific uid and a primary group of 'admin'
- user: name=johnd comment="John Doe" uid=1040 group=admin - user:
name: johnd
comment: "John Doe"
uid: 1040
group: admin
# Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' to the user's groups # Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' to the user's groups
- user: name=james shell=/bin/bash groups=admins,developers append=yes - user:
name: james
shell: /bin/bash
groups: admins,developers
append: yes
# Remove the user 'johnd' # Remove the user 'johnd'
- user: name=johnd state=absent remove=yes - user:
name: johnd
state: absent
remove: yes
# Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa # Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa
- user: name=jsmith generate_ssh_key=yes ssh_key_bits=2048 ssh_key_file=.ssh/id_rsa - user:
name: jsmith
generate_ssh_key: yes
ssh_key_bits: 2048
ssh_key_file: .ssh/id_rsa
# added a consultant whose account you want to expire # added a consultant whose account you want to expire
- user: name=james18 shell=/bin/zsh groups=developers expires=1422403387 - user:
name: james18
shell: /bin/zsh
groups: developers
expires: 1422403387
''' '''
import os import os

View file

@ -51,16 +51,22 @@ author:
EXAMPLES = ''' EXAMPLES = '''
# Example that prints the loopback address and gateway for each host # Example that prints the loopback address and gateway for each host
- debug: msg="System {{ inventory_hostname }} has uuid {{ ansible_product_uuid }}" - debug:
msg: "System {{ inventory_hostname }} has uuid {{ ansible_product_uuid }}"
- debug: msg="System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }}" - debug:
msg: "System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }}"
when: ansible_default_ipv4.gateway is defined when: ansible_default_ipv4.gateway is defined
- shell: /usr/bin/uptime - shell: /usr/bin/uptime
register: result register: result
- debug: var=result verbosity=2 - debug:
var: result
verbosity: 2
- name: Display all variables/facts known for a host - name: Display all variables/facts known for a host
debug: var=hostvars[inventory_hostname] verbosity=4 debug:
var: hostvars[inventory_hostname]
verbosity: 4
''' '''

View file

@ -39,6 +39,7 @@ author: "Dag Wieers (@dagwieers)"
EXAMPLES = ''' EXAMPLES = '''
# Example playbook using fail and when together # Example playbook using fail and when together
- fail: msg="The system may not be provisioned according to the CMDB status." - fail:
msg: "The system may not be provisioned according to the CMDB status."
when: cmdb_status != "to-be-staged" when: cmdb_status != "to-be-staged"
''' '''

View file

@ -34,7 +34,8 @@ EXAMPLES = """
# include a play after another play # include a play after another play
- hosts: localhost - hosts: localhost
tasks: tasks:
- debug: msg="play1" - debug:
msg: "play1"
- include: otherplays.yml - include: otherplays.yml
@ -42,15 +43,21 @@ EXAMPLES = """
# include task list in play # include task list in play
- hosts: all - hosts: all
tasks: tasks:
- debug: msg=task1 - debug:
msg: task1
- include: stuff.yml - include: stuff.yml
- debug: msg=task10
- debug:
msg: task10
# dyanmic include task list in play # dyanmic include task list in play
- hosts: all - hosts: all
tasks: tasks:
- debug: msg=task1 - debug:
- include: {{hostvar}}.yml msg: task1
- include: "{{ hostvar }}.yml"
static: no static: no
when: hostvar is defined when: hostvar is defined
""" """

View file

@ -59,7 +59,8 @@ notes:
''' '''
EXAMPLES = """ EXAMPLES = """
- include_role: name=myrole - include_role:
name: myrole
- name: Run tasks/other.yml instead of 'main' - name: Run tasks/other.yml instead of 'main'
include_role: include_role:

View file

@ -61,7 +61,9 @@ EXAMPLES = """
name: stuff name: stuff
# Conditionally decide to load in variables into 'plans' when x is 0, otherwise do not. (2.2) # Conditionally decide to load in variables into 'plans' when x is 0, otherwise do not. (2.2)
- include_vars: file=contingency_plan.yml name=plans - include_vars:
file: contingency_plan.yml
name: plans
when: x == 0 when: x == 0
# Load a variable file based on the OS type, or a default if not found. # Load a variable file based on the OS type, or a default if not found.

View file

@ -47,11 +47,13 @@ notes:
EXAMPLES = ''' EXAMPLES = '''
# Pause for 5 minutes to build app cache. # Pause for 5 minutes to build app cache.
- pause: minutes=5 - pause:
minutes: 5
# Pause until you can verify updates to an application were successful. # Pause until you can verify updates to an application were successful.
- pause: - pause:
# A helpful reminder of what to look out for post-update. # A helpful reminder of what to look out for post-update.
- pause: prompt="Make sure org.foo.FooOverload exception is not present" - pause:
prompt: "Make sure org.foo.FooOverload exception is not present"
''' '''

View file

@ -123,30 +123,50 @@ author:
EXAMPLES = ''' EXAMPLES = '''
# wait 300 seconds for port 8000 to become open on the host, don't start checking for 10 seconds # wait 300 seconds for port 8000 to become open on the host, don't start checking for 10 seconds
- wait_for: port=8000 delay=10 - wait_for:
port: 8000
delay: 10
# wait 300 seconds for port 8000 of any IP to close active connections, don't start checking for 10 seconds # wait 300 seconds for port 8000 of any IP to close active connections, don't start checking for 10 seconds
- wait_for: host=0.0.0.0 port=8000 delay=10 state=drained - wait_for:
host: 0.0.0.0
port: 8000
delay: 10
state: drained
# wait 300 seconds for port 8000 of any IP to close active connections, ignoring connections for specified hosts # wait 300 seconds for port 8000 of any IP to close active connections, ignoring connections for specified hosts
- wait_for: host=0.0.0.0 port=8000 state=drained exclude_hosts=10.2.1.2,10.2.1.3 - wait_for:
host: 0.0.0.0
port: 8000
state: drained
exclude_hosts: 10.2.1.2,10.2.1.3
# wait until the file /tmp/foo is present before continuing # wait until the file /tmp/foo is present before continuing
- wait_for: path=/tmp/foo - wait_for:
path: /tmp/foo
# wait until the string "completed" is in the file /tmp/foo before continuing # wait until the string "completed" is in the file /tmp/foo before continuing
- wait_for: path=/tmp/foo search_regex=completed - wait_for:
path: /tmp/foo
search_regex: completed
# wait until the lock file is removed # wait until the lock file is removed
- wait_for: path=/var/lock/file.lock state=absent - wait_for:
path: /var/lock/file.lock
state: absent
# wait until the process is finished and pid was destroyed # wait until the process is finished and pid was destroyed
- wait_for: path=/proc/3466/status state=absent - wait_for:
path: /proc/3466/status
state: absent
# wait 300 seconds for port 22 to become open and contain "OpenSSH", don't assume the inventory_hostname is resolvable # wait 300 seconds for port 22 to become open and contain "OpenSSH", don't assume the inventory_hostname is resolvable
# and don't start checking for 10 seconds # and don't start checking for 10 seconds
- local_action: wait_for port=22 host="{{ ansible_ssh_host | default(inventory_hostname) }}" search_regex=OpenSSH delay=10 - local_action: wait_for
port: 22
host: "{{ ansible_ssh_host | default(inventory_hostname) }}"
search_regex: OpenSSH
delay: 10
''' '''
class TCPConnectionInfo(object): class TCPConnectionInfo(object):

View file

@ -47,10 +47,14 @@ requirements: ["a2enmod","a2dismod"]
EXAMPLES = ''' EXAMPLES = '''
# enables the Apache2 module "wsgi" # enables the Apache2 module "wsgi"
- apache2_module: state=present name=wsgi - apache2_module:
state: present
name: wsgi
# disables the Apache2 module "wsgi" # disables the Apache2 module "wsgi"
- apache2_module: state=absent name=wsgi - apache2_module:
state: absent
name: wsgi
''' '''
import re import re

View file

@ -99,24 +99,34 @@ author: "Scott Anderson (@tastychutney)"
EXAMPLES = """ EXAMPLES = """
# Run cleanup on the application installed in 'django_dir'. # Run cleanup on the application installed in 'django_dir'.
- django_manage: command=cleanup app_path={{ django_dir }} - django_manage:
command: cleanup
app_path: "{{ django_dir }}"
# Load the initial_data fixture into the application # Load the initial_data fixture into the application
- django_manage: command=loaddata app_path={{ django_dir }} fixtures={{ initial_data }} - django_manage:
command: loaddata
app_path: "{{ django_dir }}"
fixtures: "{{ initial_data }}"
# Run syncdb on the application # Run syncdb on the application
- django_manage: > - django_manage:
command=syncdb command: syncdb
app_path={{ django_dir }} app_path: "{{ django_dir }}"
settings={{ settings_app_name }} settings: "{{ settings_app_name }}"
pythonpath={{ settings_dir }} pythonpath: "{{ settings_dir }}"
virtualenv={{ virtualenv_dir }} virtualenv: "{{ virtualenv_dir }}"
# Run the SmokeTest test case from the main app. Useful for testing deploys. # Run the SmokeTest test case from the main app. Useful for testing deploys.
- django_manage: command=test app_path={{ django_dir }} apps=main.SmokeTest - django_manage:
command: test
app_path: "{{ django_dir }}"
apps: main.SmokeTest
# Create an initial superuser. # Create an initial superuser.
- django_manage: command="createsuperuser --noinput --username=admin --email=admin@example.com" app_path={{ django_dir }} - django_manage:
command: "createsuperuser --noinput --username=admin --email=admin@example.com"
app_path: "{{ django_dir }}"
""" """

View file

@ -74,11 +74,26 @@ author: "Ansible Core Team"
EXAMPLES = """ EXAMPLES = """
# Add a user to a password file and ensure permissions are set # Add a user to a password file and ensure permissions are set
- htpasswd: path=/etc/nginx/passwdfile name=janedoe password=9s36?;fyNp owner=root group=www-data mode=0640 - htpasswd:
path: /etc/nginx/passwdfile
name: janedoe
password: '9s36?;fyNp'
owner: root
group: www-data
mode: 0640
# Remove a user from a password file # Remove a user from a password file
- htpasswd: path=/etc/apache2/passwdfile name=foobar state=absent - htpasswd:
path: /etc/apache2/passwdfile
name: foobar
state: absent
# Add a user to a password file suitable for use by libpam-pwdfile # Add a user to a password file suitable for use by libpam-pwdfile
- htpasswd: path=/etc/mail/passwords name=alex password=oedu2eGh crypt_scheme=md5_crypt - htpasswd:
path: /etc/mail/passwords
name: alex
password: oedu2eGh
crypt_scheme: md5_crypt
""" """