summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/PULL_REQUEST_TEMPLATE.md12
-rw-r--r--cloud/amazon/_ec2_ami_search.py12
-rw-r--r--cloud/amazon/cloudformation.py20
-rw-r--r--cloud/amazon/ec2.py29
-rw-r--r--cloud/amazon/ec2_asg.py63
-rw-r--r--cloud/amazon/ec2_eip.py59
-rw-r--r--cloud/amazon/ec2_elb.py2
-rw-r--r--cloud/amazon/ec2_facts.py5
-rw-r--r--cloud/amazon/ec2_tag.py2
-rw-r--r--cloud/amazon/ec2_vol.py4
-rw-r--r--cloud/amazon/iam.py2
-rw-r--r--cloud/amazon/iam_policy.py2
-rw-r--r--cloud/amazon/rds.py4
-rw-r--r--cloud/amazon/route53.py30
-rwxr-xr-xcloud/amazon/s3.py129
-rw-r--r--cloud/digital_ocean/digital_ocean.py8
-rw-r--r--cloud/docker/docker_container.py9
-rw-r--r--cloud/docker/docker_image.py1
-rw-r--r--cloud/docker/docker_service.py21
-rw-r--r--cloud/google/gc_storage.py63
-rw-r--r--cloud/google/gce.py13
-rw-r--r--cloud/google/gce_mig.py19
-rw-r--r--cloud/openstack/README.md8
-rw-r--r--cloud/openstack/_glance_image.py19
-rw-r--r--cloud/openstack/_keystone_user.py24
-rw-r--r--cloud/openstack/_nova_keypair.py24
-rw-r--r--cloud/openstack/_quantum_floating_ip.py13
-rw-r--r--cloud/openstack/_quantum_floating_ip_associate.py16
-rw-r--r--cloud/openstack/_quantum_network.py29
-rw-r--r--cloud/openstack/_quantum_router.py13
-rw-r--r--cloud/openstack/_quantum_router_gateway.py12
-rw-r--r--cloud/openstack/_quantum_router_interface.py16
-rw-r--r--cloud/openstack/_quantum_subnet.py14
-rw-r--r--cloud/openstack/os_auth.py9
-rw-r--r--cloud/openstack/os_client_config.py16
-rw-r--r--cloud/openstack/os_image_facts.py11
-rw-r--r--cloud/openstack/os_networks_facts.py35
-rw-r--r--cloud/openstack/os_nova_flavor.py31
-rw-r--r--cloud/openstack/os_object.py18
-rw-r--r--cloud/openstack/os_security_group.py16
-rw-r--r--cloud/openstack/os_server.py222
-rw-r--r--cloud/openstack/os_subnets_facts.py37
-rw-r--r--cloud/openstack/os_user.py9
-rw-r--r--cloud/rackspace/rax_files.py27
-rw-r--r--cloud/rackspace/rax_files_objects.py74
-rw-r--r--cloud/vmware/vsphere_guest.py7
-rw-r--r--commands/script.py10
-rw-r--r--commands/shell.py10
-rw-r--r--database/mysql/mysql_db.py35
-rw-r--r--database/mysql/mysql_user.py70
-rw-r--r--database/mysql/mysql_variables.py7
-rwxr-xr-xdatabase/postgresql/postgresql_db.py14
-rw-r--r--database/postgresql/postgresql_privs.py120
-rw-r--r--database/postgresql/postgresql_user.py29
-rw-r--r--files/acl.py29
-rw-r--r--files/assemble.py14
-rw-r--r--files/copy.py34
-rw-r--r--files/fetch.py21
-rw-r--r--files/file.py34
-rw-r--r--files/find.py46
-rw-r--r--files/ini_file.py27
-rw-r--r--files/lineinfile.py63
-rw-r--r--files/replace.py23
-rw-r--r--files/stat.py105
-rw-r--r--files/synchronize.py81
-rw-r--r--files/template.py25
-rw-r--r--files/unarchive.py16
-rw-r--r--files/xattr.py13
-rw-r--r--inventory/add_host.py22
-rw-r--r--inventory/group_by.py7
-rw-r--r--network/basics/get_url.py6
-rw-r--r--network/basics/uri.py20
-rw-r--r--network/cumulus/cl_bond.py48
-rw-r--r--network/cumulus/cl_bridge.py55
-rw-r--r--network/cumulus/cl_img_install.py34
-rw-r--r--network/cumulus/cl_interface.py80
-rw-r--r--network/cumulus/cl_license.py54
-rw-r--r--network/cumulus/cl_ports.py4
-rw-r--r--network/ios/ios_command.py11
-rw-r--r--network/ios/ios_config.py2
-rw-r--r--network/junos/junos_config.py2
-rw-r--r--network/junos/junos_facts.py16
-rw-r--r--network/nxos/nxos_bgp.py6
-rw-r--r--network/nxos/nxos_bgp_af.py2
-rw-r--r--network/nxos/nxos_feature.py28
-rw-r--r--network/nxos/nxos_hsrp.py33
-rw-r--r--network/nxos/nxos_igmp.py33
-rw-r--r--network/nxos/nxos_igmp_interface.py2
-rw-r--r--network/nxos/nxos_interface.py48
-rw-r--r--network/nxos/nxos_interface_ospf.py2
-rw-r--r--network/nxos/nxos_ip_interface.py23
-rw-r--r--network/nxos/nxos_ping.py15
-rw-r--r--network/nxos/nxos_static_route.py2
-rw-r--r--network/nxos/nxos_switchport.py46
-rw-r--r--network/nxos/nxos_vlan.py37
-rw-r--r--network/nxos/nxos_vpc_interface.py2
-rw-r--r--network/nxos/nxos_vrf.py8
-rw-r--r--network/nxos/nxos_vrf_interface.py17
-rw-r--r--network/nxos/nxos_vrrp.py31
-rw-r--r--network/vyos/vyos_command.py14
-rw-r--r--packaging/language/easy_install.py8
-rw-r--r--packaging/language/gem.py14
-rwxr-xr-xpackaging/language/pip.py55
-rw-r--r--packaging/os/apt.py2
-rw-r--r--packaging/os/apt_key.py35
-rw-r--r--packaging/os/apt_repository.py26
-rwxr-xr-xpackaging/os/apt_rpm.py24
-rw-r--r--packaging/os/package.py8
-rw-r--r--packaging/os/redhat_subscription.py37
-rw-r--r--packaging/os/rhn_channel.py11
-rw-r--r--packaging/os/rhn_register.py45
-rw-r--r--packaging/os/rpm_key.py12
-rw-r--r--packaging/os/yum.py39
-rw-r--r--source_control/git.py30
-rw-r--r--source_control/hg.py12
-rw-r--r--source_control/subversion.py14
-rw-r--r--system/authorized_key.py31
-rw-r--r--system/cron.py47
-rw-r--r--system/group.py31
-rw-r--r--system/hostname.py3
-rw-r--r--system/mount.py63
-rw-r--r--system/seboolean.py5
-rw-r--r--system/selinux.py16
-rw-r--r--system/service.py36
-rw-r--r--system/sysctl.py24
-rw-r--r--system/systemd.py122
-rw-r--r--system/user.py35
-rw-r--r--utilities/helper/meta.py21
-rw-r--r--utilities/logic/async_wrapper.py17
-rw-r--r--utilities/logic/debug.py16
-rw-r--r--utilities/logic/fail.py3
-rw-r--r--utilities/logic/include.py17
-rw-r--r--utilities/logic/include_role.py3
-rw-r--r--utilities/logic/include_vars.py10
-rw-r--r--utilities/logic/pause.py6
-rw-r--r--utilities/logic/set_fact.py4
-rw-r--r--utilities/logic/wait_for.py42
-rw-r--r--web_infrastructure/apache2_module.py8
-rw-r--r--web_infrastructure/django_manage.py30
-rw-r--r--web_infrastructure/htpasswd.py21
-rw-r--r--web_infrastructure/supervisorctl.py20
-rw-r--r--windows/async_wrapper.ps12
-rwxr-xr-xwindows/win_copy.py21
-rw-r--r--windows/win_file.py34
-rw-r--r--windows/win_get_url.py26
-rw-r--r--windows/win_group.py4
-rw-r--r--windows/win_lineinfile.py57
-rw-r--r--windows/win_msi.py19
-rw-r--r--windows/win_service.py4
-rw-r--r--windows/win_stat.py9
150 files changed, 2694 insertions, 1230 deletions
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index 5cfd0271..4bfadfb6 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -9,7 +9,11 @@
<!--- Name of the plugin/module/task -->
##### ANSIBLE VERSION
-<!--- Paste verbatim output from “ansible --version” between quotes below -->
+<!---
+Paste verbatim output from “ansible --version” between quotes below,
+this is to help the Ansible team determine if this is a version specific
+issue which is being fixed.
+-->
```
```
@@ -22,7 +26,11 @@ If you are fixing an existing issue, please include "Fixes #nnnn" in your commit
message and your description; but you should still explain what the change does.
-->
-<!--- Paste verbatim command output below, e.g. before and after your change -->
+<!---
+Please paste verbatim command output below, e.g. before and after your change.
+Even in the event of a Docs Pull Request, this allows the Ansible team to quickly
+verify that there were no accidental syntax mistakes.
+-->
```
```
diff --git a/cloud/amazon/_ec2_ami_search.py b/cloud/amazon/_ec2_ami_search.py
index 4e3189f5..eae013cc 100644
--- a/cloud/amazon/_ec2_ami_search.py
+++ b/cloud/amazon/_ec2_ami_search.py
@@ -74,10 +74,18 @@ EXAMPLES = '''
connection: local
tasks:
- name: Get the Ubuntu precise AMI
- ec2_ami_search: distro=ubuntu release=precise region=us-west-1 store=instance-store
+ ec2_ami_search:
+ distro: ubuntu
+ release: precise
+ region: us-west-1
+ store: instance-store
register: ubuntu_image
+
- name: Start the EC2 instance
- ec2: image={{ ubuntu_image.ami }} instance_type=m1.small key_name=mykey
+ ec2:
+ image: "{{ ubuntu_image.ami }}"
+ instance_type: m1.small
+ key_name: mykey
'''
import csv
diff --git a/cloud/amazon/cloudformation.py b/cloud/amazon/cloudformation.py
index 724bf391..2cf26785 100644
--- a/cloud/amazon/cloudformation.py
+++ b/cloud/amazon/cloudformation.py
@@ -143,9 +143,11 @@ EXAMPLES = '''
# Use a template from a URL
- name: launch ansible cloudformation example
cloudformation:
- stack_name="ansible-cloudformation" state=present
- region=us-east-1 disable_rollback=true
- template_url=https://s3.amazonaws.com/my-bucket/cloudformation.template
+ stack_name: "ansible-cloudformation"
+ state: present
+ region: us-east-1
+ disable_rollback: true
+ template_url: 'https://s3.amazonaws.com/my-bucket/cloudformation.template'
args:
template_parameters:
KeyName: jmartin
@@ -158,10 +160,12 @@ EXAMPLES = '''
# Use a template from a URL, and assume a role to execute
- name: launch ansible cloudformation example with role assumption
cloudformation:
- stack_name="ansible-cloudformation" state=present
- region=us-east-1 disable_rollback=true
- template_url=https://s3.amazonaws.com/my-bucket/cloudformation.template
- role_arn: arn:aws:iam::123456789012:role/cloudformation-iam-role
+ stack_name: "ansible-cloudformation"
+ state: present
+ region: us-east-1
+ disable_rollback: true
+ template_url: 'https://s3.amazonaws.com/my-bucket/cloudformation.template'
+ role_arn: 'arn:aws:iam::123456789012:role/cloudformation-iam-role'
args:
template_parameters:
KeyName: jmartin
@@ -464,7 +468,7 @@ def main():
for res in reslist.get('StackResourceSummaries', []):
stack_resources.append({
"logical_resource_id": res['LogicalResourceId'],
- "physical_resource_id": res['PhysicalResourceId'],
+ "physical_resource_id": res.get('PhysicalResourceId', ''),
"resource_type": res['ResourceType'],
"last_updated_time": res['LastUpdatedTimestamp'],
"status": res['ResourceStatus'],
diff --git a/cloud/amazon/ec2.py b/cloud/amazon/ec2.py
index 01d105fd..8e17b920 100644
--- a/cloud/amazon/ec2.py
+++ b/cloud/amazon/ec2.py
@@ -434,12 +434,21 @@ EXAMPLES = '''
vpc_subnet_id: subnet-29e63245
assign_public_ip: yes
register: ec2
+
- name: Add new instance to host group
- add_host: hostname={{ item.public_ip }} groupname=launched
- with_items: '{{ec2.instances}}'
+ add_host:
+ hostname: "{{ item.public_ip }}"
+ groupname: launched
+ with_items: "{{ ec2.instances }}"
+
- name: Wait for SSH to come up
- wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started
- with_items: '{{ec2.instances}}'
+ wait_for:
+ host: "{{ item.public_dns_name }}"
+ port: 22
+ delay: 60
+ timeout: 320
+ state: started
+ with_items: "{{ ec2.instances }}"
- name: Configure instance(s)
hosts: launched
@@ -587,6 +596,8 @@ EXAMPLES = '''
import time
from ast import literal_eval
+from ansible.module_utils.six import iteritems
+from ansible.module_utils.six import get_function_code
try:
import boto.ec2
@@ -614,7 +625,7 @@ def find_running_instances_by_count_tag(module, ec2, count_tag, zone=None):
def _set_none_to_blank(dictionary):
result = dictionary
- for k in result.iterkeys():
+ for k in result:
if isinstance(result[k], dict):
result[k] = _set_none_to_blank(result[k])
elif not result[k]:
@@ -644,14 +655,14 @@ def get_reservations(module, ec2, tags=None, state=None, zone=None):
for x in tags:
if isinstance(x, dict):
x = _set_none_to_blank(x)
- filters.update(dict(("tag:"+tn, tv) for (tn,tv) in x.iteritems()))
+ filters.update(dict(("tag:"+tn, tv) for (tn,tv) in iteritems(x)))
else:
filters.update({"tag-key": x})
# if dict, add the key and value to the filter
if isinstance(tags, dict):
tags = _set_none_to_blank(tags)
- filters.update(dict(("tag:"+tn, tv) for (tn,tv) in tags.iteritems()))
+ filters.update(dict(("tag:"+tn, tv) for (tn,tv) in iteritems(tags)))
if state:
# http://stackoverflow.com/questions/437511/what-are-the-valid-instancestates-for-the-amazon-ec2-api
@@ -751,7 +762,7 @@ def boto_supports_profile_name_arg(ec2):
True if Boto library accept instance_profile_name argument, else false
"""
run_instances_method = getattr(ec2, 'run_instances')
- return 'instance_profile_name' in run_instances_method.func_code.co_varnames
+ return 'instance_profile_name' in get_function_code(run_instances_method).co_varnames
def create_block_device(module, ec2, volume):
# Not aware of a way to determine this programatically
@@ -801,7 +812,7 @@ def boto_supports_param_in_spot_request(ec2, param):
True if boto library has the named param as an argument on the request_spot_instances method, else False
"""
method = getattr(ec2, 'request_spot_instances')
- return param in method.func_code.co_varnames
+ return param in get_function_code(method).co_varnames
def await_spot_requests(module, ec2, spot_requests, count):
"""
diff --git a/cloud/amazon/ec2_asg.py b/cloud/amazon/ec2_asg.py
index 6cf0bc8f..378aaddd 100644
--- a/cloud/amazon/ec2_asg.py
+++ b/cloud/amazon/ec2_asg.py
@@ -53,6 +53,12 @@ options:
description:
- Maximum number of instances in group, if unspecified then the current group value will be used.
required: false
+ placement_group:
+ description:
+ - Physical location of your cluster placement group created in Amazon EC2.
+ required: false
+ version_added: "2.3"
+ default: None
desired_capacity:
description:
- Desired number of instances in group, if unspecified then the current group value will be used.
@@ -142,6 +148,13 @@ options:
default: ['autoscaling:EC2_INSTANCE_LAUNCH', 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR', 'autoscaling:EC2_INSTANCE_TERMINATE', 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR']
required: false
version_added: "2.2"
+ suspend_processes:
+ description:
+ - A list of scaling processes to suspend.
+ required: False
+ default: []
+ choices: ['Launch', 'Terminate', 'HealthCheck', 'ReplaceUnhealthy', 'AZRebalance', 'AlarmNotification', 'ScheduledActions', 'AddToLoadBalancer']
+ version_added: "2.3"
extends_documentation_fragment:
- aws
- ec2
@@ -387,6 +400,28 @@ def wait_for_elb(asg_connection, module, group_name):
module.fail_json(msg = "Waited too long for ELB instances to be healthy. %s" % time.asctime())
log.debug("Waiting complete. ELB thinks {0} instances are healthy.".format(healthy_instances))
+
+def suspend_processes(as_group, module):
+ suspend_processes = set(module.params.get('suspend_processes'))
+
+ try:
+ suspended_processes = set([p.process_name for p in as_group.suspended_processes])
+ except AttributeError:
+ # New ASG being created, no suspended_processes defined yet
+ suspended_processes = set()
+
+ if suspend_processes == suspended_processes:
+ return False
+
+ resume_processes = list(suspended_processes - suspend_processes)
+ if resume_processes:
+ as_group.resume_processes(resume_processes)
+
+ if suspend_processes:
+ as_group.suspend_processes(list(suspend_processes))
+
+ return True
+
def create_autoscaling_group(connection, module):
group_name = module.params.get('name')
load_balancers = module.params['load_balancers']
@@ -394,6 +429,7 @@ def create_autoscaling_group(connection, module):
launch_config_name = module.params.get('launch_config_name')
min_size = module.params['min_size']
max_size = module.params['max_size']
+ placement_group = module.params.get('placement_group')
desired_capacity = module.params.get('desired_capacity')
vpc_zone_identifier = module.params.get('vpc_zone_identifier')
set_tags = module.params.get('tags')
@@ -439,6 +475,7 @@ def create_autoscaling_group(connection, module):
launch_config=launch_configs[0],
min_size=min_size,
max_size=max_size,
+ placement_group=placement_group,
desired_capacity=desired_capacity,
vpc_zone_identifier=vpc_zone_identifier,
connection=connection,
@@ -450,6 +487,7 @@ def create_autoscaling_group(connection, module):
try:
connection.create_auto_scaling_group(ag)
+ suspend_processes(ag, module)
if wait_for_instances:
wait_for_new_inst(module, connection, group_name, wait_timeout, desired_capacity, 'viable_instances')
wait_for_elb(connection, module, group_name)
@@ -466,6 +504,10 @@ def create_autoscaling_group(connection, module):
else:
as_group = as_groups[0]
changed = False
+
+ if suspend_processes(as_group, module):
+ changed = True
+
for attr in ASG_ATTRIBUTES:
if module.params.get(attr, None) is not None:
module_attr = module.params.get(attr)
@@ -598,6 +640,14 @@ def replace(connection, module):
instances = props['instances']
if replace_instances:
instances = replace_instances
+
+ #check if min_size/max_size/desired capacity have been specified and if not use ASG values
+ if min_size is None:
+ min_size = as_group.min_size
+ if max_size is None:
+ max_size = as_group.max_size
+ if desired_capacity is None:
+ desired_capacity = as_group.desired_capacity
# check to see if instances are replaceable if checking launch configs
new_instances, old_instances = get_instances_by_lc(props, lc_check, instances)
@@ -620,14 +670,7 @@ def replace(connection, module):
if not old_instances:
changed = False
return(changed, props)
-
- #check if min_size/max_size/desired capacity have been specified and if not use ASG values
- if min_size is None:
- min_size = as_group.min_size
- if max_size is None:
- max_size = as_group.max_size
- if desired_capacity is None:
- desired_capacity = as_group.desired_capacity
+
# set temporary settings and wait for them to be reached
# This should get overwritten if the number of instances left is less than the batch size.
@@ -818,6 +861,7 @@ def main():
launch_config_name=dict(type='str'),
min_size=dict(type='int'),
max_size=dict(type='int'),
+ placement_group=dict(type='str'),
desired_capacity=dict(type='int'),
vpc_zone_identifier=dict(type='list'),
replace_batch_size=dict(type='int', default=1),
@@ -838,7 +882,8 @@ def main():
'autoscaling:EC2_INSTANCE_LAUNCH_ERROR',
'autoscaling:EC2_INSTANCE_TERMINATE',
'autoscaling:EC2_INSTANCE_TERMINATE_ERROR'
- ])
+ ]),
+ suspend_processes=dict(type='list', default=[])
),
)
diff --git a/cloud/amazon/ec2_eip.py b/cloud/amazon/ec2_eip.py
index eb3f17a9..4fb7c2ae 100644
--- a/cloud/amazon/ec2_eip.py
+++ b/cloud/amazon/ec2_eip.py
@@ -79,34 +79,67 @@ notes:
EXAMPLES = '''
- name: associate an elastic IP with an instance
- ec2_eip: device_id=i-1212f003 ip=93.184.216.119
+ ec2_eip:
+ device_id: i-1212f003
+ ip: 93.184.216.119
+
- name: associate an elastic IP with a device
- ec2_eip: device_id=eni-c8ad70f3 ip=93.184.216.119
+ ec2_eip:
+ device_id: eni-c8ad70f3
+ ip: 93.184.216.119
+
- name: disassociate an elastic IP from an instance
- ec2_eip: device_id=i-1212f003 ip=93.184.216.119 state=absent
+ ec2_eip:
+ device_id: i-1212f003
+ ip: 93.184.216.119
+ state: absent
+
- name: disassociate an elastic IP with a device
- ec2_eip: device_id=eni-c8ad70f3 ip=93.184.216.119 state=absent
+ ec2_eip:
+ device_id: eni-c8ad70f3
+ ip: 93.184.216.119
+ state: absent
+
- name: allocate a new elastic IP and associate it with an instance
- ec2_eip: device_id=i-1212f003
+ ec2_eip:
+ device_id: i-1212f003
+
- name: allocate a new elastic IP without associating it to anything
action: ec2_eip
register: eip
+
- name: output the IP
- debug: msg="Allocated IP is {{ eip.public_ip }}"
+ debug:
+ msg: "Allocated IP is {{ eip.public_ip }}"
+
- name: another way of allocating an elastic IP without associating it to anything
- ec2_eip: state='present'
+ ec2_eip:
+ state: 'present'
+
- name: provision new instances with ec2
- ec2: keypair=mykey instance_type=c1.medium image=ami-40603AD1 wait=yes'''
-''' group=webserver count=3
+ ec2:
+ keypair: mykey
+ instance_type: c1.medium
+ image: ami-40603AD1
+ wait: yes
+ group: webserver
+ count: 3
register: ec2
+
- name: associate new elastic IPs with each of the instances
- ec2_eip: "device_id={{ item }}"
- with_items: ec2.instance_ids
+ ec2_eip:
+ device_id: "{{ item }}"
+ with_items: "{{ ec2.instance_ids }}"
+
- name: allocate a new elastic IP inside a VPC in us-west-2
- ec2_eip: region=us-west-2 in_vpc=yes
+ ec2_eip:
+ region: us-west-2
+ in_vpc: yes
register: eip
+
- name: output the IP
- debug: msg="Allocated IP inside a VPC is {{ eip.public_ip }}"
+ debug:
+ msg: "Allocated IP inside a VPC is {{ eip.public_ip }}"
'''
try:
diff --git a/cloud/amazon/ec2_elb.py b/cloud/amazon/ec2_elb.py
index 000bcf04..0aab5cc0 100644
--- a/cloud/amazon/ec2_elb.py
+++ b/cloud/amazon/ec2_elb.py
@@ -92,7 +92,7 @@ post_tasks:
instance_id: "{{ ansible_ec2_instance_id }}"
ec2_elbs: "{{ item }}"
state: present
- with_items: ec2_elbs
+ with_items: "{{ ec2_elbs }}"
"""
import time
diff --git a/cloud/amazon/ec2_facts.py b/cloud/amazon/ec2_facts.py
index bcda99f1..f7fb86cb 100644
--- a/cloud/amazon/ec2_facts.py
+++ b/cloud/amazon/ec2_facts.py
@@ -42,10 +42,11 @@ author: "Silviu Dicu (@silviud) <silviudicu@gmail.com>"
EXAMPLES = '''
# Conditional example
- name: Gather facts
- action: ec2_facts
+ ec2_facts:
- name: Conditional
- action: debug msg="This instance is a t1.micro"
+ debug:
+ msg: "This instance is a t1.micro"
when: ansible_ec2_instance_type == "t1.micro"
'''
diff --git a/cloud/amazon/ec2_tag.py b/cloud/amazon/ec2_tag.py
index 3fd05dd4..76bba14b 100644
--- a/cloud/amazon/ec2_tag.py
+++ b/cloud/amazon/ec2_tag.py
@@ -89,7 +89,7 @@ tasks:
instance: "{{ item.id }}"
region: eu-west-1
state: list
- with_items: ec2.tagged_instances
+ with_items: "{{ ec2.tagged_instances }}"
register: ec2_vol
- name: tag the volumes
diff --git a/cloud/amazon/ec2_vol.py b/cloud/amazon/ec2_vol.py
index 5d325d83..fb78365f 100644
--- a/cloud/amazon/ec2_vol.py
+++ b/cloud/amazon/ec2_vol.py
@@ -135,7 +135,7 @@ EXAMPLES = '''
- ec2_vol:
instance: "{{ item.id }} "
volume_size: 5
- with_items: ec2.instances
+ with_items: "{{ ec2.instances }}"
register: ec2_vol
# Example: Launch an instance and then add a volume if not already attached
@@ -156,7 +156,7 @@ EXAMPLES = '''
instance: "{{ item.id }}"
name: my_existing_volume_Name_tag
device_name: /dev/xvdf
- with_items: ec2.instances
+ with_items: "{{ ec2.instances }}"
register: ec2_vol
# Remove a volume
diff --git a/cloud/amazon/iam.py b/cloud/amazon/iam.py
index 9f4e119b..15f6741b 100644
--- a/cloud/amazon/iam.py
+++ b/cloud/amazon/iam.py
@@ -136,7 +136,7 @@ task:
name: jdavila
state: update
groups: "{{ item.created_group.group_name }}"
- with_items: new_groups.results
+ with_items: "{{ new_groups.results }}"
# Example of role with custom trust policy for Lambda service
- name: Create IAM role with custom trust relationship
diff --git a/cloud/amazon/iam_policy.py b/cloud/amazon/iam_policy.py
index 559ad3c4..a95f88f4 100644
--- a/cloud/amazon/iam_policy.py
+++ b/cloud/amazon/iam_policy.py
@@ -94,7 +94,7 @@ task:
policy_name: "READ-ONLY"
policy_document: readonlypolicy.json
state: present
- with_items: new_groups.results
+ with_items: "{{ new_groups.results }}"
# Create a new S3 policy with prefix per user
tasks:
diff --git a/cloud/amazon/rds.py b/cloud/amazon/rds.py
index bde50fce..5b2e4383 100644
--- a/cloud/amazon/rds.py
+++ b/cloud/amazon/rds.py
@@ -301,9 +301,9 @@ EXAMPLES = '''
instance_name: MyNewInstanceName
region: us-west-2
vpc_security_groups: sg-xxx945xx
-
-- debug: msg="The new db endpoint is {{ rds.instance.endpoint }}"
+- debug:
+ msg: "The new db endpoint is {{ rds.instance.endpoint }}"
'''
import sys
diff --git a/cloud/amazon/route53.py b/cloud/amazon/route53.py
index 6e8c2537..4f08a4f6 100644
--- a/cloud/amazon/route53.py
+++ b/cloud/amazon/route53.py
@@ -217,13 +217,13 @@ EXAMPLES = '''
# Add an alias record that points to an Amazon ELB:
- route53:
- command=create
- zone=foo.com
- record=elb.foo.com
- type=A
- value="{{ elb_dns_name }}"
- alias=True
- alias_hosted_zone_id="{{ elb_zone_id }}"
+ command: create
+ zone: foo.com
+ record: elb.foo.com
+ type: A
+ value: "{{ elb_dns_name }}"
+ alias: True
+ alias_hosted_zone_id: "{{ elb_zone_id }}"
# Retrieve the details for elb.foo.com
- route53:
@@ -246,14 +246,14 @@ EXAMPLES = '''
# Add an alias record that points to an Amazon ELB and evaluates it health:
- route53:
- command=create
- zone=foo.com
- record=elb.foo.com
- type=A
- value="{{ elb_dns_name }}"
- alias=True
- alias_hosted_zone_id="{{ elb_zone_id }}"
- alias_evaluate_target_health=True
+ command: create
+ zone: foo.com
+ record: elb.foo.com
+ type: A
+ value: "{{ elb_dns_name }}"
+ alias: True
+ alias_hosted_zone_id: "{{ elb_zone_id }}"
+ alias_evaluate_target_health: True
# Add an AAAA record with Hosted Zone ID. Note that because there are colons in the value
# that the entire parameter list must be quoted:
diff --git a/cloud/amazon/s3.py b/cloud/amazon/s3.py
index bb3d0145..bfb4627f 100755
--- a/cloud/amazon/s3.py
+++ b/cloud/amazon/s3.py
@@ -154,44 +154,97 @@ extends_documentation_fragment: aws
'''
EXAMPLES = '''
-# Simple PUT operation
-- s3: bucket=mybucket object=/my/desired/key.txt src=/usr/local/myfile.txt mode=put
-
-# Simple PUT operation in Ceph RGW S3
-- s3: bucket=mybucket object=/my/desired/key.txt src=/usr/local/myfile.txt mode=put rgw=true s3_url=http://localhost:8000
-
-# Simple GET operation
-- s3: bucket=mybucket object=/my/desired/key.txt dest=/usr/local/myfile.txt mode=get
-
-# Get a specific version of an object.
-- s3: bucket=mybucket object=/my/desired/key.txt version=48c9ee5131af7a716edc22df9772aa6f dest=/usr/local/myfile.txt mode=get
-
-# PUT/upload with metadata
-- s3: bucket=mybucket object=/my/desired/key.txt src=/usr/local/myfile.txt mode=put metadata='Content-Encoding=gzip,Cache-Control=no-cache'
-
-# PUT/upload with custom headers
-- s3: bucket=mybucket object=/my/desired/key.txt src=/usr/local/myfile.txt mode=put headers=x-amz-grant-full-control=emailAddress=owner@example.com
-
-# List keys simple
-- s3: bucket=mybucket mode=list
-
-# List keys all options
-- s3: bucket=mybucket mode=list prefix=/my/desired/ marker=/my/desired/0023.txt max_keys=472
-
-# Create an empty bucket
-- s3: bucket=mybucket mode=create permission=public-read
-
-# Create a bucket with key as directory, in the EU region
-- s3: bucket=mybucket object=/my/directory/path mode=create region=eu-west-1
-
-# Delete a bucket and all contents
-- s3: bucket=mybucket mode=delete
-
-# GET an object but dont download if the file checksums match. New in 2.0
-- s3: bucket=mybucket object=/my/desired/key.txt dest=/usr/local/myfile.txt mode=get overwrite=different
-
-# Delete an object from a bucket
-- s3: bucket=mybucket object=/my/desired/key.txt mode=delobj
+- name: Simple PUT operation
+ s3:
+ bucket: mybucket
+ object: /my/desired/key.txt
+ src: /usr/local/myfile.txt
+ mode: put
+
+- name: Simple PUT operation in Ceph RGW S3
+ s3:
+ bucket: mybucket
+ object: /my/desired/key.txt
+ src: /usr/local/myfile.txt
+ mode: put
+ rgw: true
+ s3_url: "http://localhost:8000"
+
+- name: Simple GET operation
+ s3:
+ bucket: mybucket
+ object: /my/desired/key.txt
+ dest: /usr/local/myfile.txt
+ mode: get
+
+- name: Get a specific version of an object.
+ s3:
+ bucket: mybucket
+ object: /my/desired/key.txt
+ version: 48c9ee5131af7a716edc22df9772aa6f
+ dest: /usr/local/myfile.txt
+ mode: get
+
+- name: PUT/upload with metadata
+ s3:
+ bucket: mybucket
+ object: /my/desired/key.txt
+ src: /usr/local/myfile.txt
+ mode: put
+ metadata: 'Content-Encoding=gzip,Cache-Control=no-cache'
+
+- name: PUT/upload with custom headers
+ s3:
+ bucket: mybucket
+ object: /my/desired/key.txt
+ src: /usr/local/myfile.txt
+ mode: put
+ headers: 'x-amz-grant-full-control=emailAddress=owner@example.com'
+
+- name: List keys simple
+ s3:
+ bucket: mybucket
+ mode: list
+
+- name: List keys all options
+ s3:
+ bucket: mybucket
+ mode: list
+ prefix: /my/desired/
+ marker: /my/desired/0023.txt
+ max_keys: 472
+
+- name: Create an empty bucket
+ s3:
+ bucket: mybucket
+ mode: create
+ permission: public-read
+
+- name: Create a bucket with key as directory, in the EU region
+ s3:
+ bucket: mybucket
+ object: /my/directory/path
+ mode: create
+ region: eu-west-1
+
+- name: Delete a bucket and all contents
+ s3:
+ bucket: mybucket
+ mode: delete
+
+- name: GET an object but dont download if the file checksums match. New in 2.0
+ s3:
+ bucket: mybucket
+ object: /my/desired/key.txt
+ dest: /usr/local/myfile.txt
+ mode: get
+ overwrite: different
+
+- name: Delete an object from a bucket
+ s3:
+ bucket: mybucket
+ object: /my/desired/key.txt
+ mode: delobj
'''
import os
diff --git a/cloud/digital_ocean/digital_ocean.py b/cloud/digital_ocean/digital_ocean.py
index a90f27f7..d2c894cc 100644
--- a/cloud/digital_ocean/digital_ocean.py
+++ b/cloud/digital_ocean/digital_ocean.py
@@ -141,11 +141,13 @@ EXAMPLES = '''
region_id: ams2
image_id: fedora-19-x64
wait_timeout: 500
-
register: my_droplet
-- debug: msg="ID is {{ my_droplet.droplet.id }}"
-- debug: msg="IP is {{ my_droplet.droplet.ip_address }}"
+- debug:
+ msg: "ID is {{ my_droplet.droplet.id }}"
+
+- debug:
+ msg: "IP is {{ my_droplet.droplet.ip_address }}"
# Ensure a droplet is present
# If droplet id already exist, will return the droplet details and changed = False
diff --git a/cloud/docker/docker_container.py b/cloud/docker/docker_container.py
index a1a595ed..d6811e00 100644
--- a/cloud/docker/docker_container.py
+++ b/cloud/docker/docker_container.py
@@ -571,7 +571,6 @@ EXAMPLES = '''
- name: Add container to networks
docker_container:
- docker_container:
name: sleepy
networks:
- name: TestingNet
@@ -1201,6 +1200,12 @@ class Container(DockerBaseClass):
# assuming if the container was running, it must have been detached.
detach = not (config.get('AttachStderr') and config.get('AttachStdout'))
+ # "ExposedPorts": null returns None type & causes AttributeError - PR #5517
+ if config.get('ExposedPorts') is not None:
+ expected_exposed = [re.sub(r'/.+$', '', p) for p in config.get('ExposedPorts', dict()).keys()]
+ else:
+ expected_exposed = []
+
# Map parameters to container inspect results
config_mapping = dict(
image=config.get('Image'),
@@ -1217,7 +1222,7 @@ class Container(DockerBaseClass):
expected_env=(config.get('Env') or []),
expected_entrypoint=config.get('Entrypoint'),
expected_etc_hosts=host_config['ExtraHosts'],
- expected_exposed=[re.sub(r'/.+$', '', p) for p in config.get('ExposedPorts', dict()).keys()],
+ expected_exposed=expected_exposed,
groups=host_config.get('GroupAdd'),
ipc_mode=host_config.get("IpcMode"),
labels=config.get('Labels'),
diff --git a/cloud/docker/docker_image.py b/cloud/docker/docker_image.py
index 7d97d984..a7450b0b 100644
--- a/cloud/docker/docker_image.py
+++ b/cloud/docker/docker_image.py
@@ -224,7 +224,6 @@ EXAMPLES = '''
tag: v1
push: yes
load_path: my_sinatra.tar
- push: True
- name: Build image and with buildargs
docker_image:
diff --git a/cloud/docker/docker_service.py b/cloud/docker/docker_service.py
index ad231607..33a31cf7 100644
--- a/cloud/docker/docker_service.py
+++ b/cloud/docker/docker_service.py
@@ -190,14 +190,16 @@ EXAMPLES = '''
project_src: flask
register: output
- - debug: var=output
+ - debug:
+ var: output
- docker_service:
project_src: flask
build: no
register: output
- - debug: var=output
+ - debug:
+ var: output
- assert:
that: "not output.changed "
@@ -208,7 +210,8 @@ EXAMPLES = '''
stopped: true
register: output
- - debug: var=output
+ - debug:
+ var: output
- assert:
that:
@@ -221,7 +224,8 @@ EXAMPLES = '''
restarted: true
register: output
- - debug: var=output
+ - debug:
+ var: output
- assert:
that:
@@ -239,7 +243,8 @@ EXAMPLES = '''
web: 2
register: output
- - debug: var=output
+ - debug:
+ var: output
- name: Run with inline v2 compose
hosts: localhost
@@ -268,7 +273,8 @@ EXAMPLES = '''
- db
register: output
- - debug: var=output
+ - debug:
+ var: output
- assert:
that:
@@ -300,7 +306,8 @@ EXAMPLES = '''
- db
register: output
- - debug: var=output
+ - debug:
+ var: output
- assert:
that:
diff --git a/cloud/google/gc_storage.py b/cloud/google/gc_storage.py
index 64222d47..a032c63c 100644
--- a/cloud/google/gc_storage.py
+++ b/cloud/google/gc_storage.py
@@ -89,26 +89,49 @@ author: "Benno Joy (@bennojoy)"
'''
EXAMPLES = '''
-# upload some content
-- gc_storage: bucket=mybucket object=key.txt src=/usr/local/myfile.txt mode=put permission=public-read
-
-# upload some headers
-- gc_storage: bucket=mybucket object=key.txt src=/usr/local/myfile.txt headers='{"Content-Encoding": "gzip"}'
-
-# download some content
-- gc_storage: bucket=mybucket object=key.txt dest=/usr/local/myfile.txt mode=get
-
-# Download an object as a string to use else where in your playbook
-- gc_storage: bucket=mybucket object=key.txt mode=get_str
-
-# Create an empty bucket
-- gc_storage: bucket=mybucket mode=create
-
-# Create a bucket with key as directory
-- gc_storage: bucket=mybucket object=/my/directory/path mode=create
-
-# Delete a bucket and all contents
-- gc_storage: bucket=mybucket mode=delete
+- name: Upload some content
+ gc_storage:
+ bucket: mybucket
+ object: key.txt
+ src: /usr/local/myfile.txt
+ mode: put
+ permission: public-read
+
+- name: Upload some headers
+ gc_storage:
+ bucket: mybucket
+ object: key.txt
+ src: /usr/local/myfile.txt
+ headers: '{"Content-Encoding": "gzip"}'
+
+- name: Download some content
+ gc_storage:
+ bucket: mybucket
+ object: key.txt
+ dest: /usr/local/myfile.txt
+ mode: get
+
+- name: Download an object as a string to use else where in your playbook
+ gc_storage:
+ bucket: mybucket
+ object: key.txt
+ mode: get_str
+
+- name: Create an empty bucket
+ gc_storage:
+ bucket: mybucket
+ mode: create
+
+- name: Create a bucket with key as directory
+ gc_storage:
+ bucket: mybucket
+ object: /my/directory/path
+ mode: create
+
+- name: Delete a bucket and all contents
+ gc_storage:
+ bucket: mybucket
+ mode: delete
'''
import os
diff --git a/cloud/google/gce.py b/cloud/google/gce.py
index 9c18b71f..e1682e9c 100644
--- a/cloud/google/gce.py
+++ b/cloud/google/gce.py
@@ -246,11 +246,18 @@ EXAMPLES = '''
register: gce
- name: Save host data
- add_host: hostname={{ item.public_ip }} groupname=gce_instances_ips
+ add_host:
+ hostname: "{{ item.public_ip }}"
+ groupname: gce_instances_ips
with_items: "{{ gce.instance_data }}"
- name: Wait for SSH for instances
- wait_for: delay=1 host={{ item.public_ip }} port=22 state=started timeout=30
+ wait_for:
+ delay: 1
+ host: "{{ item.public_ip }}"
+ port: 22
+ state: started
+ timeout: 30
with_items: "{{ gce.instance_data }}"
- name: Configure Hosts
@@ -442,7 +449,7 @@ def create_instances(module, gce, instance_names, number):
bad_perms = []
if service_account_permissions:
for perm in service_account_permissions:
- if perm not in gce.SA_SCOPES_MAP.keys():
+ if perm not in gce.SA_SCOPES_MAP:
bad_perms.append(perm)
if len(bad_perms) > 0:
module.fail_json(msg='bad permissions: %s' % str(bad_perms))
diff --git a/cloud/google/gce_mig.py b/cloud/google/gce_mig.py
index 11433b35..37b17de0 100644
--- a/cloud/google/gce_mig.py
+++ b/cloud/google/gce_mig.py
@@ -116,7 +116,11 @@ EXAMPLES = '''
port: 80
- name: foobar
port: 82
- - pause: seconds=30
+
+ - name: Pause for 30 seconds
+ pause:
+ seconds: 30
+
- name: Recreate MIG Instances with Instance Template change.
gce_mig:
name: ansible-mig-example
@@ -124,13 +128,18 @@ EXAMPLES = '''
state: present
template: my-instance-template-2-small
recreate_instances: yes
- - pause: seconds=30
+
+ - name: Pause for 30 seconds
+ pause:
+ seconds: 30
+
- name: Resize MIG
gce_mig:
name: ansible-mig-example
zone: us-central1-c
state: present
size: 3
+
- name: Update MIG with Autoscaler
gce_mig:
name: ansible-mig-example
@@ -150,7 +159,11 @@ EXAMPLES = '''
target: .39
load_balancing_utilization:
target: 0.4
- - pause: seconds=30
+
+ - name: Pause for 30 seconds
+ pause:
+ seconds: 30
+
- name: Delete MIG
gce_mig:
name: ansible-mig-example
diff --git a/cloud/openstack/README.md b/cloud/openstack/README.md
index 4a872b11..36cdcd38 100644
--- a/cloud/openstack/README.md
+++ b/cloud/openstack/README.md
@@ -54,3 +54,11 @@ Libraries
users as a primary audience, they are for intra-server communication. The
python-openstacksdk is the future there, and shade will migrate to it when
its ready in a manner that is not noticable to ansible users.
+
+Testing
+-------
+
+* Integration testing is currently done in OpenStack's CI system in
+ http://git.openstack.org/cgit/openstack-infra/shade/tree/shade/tests/ansible
+* Testing in shade produces an obvious chicken-and-egg scenario. Work is under
+ way to trigger from and report on PRs directly.
diff --git a/cloud/openstack/_glance_image.py b/cloud/openstack/_glance_image.py
index 0db7aa2c..2d3c9583 100644
--- a/cloud/openstack/_glance_image.py
+++ b/cloud/openstack/_glance_image.py
@@ -120,15 +120,16 @@ requirements:
'''
EXAMPLES = '''
-# Upload an image from an HTTP URL
-- glance_image: login_username=admin
- login_password=passme
- login_tenant_name=admin
- name=cirros
- container_format=bare
- disk_format=qcow2
- state=present
- copy_from=http:launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
+- name: Upload an image from an HTTP URL
+ glance_image:
+ login_username: admin
+ login_password: passme
+ login_tenant_name: admin
+ name: cirros
+ container_format: bare
+ disk_format: qcow2
+ state: present
+ copy_from: 'http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img'
'''
import time
diff --git a/cloud/openstack/_keystone_user.py b/cloud/openstack/_keystone_user.py
index e7be3a1d..430e8bf4 100644
--- a/cloud/openstack/_keystone_user.py
+++ b/cloud/openstack/_keystone_user.py
@@ -94,14 +94,22 @@ author: "Ansible Core Team (deprecated)"
'''
EXAMPLES = '''
-# Create a tenant
-- keystone_user: tenant=demo tenant_description="Default Tenant"
-
-# Create a user
-- keystone_user: user=john tenant=demo password=secrete
-
-# Apply the admin role to the john user in the demo tenant
-- keystone_user: role=admin user=john tenant=demo
+- name: Create a tenant
+ keystone_user:
+ tenant: demo
+ tenant_description: "Default Tenant"
+
+- name: Create a user
+ keystone_user:
+ user: john
+ tenant: demo
+ password: secrete
+
+- name: Apply the admin role to the john user in the demo tenant
+ keystone_user:
+ role: admin
+ user: john
+ tenant: demo
'''
try:
diff --git a/cloud/openstack/_nova_keypair.py b/cloud/openstack/_nova_keypair.py
index 330a280f..587bb5dc 100644
--- a/cloud/openstack/_nova_keypair.py
+++ b/cloud/openstack/_nova_keypair.py
@@ -29,7 +29,7 @@ DOCUMENTATION = '''
---
module: nova_keypair
version_added: "1.2"
-author:
+author:
- "Benno Joy (@bennojoy)"
- "Michael DeHaan"
deprecated: Deprecated in 2.0. Use os_keypair instead
@@ -83,14 +83,22 @@ requirements:
- "python-novaclient"
'''
EXAMPLES = '''
-# Creates a key pair with the running users public key
-- nova_keypair: state=present login_username=admin
- login_password=admin login_tenant_name=admin name=ansible_key
- public_key={{ lookup('file','~/.ssh/id_rsa.pub') }}
+- name: Create a key pair with the running users public key
+ nova_keypair:
+ state: present
+ login_username: admin
+ login_password: admin
+ login_tenant_name: admin
+ name: ansible_key
+ public_key: "{{ lookup('file','~/.ssh/id_rsa.pub') }}"
-# Creates a new key pair and the private key returned after the run.
-- nova_keypair: state=present login_username=admin login_password=admin
- login_tenant_name=admin name=ansible_key
+- name: Create a new key pair and the private key returned after the run.
+ nova_keypair:
+ state: present
+ login_username: admin
+ login_password: admin
+ login_tenant_name: admin
+ name: ansible_key
'''
def main():
diff --git a/cloud/openstack/_quantum_floating_ip.py b/cloud/openstack/_quantum_floating_ip.py
index e6eb267e..d3e2c898 100644
--- a/cloud/openstack/_quantum_floating_ip.py
+++ b/cloud/openstack/_quantum_floating_ip.py
@@ -95,10 +95,15 @@ requirements:
'''
EXAMPLES = '''
-# Assign a floating ip to the instance from an external network
-- quantum_floating_ip: state=present login_username=admin login_password=admin
- login_tenant_name=admin network_name=external_network
- instance_name=vm1 internal_network_name=internal_network
+- name: Assign a floating ip to the instance from an external network
+ quantum_floating_ip:
+ state: present
+ login_username: admin
+ login_password: admin
+ login_tenant_name: admin
+ network_name: external_network
+ instance_name: vm1
+ internal_network_name: internal_network
'''
def _get_ksclient(module, kwargs):
diff --git a/cloud/openstack/_quantum_floating_ip_associate.py b/cloud/openstack/_quantum_floating_ip_associate.py
index 90852974..7c7d7045 100644
--- a/cloud/openstack/_quantum_floating_ip_associate.py
+++ b/cloud/openstack/_quantum_floating_ip_associate.py
@@ -86,14 +86,14 @@ requirements:
'''
EXAMPLES = '''
-# Associate a specific floating IP with an Instance
-- quantum_floating_ip_associate:
- state=present
- login_username=admin
- login_password=admin
- login_tenant_name=admin
- ip_address=1.1.1.1
- instance_name=vm1
+- name: Associate a specific floating IP with an Instance
+ quantum_floating_ip_associate:
+ state: present
+ login_username: admin
+ login_password: admin
+ login_tenant_name: admin
+ ip_address: 1.1.1.1
+ instance_name: vm1
'''
def _get_ksclient(module, kwargs):
diff --git a/cloud/openstack/_quantum_network.py b/cloud/openstack/_quantum_network.py
index 83c80438..a6cf688e 100644
--- a/cloud/openstack/_quantum_network.py
+++ b/cloud/openstack/_quantum_network.py
@@ -113,15 +113,26 @@ requirements:
'''
EXAMPLES = '''
-# Create a GRE backed Quantum network with tunnel id 1 for tenant1
-- quantum_network: name=t1network tenant_name=tenant1 state=present
- provider_network_type=gre provider_segmentation_id=1
- login_username=admin login_password=admin login_tenant_name=admin
-
-# Create an external network
-- quantum_network: name=external_network state=present
- provider_network_type=local router_external=yes
- login_username=admin login_password=admin login_tenant_name=admin
+- name: Create a GRE backed Quantum network with tunnel id 1 for tenant1
+ quantum_network:
+ name: t1network
+ tenant_name: tenant1
+ state: present
+ provider_network_type: gre
+ provider_segmentation_id: 1
+ login_username: admin
+ login_password: admin
+ login_tenant_name: admin
+
+- name: Create an external network
+ quantum_network:
+ name: external_network
+ state: present
+ provider_network_type: local
+ router_external: yes
+ login_username: admin
+ login_password: admin
+ login_tenant_name: admin
'''
_os_keystone = None
diff --git a/cloud/openstack/_quantum_router.py b/cloud/openstack/_quantum_router.py
index f1e0ed8c..3a12028d 100644
--- a/cloud/openstack/_quantum_router.py
+++ b/cloud/openstack/_quantum_router.py
@@ -88,12 +88,13 @@ requirements:
'''
EXAMPLES = '''
-# Creates a router for tenant admin
-- quantum_router: state=present
- login_username=admin
- login_password=admin
- login_tenant_name=admin
- name=router1"
+- name: Create a router for tenant admin
+ quantum_router:
+ state: present
+ login_username: admin
+ login_password: admin
+ login_tenant_name: admin
+ name: router1
'''
_os_keystone = None
diff --git a/cloud/openstack/_quantum_router_gateway.py b/cloud/openstack/_quantum_router_gateway.py
index 0e060b50..e71a1717 100644
--- a/cloud/openstack/_quantum_router_gateway.py
+++ b/cloud/openstack/_quantum_router_gateway.py
@@ -83,10 +83,14 @@ requirements:
'''
EXAMPLES = '''
-# Attach an external network with a router to allow flow of external traffic
-- quantum_router_gateway: state=present login_username=admin login_password=admin
- login_tenant_name=admin router_name=external_router
- network_name=external_network
+- name: Attach an external network with a router to allow flow of external traffic
+ quantum_router_gateway:
+ state: present
+ login_username: admin
+ login_password: admin
+ login_tenant_name: admin
+ router_name: external_router
+ network_name: external_network
'''
_os_keystone = None
diff --git a/cloud/openstack/_quantum_router_interface.py b/cloud/openstack/_quantum_router_interface.py
index abff97e0..aba6d0cb 100644
--- a/cloud/openstack/_quantum_router_interface.py
+++ b/cloud/openstack/_quantum_router_interface.py
@@ -88,13 +88,15 @@ requirements:
'''
EXAMPLES = '''
-# Attach tenant1's subnet to the external router
-- quantum_router_interface: state=present login_username=admin
- login_password=admin
- login_tenant_name=admin
- tenant_name=tenant1
- router_name=external_route
- subnet_name=t1subnet
+- name: "Attach tenant1's subnet to the external router"
+ quantum_router_interface:
+ state: present
+ login_username: admin
+ login_password: admin
+ login_tenant_name: admin
+ tenant_name: tenant1
+ router_name: external_route
+ subnet_name: t1subnet
'''
diff --git a/cloud/openstack/_quantum_subnet.py b/cloud/openstack/_quantum_subnet.py
index 27c2a3e8..8e6dee2c 100644
--- a/cloud/openstack/_quantum_subnet.py
+++ b/cloud/openstack/_quantum_subnet.py
@@ -123,10 +123,16 @@ requirements:
'''
EXAMPLES = '''
-# Create a subnet for a tenant with the specified subnet
-- quantum_subnet: state=present login_username=admin login_password=admin
- login_tenant_name=admin tenant_name=tenant1
- network_name=network1 name=net1subnet cidr=192.168.0.0/24"
+- name: Create a subnet for a tenant with the specified subnet
+ quantum_subnet:
+ state: present
+ login_username: admin
+ login_password: admin
+ login_tenant_name: admin
+ tenant_name: tenant1
+ network_name: network1
+ name: net1subnet
+ cidr: 192.168.0.0/24
'''
_os_keystone = None
diff --git a/cloud/openstack/os_auth.py b/cloud/openstack/os_auth.py
index 4f4d22ea..f4cdea43 100644
--- a/cloud/openstack/os_auth.py
+++ b/cloud/openstack/os_auth.py
@@ -37,10 +37,13 @@ extends_documentation_fragment: openstack
'''
EXAMPLES = '''
-# Authenticate to the cloud and retrieve the service catalog
-- os_auth:
+- name: Authenticate to the cloud and retrieve the service catalog
+ os_auth:
cloud: rax-dfw
-- debug: var=service_catalog
+
+- name: Show service catalog
+ debug:
+ var: service_catalog
'''
def main():
diff --git a/cloud/openstack/os_client_config.py b/cloud/openstack/os_client_config.py
index 1627bdfe..ba524a5b 100644
--- a/cloud/openstack/os_client_config.py
+++ b/cloud/openstack/os_client_config.py
@@ -39,15 +39,17 @@ author: "Monty Taylor (@emonty)"
'''
EXAMPLES = '''
-# Get list of clouds that do not support security groups
-- os_client_config:
-- debug: var={{ item }}
- with_items: "{{ openstack.clouds|rejectattr('secgroup_source', 'none')|list() }}"
+- name: Get list of clouds that do not support security groups
+ os_client_config:
-# Get the information back just about the mordred cloud
-- os_client_config:
+- debug:
+ var: "{{ item }}"
+ with_items: "{{ openstack.clouds | rejectattr('secgroup_source', 'none') | list }}"
+
+- name: Get the information back just about the mordred cloud
+ os_client_config:
clouds:
- - mordred
+ - mordred
'''
diff --git a/cloud/openstack/os_image_facts.py b/cloud/openstack/os_image_facts.py
index 4058d400..9f693c73 100644
--- a/cloud/openstack/os_image_facts.py
+++ b/cloud/openstack/os_image_facts.py
@@ -42,15 +42,18 @@ extends_documentation_fragment: openstack
'''
EXAMPLES = '''
-# Gather facts about a previously created image named image1
-- os_image_facts:
+- name: Gather facts about a previously created image named image1
+ os_image_facts:
auth:
- auth_url: https://your_api_url.com:9000/v2.0
+ auth_url: 'https://your_api_url.com:9000/v2.0'
username: user
password: password
project_name: someproject
image: image1
-- debug: var=openstack
+
+- name: Show openstack facts
+ debug:
+ var: openstack
'''
RETURN = '''
diff --git a/cloud/openstack/os_networks_facts.py b/cloud/openstack/os_networks_facts.py
index 9db5ecea..c261fc32 100644
--- a/cloud/openstack/os_networks_facts.py
+++ b/cloud/openstack/os_networks_facts.py
@@ -46,30 +46,36 @@ extends_documentation_fragment: openstack
'''
EXAMPLES = '''
-# Gather facts about previously created networks
-- os_networks_facts:
+- name: Gather facts about previously created networks
+ os_networks_facts:
auth:
- auth_url: https://your_api_url.com:9000/v2.0
+ auth_url: 'https://your_api_url.com:9000/v2.0'
username: user
password: password
project_name: someproject
-- debug: var=openstack_networks
-# Gather facts about a previously created network by name
-- os_networks_facts:
+- name: Show openstack networks
+ debug:
+ var: openstack_networks
+
+- name: Gather facts about a previously created network by name
+ os_networks_facts:
auth:
- auth_url: https://your_api_url.com:9000/v2.0
+ auth_url: 'https://your_api_url.com:9000/v2.0'
username: user
password: password
project_name: someproject
name: network1
-- debug: var=openstack_networks
-# Gather facts about a previously created network with filter (note: name and
- filters parameters are Not mutually exclusive)
-- os_networks_facts:
+- name: Show openstack networks
+ debug:
+ var: openstack_networks
+
+- name: Gather facts about a previously created network with filter
+ # Note: name and filters parameters are Not mutually exclusive
+ os_networks_facts:
auth:
- auth_url: https://your_api_url.com:9000/v2.0
+ auth_url: 'https://your_api_url.com:9000/v2.0'
username: user
password: password
project_name: someproject
@@ -78,7 +84,10 @@ EXAMPLES = '''
subnets:
- 057d4bdf-6d4d-4728-bb0f-5ac45a6f7400
- 443d4dc0-91d4-4998-b21c-357d10433483
-- debug: var=openstack_networks
+
+- name: Show openstack networks
+ debug:
+ var: openstack_networks
'''
RETURN = '''
diff --git a/cloud/openstack/os_nova_flavor.py b/cloud/openstack/os_nova_flavor.py
index 102b2bf2..8dd939bc 100644
--- a/cloud/openstack/os_nova_flavor.py
+++ b/cloud/openstack/os_nova_flavor.py
@@ -88,22 +88,21 @@ requirements: ["shade"]
'''
EXAMPLES = '''
-# Create 'tiny' flavor with 1024MB of RAM, 1 virtual CPU, and 10GB of
-# local disk, and 10GB of ephemeral.
-- os_nova_flavor:
- cloud=mycloud
- state=present
- name=tiny
- ram=1024
- vcpus=1
- disk=10
- ephemeral=10
-
-# Delete 'tiny' flavor
-- os_nova_flavor:
- cloud=mycloud
- state=absent
- name=tiny
+- name: "Create 'tiny' flavor with 1024MB of RAM, 1 virtual CPU, and 10GB of local disk, and 10GB of ephemeral."
+ os_nova_flavor:
+ cloud: mycloud
+ state: present
+ name: tiny
+ ram: 1024
+ vcpus: 1
+ disk: 10
+ ephemeral: 10
+
+- name: "Delete 'tiny' flavor"
+ os_nova_flavor:
+ cloud: mycloud
+ state: absent
+ name: tiny
'''
RETURN = '''
diff --git a/cloud/openstack/os_object.py b/cloud/openstack/os_object.py
index d5d77e13..d386d853 100644
--- a/cloud/openstack/os_object.py
+++ b/cloud/openstack/os_object.py
@@ -60,11 +60,19 @@ options:
'''
EXAMPLES = '''
-# Creates a object named 'fstab' in the 'config' container
-- os_object: cloud=mordred state=present name=fstab container=config filename=/etc/fstab
-
-# Deletes a container called config and all of its contents
-- os_object: cloud=rax-iad state=absent container=config
+- name: "Create a object named 'fstab' in the 'config' container"
+ os_object:
+ cloud: mordred
+ state: present
+ name: fstab
+ container: config
+ filename: /etc/fstab
+
+- name: Delete a container called config and all of its contents
+ os_object:
+ cloud: rax-iad
+ state: absent
+ container: config
'''
diff --git a/cloud/openstack/os_security_group.py b/cloud/openstack/os_security_group.py
index f2a2bb6a..e5d0b899 100644
--- a/cloud/openstack/os_security_group.py
+++ b/cloud/openstack/os_security_group.py
@@ -53,17 +53,17 @@ options:
EXAMPLES = '''
# Create a security group
- os_security_group:
- cloud=mordred
- state=present
- name=foo
- description=security group for foo servers
+ cloud: mordred
+ state: present
+ name: foo
+ description: security group for foo servers
# Update the existing 'foo' security group description
- os_security_group:
- cloud=mordred
- state=present
- name=foo
- description=updated description for the foo security group
+ cloud: mordred
+ state: present
+ name: foo
+ description: updated description for the foo security group
'''
diff --git a/cloud/openstack/os_server.py b/cloud/openstack/os_server.py
index 12d8724e..f4d546d2 100644
--- a/cloud/openstack/os_server.py
+++ b/cloud/openstack/os_server.py
@@ -203,12 +203,11 @@ requirements:
'''
EXAMPLES = '''
-# Creates a new instance and attaches to a network and passes metadata to
-# the instance
-- os_server:
+- name: Create a new instance and attaches to a network and passes metadata to the instance
+ os_server:
state: present
auth:
- auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/
+ auth_url: 'https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/'
username: admin
password: admin
project_name: admin
@@ -224,99 +223,98 @@ EXAMPLES = '''
hostname: test1
group: uge_master
-# Creates a new instance in HP Cloud AE1 region availability zone az2 and
+# Create a new instance in HP Cloud AE1 region availability zone az2 and
# automatically assigns a floating IP
- name: launch a compute instance
hosts: localhost
tasks:
- - name: launch an instance
- os_server:
- state: present
- auth:
- auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/
- username: username
- password: Equality7-2521
- project_name: username-project1
- name: vm1
- region_name: region-b.geo-1
- availability_zone: az2
- image: 9302692b-b787-4b52-a3a6-daebb79cb498
- key_name: test
- timeout: 200
- flavor: 101
- security_groups: default
- auto_ip: yes
-
-# Creates a new instance in named cloud mordred availability zone az2
+ - name: launch an instance
+ os_server:
+ state: present
+ auth:
+ auth_url: 'https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/'
+ username: username
+ password: Equality7-2521
+ project_name: username-project1
+ name: vm1
+ region_name: region-b.geo-1
+ availability_zone: az2
+ image: 9302692b-b787-4b52-a3a6-daebb79cb498
+ key_name: test
+ timeout: 200
+ flavor: 101
+ security_groups: default
+ auto_ip: yes
+
+# Create a new instance in named cloud mordred availability zone az2
# and assigns a pre-known floating IP
- name: launch a compute instance
hosts: localhost
tasks:
- - name: launch an instance
- os_server:
- state: present
- cloud: mordred
- name: vm1
- availability_zone: az2
- image: 9302692b-b787-4b52-a3a6-daebb79cb498
- key_name: test
- timeout: 200
- flavor: 101
- floating_ips:
- - 12.34.56.79
-
-# Creates a new instance with 4G of RAM on Ubuntu Trusty, ignoring
+ - name: launch an instance
+ os_server:
+ state: present
+ cloud: mordred
+ name: vm1
+ availability_zone: az2
+ image: 9302692b-b787-4b52-a3a6-daebb79cb498
+ key_name: test
+ timeout: 200
+ flavor: 101
+ floating_ips:
+ - 12.34.56.79
+
+# Create a new instance with 4G of RAM on Ubuntu Trusty, ignoring
# deprecated images
- name: launch a compute instance
hosts: localhost
tasks:
- - name: launch an instance
- os_server:
- name: vm1
- state: present
- cloud: mordred
- region_name: region-b.geo-1
- image: Ubuntu Server 14.04
- image_exclude: deprecated
- flavor_ram: 4096
-
-# Creates a new instance with 4G of RAM on Ubuntu Trusty on a Performance node
+ - name: launch an instance
+ os_server:
+ name: vm1
+ state: present
+ cloud: mordred
+ region_name: region-b.geo-1
+ image: Ubuntu Server 14.04
+ image_exclude: deprecated
+ flavor_ram: 4096
+
+# Create a new instance with 4G of RAM on Ubuntu Trusty on a Performance node
- name: launch a compute instance
hosts: localhost
tasks:
- - name: launch an instance
- os_server:
- name: vm1
- cloud: rax-dfw
- state: present
- image: Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
- flavor_ram: 4096
- flavor_include: Performance
+ - name: launch an instance
+ os_server:
+ name: vm1
+ cloud: rax-dfw
+ state: present
+ image: Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
+ flavor_ram: 4096
+ flavor_include: Performance
# Creates a new instance and attaches to multiple network
- name: launch a compute instance
hosts: localhost
tasks:
- - name: launch an instance with a string
- os_server:
- auth:
- auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/
- username: admin
- password: admin
- project_name: admin
- name: vm1
- image: 4f905f38-e52a-43d2-b6ec-754a13ffb529
- key_name: ansible_key
- timeout: 200
- flavor: 4
- nics: "net-id=4cb08b20-62fe-11e5-9d70-feff819cdc9f,net-id=542f0430-62fe-11e5-9d70-feff819cdc9f..."
-
-# Creates a new instance and attaches to a network and passes metadata to
-# the instance
-- os_server:
+ - name: launch an instance with a string
+ os_server:
+ auth:
+ auth_url: 'https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/'
+ username: admin
+ password: admin
+ project_name: admin
+ name: vm1
+ image: 4f905f38-e52a-43d2-b6ec-754a13ffb529
+ key_name: ansible_key
+ timeout: 200
+ flavor: 4
+ nics: "net-id=4cb08b20-62fe-11e5-9d70-feff819cdc9f,net-id=542f0430-62fe-11e5-9d70-feff819cdc9f..."
+
+- name: Creates a new instance and attaches to a network and passes metadata to the instance
+ os_server:
state: present
auth:
- auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/
+ auth_url: 'https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/'
username: admin
password: admin
project_name: admin
@@ -330,51 +328,51 @@ EXAMPLES = '''
- net-name: another_network
meta: "hostname=test1,group=uge_master"
-# Creates a new instance and attaches to a specific network
-- os_server:
- state: present
- auth:
- auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/
- username: admin
- password: admin
- project_name: admin
- name: vm1
- image: 4f905f38-e52a-43d2-b6ec-754a13ffb529
- key_name: ansible_key
- timeout: 200
- flavor: 4
- network: another_network
-
-# Creates a new instance with 4G of RAM on a 75G Ubuntu Trusty volume
+- name: Creates a new instance and attaches to a specific network
+ os_server:
+ state: present
+ auth:
+ auth_url: 'https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/'
+ username: admin
+ password: admin
+ project_name: admin
+ name: vm1
+ image: 4f905f38-e52a-43d2-b6ec-754a13ffb529
+ key_name: ansible_key
+ timeout: 200
+ flavor: 4
+ network: another_network
+
+# Create a new instance with 4G of RAM on a 75G Ubuntu Trusty volume
- name: launch a compute instance
hosts: localhost
tasks:
- - name: launch an instance
- os_server:
- name: vm1
- state: present
- cloud: mordred
- region_name: ams01
- image: Ubuntu Server 14.04
- flavor_ram: 4096
- boot_from_volume: True
- volume_size: 75
+ - name: launch an instance
+ os_server:
+ name: vm1
+ state: present
+ cloud: mordred
+ region_name: ams01
+ image: Ubuntu Server 14.04
+ flavor_ram: 4096
+ boot_from_volume: True
+ volume_size: 75
# Creates a new instance with 2 volumes attached
- name: launch a compute instance
hosts: localhost
tasks:
- - name: launch an instance
- os_server:
- name: vm1
- state: present
- cloud: mordred
- region_name: ams01
- image: Ubuntu Server 14.04
- flavor_ram: 4096
- volumes:
- - photos
- - music
+ - name: launch an instance
+ os_server:
+ name: vm1
+ state: present
+ cloud: mordred
+ region_name: ams01
+ image: Ubuntu Server 14.04
+ flavor_ram: 4096
+ volumes:
+ - photos
+ - music
'''
diff --git a/cloud/openstack/os_subnets_facts.py b/cloud/openstack/os_subnets_facts.py
index 8d853de7..dce24362 100644
--- a/cloud/openstack/os_subnets_facts.py
+++ b/cloud/openstack/os_subnets_facts.py
@@ -46,36 +46,45 @@ extends_documentation_fragment: openstack
'''
EXAMPLES = '''
-# Gather facts about previously created subnets
-- os_subnets_facts:
+- name: Gather facts about previously created subnets
+ os_subnets_facts:
auth:
- auth_url: https://your_api_url.com:9000/v2.0
+ auth_url: 'https://your_api_url.com:9000/v2.0'
username: user
password: password
project_name: someproject
-- debug: var=openstack_subnets
-# Gather facts about a previously created subnet by name
-- os_subnets_facts:
+- name: Show openstack subnets
+ debug:
+ var: openstack_subnets
+
+- name: Gather facts about a previously created subnet by name
+ os_subnets_facts:
auth:
- auth_url: https://your_api_url.com:9000/v2.0
+ auth_url: 'https://your_api_url.com:9000/v2.0'
username: user
password: password
project_name: someproject
- name: subnet1
-- debug: var=openstack_subnets
+ name: subnet1
+
+- name: Show openstack subnets
+ debug:
+ var: openstack_subnets
-# Gather facts about a previously created subnet with filter (note: name and
- filters parameters are Not mutually exclusive)
-- os_subnets_facts:
+- name: Gather facts about a previously created subnet with filter
+ # Note: name and filters parameters are not mutually exclusive
+ os_subnets_facts:
auth:
- auth_url: https://your_api_url.com:9000/v2.0
+ auth_url: 'https://your_api_url.com:9000/v2.0'
username: user
password: password
project_name: someproject
filters:
tenant_id: 55e2ce24b2a245b09f181bf025724cbe
-- debug: var=openstack_subnets
+
+- name: Show openstack subnets
+ debug:
+ var: openstack_subnets
'''
RETURN = '''
diff --git a/cloud/openstack/os_user.py b/cloud/openstack/os_user.py
index 264eb3f8..831f2fa9 100644
--- a/cloud/openstack/os_user.py
+++ b/cloud/openstack/os_user.py
@@ -191,10 +191,6 @@ def main():
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(
argument_spec,
- required_if=[
- ('update_password', 'always', ['password']),
- ('update_password', 'on_create', ['password']),
- ],
**module_kwargs)
if not HAS_SHADE:
@@ -219,6 +215,11 @@ def main():
domain_id = _get_domain_id(opcloud, domain)
if state == 'present':
+ if update_password in ('always', 'on_create'):
+ if not password:
+ msg = ("update_password is %s but a password value is "
+ "missing") % update_password
+ self.fail_json(msg=msg)
default_project_id = None
if default_project:
default_project_id = _get_default_project_id(cloud, default_project)
diff --git a/cloud/rackspace/rax_files.py b/cloud/rackspace/rax_files.py
index 48d5db21..77ab70d8 100644
--- a/cloud/rackspace/rax_files.py
+++ b/cloud/rackspace/rax_files.py
@@ -86,10 +86,12 @@ EXAMPLES = '''
gather_facts: no
tasks:
- name: "List all containers"
- rax_files: state=list
+ rax_files:
+ state: list
- name: "Create container called 'mycontainer'"
- rax_files: container=mycontainer
+ rax_files:
+ container: mycontainer
- name: "Create container 'mycontainer2' with metadata"
rax_files:
@@ -99,19 +101,30 @@ EXAMPLES = '''
file_for: someuser@example.com
- name: "Set a container's web index page"
- rax_files: container=mycontainer web_index=index.html
+ rax_files:
+ container: mycontainer
+ web_index: index.html
- name: "Set a container's web error page"
- rax_files: container=mycontainer web_error=error.html
+ rax_files:
+ container: mycontainer
+ web_error: error.html
- name: "Make container public"
- rax_files: container=mycontainer public=yes
+ rax_files:
+ container: mycontainer
+ public: yes
- name: "Make container public with a 24 hour TTL"
- rax_files: container=mycontainer public=yes ttl=86400
+ rax_files:
+ container: mycontainer
+ public: yes
+ ttl: 86400
- name: "Make container private"
- rax_files: container=mycontainer private=yes
+ rax_files:
+ container: mycontainer
+ private: yes
- name: "Test Cloud Files Containers Metadata Storage"
hosts: local
diff --git a/cloud/rackspace/rax_files_objects.py b/cloud/rackspace/rax_files_objects.py
index d89a8067..d0175996 100644
--- a/cloud/rackspace/rax_files_objects.py
+++ b/cloud/rackspace/rax_files_objects.py
@@ -102,28 +102,50 @@ EXAMPLES = '''
gather_facts: False
tasks:
- name: "Get objects from test container"
- rax_files_objects: container=testcont dest=~/Downloads/testcont
+ rax_files_objects:
+ container: testcont
+ dest: ~/Downloads/testcont
- name: "Get single object from test container"
- rax_files_objects: container=testcont src=file1 dest=~/Downloads/testcont
+ rax_files_objects:
+ container: testcont
+ src: file1
+ dest: ~/Downloads/testcont
- name: "Get several objects from test container"
- rax_files_objects: container=testcont src=file1,file2,file3 dest=~/Downloads/testcont
+ rax_files_objects:
+ container: testcont
+ src: file1,file2,file3
+ dest: ~/Downloads/testcont
- name: "Delete one object in test container"
- rax_files_objects: container=testcont method=delete dest=file1
+ rax_files_objects:
+ container: testcont
+ method: delete
+ dest: file1
- name: "Delete several objects in test container"
- rax_files_objects: container=testcont method=delete dest=file2,file3,file4
+ rax_files_objects:
+ container: testcont
+ method: delete
+ dest: file2,file3,file4
- name: "Delete all objects in test container"
- rax_files_objects: container=testcont method=delete
+ rax_files_objects:
+ container: testcont
+ method: delete
- name: "Upload all files to test container"
- rax_files_objects: container=testcont method=put src=~/Downloads/onehundred
+ rax_files_objects:
+ container: testcont
+ method: put
+ src: ~/Downloads/onehundred
- name: "Upload one file to test container"
- rax_files_objects: container=testcont method=put src=~/Downloads/testcont/file1
+ rax_files_objects:
+ container: testcont
+ method: put
+ src: ~/Downloads/testcont/file1
- name: "Upload one file to test container with metadata"
rax_files_objects:
@@ -135,14 +157,25 @@ EXAMPLES = '''
who_uploaded_this: someuser@example.com
- name: "Upload one file to test container with TTL of 60 seconds"
- rax_files_objects: container=testcont method=put src=~/Downloads/testcont/file3 expires=60
+ rax_files_objects:
+ container: testcont
+ method: put
+ src: ~/Downloads/testcont/file3
+ expires: 60
- name: "Attempt to get remote object that does not exist"
- rax_files_objects: container=testcont method=get src=FileThatDoesNotExist.jpg dest=~/Downloads/testcont
+ rax_files_objects:
+ container: testcont
+ method: get
+ src: FileThatDoesNotExist.jpg
+ dest: ~/Downloads/testcont
ignore_errors: yes
- name: "Attempt to delete remote object that does not exist"
- rax_files_objects: container=testcont method=delete dest=FileThatDoesNotExist.jpg
+ rax_files_objects:
+ container: testcont
+ method: delete
+ dest: FileThatDoesNotExist.jpg
ignore_errors: yes
- name: "Test Cloud Files Objects Metadata"
@@ -150,10 +183,16 @@ EXAMPLES = '''
gather_facts: false
tasks:
- name: "Get metadata on one object"
- rax_files_objects: container=testcont type=meta dest=file2
+ rax_files_objects:
+ container: testcont
+ type: meta
+ dest: file2
- name: "Get metadata on several objects"
- rax_files_objects: container=testcont type=meta src=file2,file1
+ rax_files_objects:
+ container: testcont
+ type: meta
+ src: file2,file1
- name: "Set metadata on an object"
rax_files_objects:
@@ -167,7 +206,10 @@ EXAMPLES = '''
clear_meta: true
- name: "Verify metadata is set"
- rax_files_objects: container=testcont type=meta src=file17
+ rax_files_objects:
+ container: testcont
+ type: meta
+ src: file17
- name: "Delete metadata"
rax_files_objects:
@@ -180,7 +222,9 @@ EXAMPLES = '''
key2: ''
- name: "Get metadata on all objects"
- rax_files_objects: container=testcont type=meta
+ rax_files_objects:
+ container: testcont
+ type: meta
'''
try:
diff --git a/cloud/vmware/vsphere_guest.py b/cloud/vmware/vsphere_guest.py
index 8d60cec2..d077803f 100644
--- a/cloud/vmware/vsphere_guest.py
+++ b/cloud/vmware/vsphere_guest.py
@@ -19,6 +19,7 @@
# TODO:
# Ability to set CPU/Memory reservations
+
try:
import json
except ImportError:
@@ -986,7 +987,7 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name
disk_num = 0
dev_changes = []
disks_changed = {}
- for disk in sorted(vm_disk.iterkeys()):
+ for disk in sorted(vm_disk):
try:
disksize = int(vm_disk[disk]['size_gb'])
# Convert the disk size to kilobytes
@@ -1342,7 +1343,7 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest,
if vm_disk:
disk_num = 0
disk_key = 0
- for disk in sorted(vm_disk.iterkeys()):
+ for disk in sorted(vm_disk):
try:
datastore = vm_disk[disk]['datastore']
except KeyError:
@@ -1398,7 +1399,7 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest,
add_floppy(module, vsphere_client, config_target, config, devices,
default_devs, floppy_type, floppy_image_path)
if vm_nic:
- for nic in sorted(vm_nic.iterkeys()):
+ for nic in sorted(vm_nic):
try:
nictype = vm_nic[nic]['type']
except KeyError:
diff --git a/commands/script.py b/commands/script.py
index 1d07bbad..be8d9a1b 100644
--- a/commands/script.py
+++ b/commands/script.py
@@ -47,7 +47,7 @@ options:
notes:
- It is usually preferable to write Ansible modules than pushing scripts. Convert your script to an Ansible module for bonus points!
- The ssh connection plugin will force psuedo-tty allocation via -tt when scripts are executed. psuedo-ttys do not have a stderr channel and all stderr is sent to stdout. If you depend on separated stdout and stderr result keys, please switch to a copy+command set of tasks instead of using script.
-author:
+author:
- Ansible Core Team
- Michael DeHaan
"""
@@ -57,8 +57,12 @@ EXAMPLES = '''
- script: /some/local/script.sh --some-arguments 1234
# Run a script that creates a file, but only if the file is not yet created
-- script: /some/local/create_file.sh --some-arguments 1234 creates=/the/created/file.txt
+- script: /some/local/create_file.sh --some-arguments 1234
+ args:
+ creates: /the/created/file.txt
# Run a script that removes a file, but only if the file is not yet removed
-- script: /some/local/remove_file.sh --some-arguments 1234 removes=/the/removed/file.txt
+- script: /some/local/remove_file.sh --some-arguments 1234
+ args:
+ removes: /the/removed/file.txt
'''
diff --git a/commands/shell.py b/commands/shell.py
index 96bbae5e..ca17ddda 100644
--- a/commands/shell.py
+++ b/commands/shell.py
@@ -68,11 +68,11 @@ notes:
playbooks will follow the trend of using M(command) unless M(shell) is
explicitly required. When running ad-hoc commands, use your best
judgement.
- - To sanitize any variables passed to the shell module, you should use
+ - To sanitize any variables passed to the shell module, you should use
"{{ var | quote }}" instead of just "{{ var }}" to make sure they don't include evil things like semicolons.
requirements: [ ]
-author:
+author:
- Ansible Core Team
- Michael DeHaan
'''
@@ -83,7 +83,9 @@ EXAMPLES = '''
- shell: somescript.sh >> somelog.txt
# Change the working directory to somedir/ before executing the command.
-- shell: somescript.sh >> somelog.txt chdir=somedir/
+- shell: somescript.sh >> somelog.txt
+ args:
+ chdir: somedir/
# You can also use the 'args' form to provide the options. This command
# will change the working directory to somedir/ and will only run when
@@ -146,4 +148,4 @@ stdout_lines:
returned: always
type: list of strings
sample: [u'Clustering node rabbit@slave1 with rabbit@master ...']
-''' \ No newline at end of file
+'''
diff --git a/database/mysql/mysql_db.py b/database/mysql/mysql_db.py
index f98547b9..43728842 100644
--- a/database/mysql/mysql_db.py
+++ b/database/mysql/mysql_db.py
@@ -78,18 +78,33 @@ extends_documentation_fragment: mysql
'''
EXAMPLES = '''
-# Create a new database with name 'bobdata'
-- mysql_db: name=bobdata state=present
+- name: Create a new database with name 'bobdata'
+ mysql_db:
+ name: bobdata
+ state: present
# Copy database dump file to remote host and restore it to database 'my_db'
-- copy: src=dump.sql.bz2 dest=/tmp
-- mysql_db: name=my_db state=import target=/tmp/dump.sql.bz2
-
-# Dumps all databases to hostname.sql
-- mysql_db: state=dump name=all target=/tmp/{{ inventory_hostname }}.sql
-
-# Imports file.sql similar to mysql -u <username> -p <password> < hostname.sql
-- mysql_db: state=import name=all target=/tmp/{{ inventory_hostname }}.sql
+- name: Copy database dump file
+ copy:
+ src: dump.sql.bz2
+ dest: /tmp
+- name: Restore database
+ mysql_db:
+ name: my_db
+ state: import
+ target: /tmp/dump.sql.bz2
+
+- name: Dump all databases to hostname.sql
+ mysql_db:
+ state: dump
+ name: all
+ target: /tmp/{{ inventory_hostname }}.sql
+
+- name: Import file.sql similar to mysql -u <username> -p <password> < hostname.sql
+ mysql_db:
+ state: import
+ name: all
+ target: /tmp/{{ inventory_hostname }}.sql
'''
import os
diff --git a/database/mysql/mysql_user.py b/database/mysql/mysql_user.py
index 010cdce6..87e8318a 100644
--- a/database/mysql/mysql_user.py
+++ b/database/mysql/mysql_user.py
@@ -111,43 +111,89 @@ extends_documentation_fragment: mysql
EXAMPLES = """
# Removes anonymous user account for localhost
-- mysql_user: name='' host=localhost state=absent
+- mysql_user:
+ name: ''
+ host: localhost
+ state: absent
# Removes all anonymous user accounts
-- mysql_user: name='' host_all=yes state=absent
+- mysql_user:
+ name: ''
+ host_all: yes
+ state: absent
# Create database user with name 'bob' and password '12345' with all database privileges
-- mysql_user: name=bob password=12345 priv=*.*:ALL state=present
+- mysql_user:
+ name: bob
+ password: 12345
+ priv: '*.*:ALL'
+ state: present
# Create database user with name 'bob' and previously hashed mysql native password '*EE0D72C1085C46C5278932678FBE2C6A782821B4' with all database privileges
-- mysql_user: name=bob password='*EE0D72C1085C46C5278932678FBE2C6A782821B4' encrypted=yes priv=*.*:ALL state=present
+- mysql_user:
+ name: bob
+ password: '*EE0D72C1085C46C5278932678FBE2C6A782821B4'
+ encrypted: yes
+ priv: '*.*:ALL'
+ state: present
# Creates database user 'bob' and password '12345' with all database privileges and 'WITH GRANT OPTION'
-- mysql_user: name=bob password=12345 priv=*.*:ALL,GRANT state=present
+- mysql_user:
+ name: bob
+ password: 12345
+ priv: '*.*:ALL,GRANT'
+ state: present
# Modify user Bob to require SSL connections. Note that REQUIRESSL is a special privilege that should only apply to *.* by itself.
-- mysql_user: name=bob append_privs=true priv=*.*:REQUIRESSL state=present
+- mysql_user:
+ name: bob
+ append_privs: true
+ priv: '*.*:REQUIRESSL'
+ state: present
# Ensure no user named 'sally'@'localhost' exists, also passing in the auth credentials.
-- mysql_user: login_user=root login_password=123456 name=sally state=absent
+- mysql_user:
+ login_user: root
+ login_password: 123456
+ name: sally
+ state: absent
# Ensure no user named 'sally' exists at all
-- mysql_user: name=sally host_all=yes state=absent
+- mysql_user:
+ name: sally
+ host_all: yes
+ state: absent
# Specify grants composed of more than one word
-- mysql_user: name=replication password=12345 priv="*.*:REPLICATION CLIENT" state=present
+- mysql_user:
+ name: replication
+ password: 12345
+ priv: "*.*:REPLICATION CLIENT"
+ state: present
# Revoke all privileges for user 'bob' and password '12345'
-- mysql_user: name=bob password=12345 priv=*.*:USAGE state=present
+- mysql_user:
+ name: bob
+ password: 12345
+ priv: "*.*:USAGE"
+ state: present
# Example privileges string format
mydb.*:INSERT,UPDATE/anotherdb.*:SELECT/yetanotherdb.*:ALL
# Example using login_unix_socket to connect to server
-- mysql_user: name=root password=abc123 login_unix_socket=/var/run/mysqld/mysqld.sock
+- mysql_user:
+ name: root
+ password: abc123
+ login_unix_socket: /var/run/mysqld/mysqld.sock
# Example of skipping binary logging while adding user 'bob'
-- mysql_user: name=bob password=12345 priv=*.*:USAGE state=present sql_log_bin=no
+- mysql_user:
+ name: bob
+ password: 12345
+ priv: "*.*:USAGE"
+ state: present
+ sql_log_bin: no
# Example .my.cnf file for setting the root password
diff --git a/database/mysql/mysql_variables.py b/database/mysql/mysql_variables.py
index 5cb6bf6f..014b768d 100644
--- a/database/mysql/mysql_variables.py
+++ b/database/mysql/mysql_variables.py
@@ -44,10 +44,13 @@ extends_documentation_fragment: mysql
'''
EXAMPLES = '''
# Check for sync_binlog setting
-- mysql_variables: variable=sync_binlog
+- mysql_variables:
+ variable: sync_binlog
# Set read_only variable to 1
-- mysql_variables: variable=read_only value=1
+- mysql_variables:
+ variable: read_only
+ value: 1
'''
diff --git a/database/postgresql/postgresql_db.py b/database/postgresql/postgresql_db.py
index 64871ed1..70cc96dc 100755
--- a/database/postgresql/postgresql_db.py
+++ b/database/postgresql/postgresql_db.py
@@ -95,16 +95,18 @@ author: "Ansible Core Team"
EXAMPLES = '''
# Create a new database with name "acme"
-- postgresql_db: name=acme
+- postgresql_db:
+ name: acme
# Create a new database with name "acme" and specific encoding and locale
# settings. If a template different from "template0" is specified, encoding
# and locale settings must match those of the template.
-- postgresql_db: name=acme
- encoding='UTF-8'
- lc_collate='de_DE.UTF-8'
- lc_ctype='de_DE.UTF-8'
- template='template0'
+- postgresql_db:
+ name: acme
+ encoding: UTF-8
+ lc_collate: de_DE.UTF-8
+ lc_ctype: de_DE.UTF-8
+ template: template0
'''
try:
diff --git a/database/postgresql/postgresql_privs.py b/database/postgresql/postgresql_privs.py
index 74b2630b..ea49a55f 100644
--- a/database/postgresql/postgresql_privs.py
+++ b/database/postgresql/postgresql_privs.py
@@ -143,90 +143,90 @@ EXAMPLES = """
# On database "library":
# GRANT SELECT, INSERT, UPDATE ON TABLE public.books, public.authors
# TO librarian, reader WITH GRANT OPTION
-- postgresql_privs: >
- database=library
- state=present
- privs=SELECT,INSERT,UPDATE
- type=table
- objs=books,authors
- schema=public
- roles=librarian,reader
- grant_option=yes
+- postgresql_privs:
+ database: library
+ state: present
+ privs: SELECT,INSERT,UPDATE
+ type: table
+ objs: books,authors
+ schema: public
+ roles: librarian,reader
+ grant_option: yes
# Same as above leveraging default values:
-- postgresql_privs: >
- db=library
- privs=SELECT,INSERT,UPDATE
- objs=books,authors
- roles=librarian,reader
- grant_option=yes
+- postgresql_privs:
+ db: library
+ privs: SELECT,INSERT,UPDATE
+ objs: books,authors
+ roles: librarian,reader
+ grant_option: yes
# REVOKE GRANT OPTION FOR INSERT ON TABLE books FROM reader
# Note that role "reader" will be *granted* INSERT privilege itself if this
-# isn't already the case (since state=present).
-- postgresql_privs: >
- db=library
- state=present
- priv=INSERT
- obj=books
- role=reader
- grant_option=no
+# isn't already the case (since state: present).
+- postgresql_privs:
+ db: library
+ state: present
+ priv: INSERT
+ obj: books
+ role: reader
+ grant_option: no
# REVOKE INSERT, UPDATE ON ALL TABLES IN SCHEMA public FROM reader
# "public" is the default schema. This also works for PostgreSQL 8.x.
-- postgresql_privs: >
- db=library
- state=absent
- privs=INSERT,UPDATE
- objs=ALL_IN_SCHEMA
- role=reader
+- postgresql_privs:
+ db: library
+ state: absent
+ privs: INSERT,UPDATE
+ objs: ALL_IN_SCHEMA
+ role: reader
# GRANT ALL PRIVILEGES ON SCHEMA public, math TO librarian
-- postgresql_privs: >
- db=library
- privs=ALL
- type=schema
- objs=public,math
- role=librarian
+- postgresql_privs:
+ db: library
+ privs: ALL
+ type: schema
+ objs: public,math
+ role: librarian
# GRANT ALL PRIVILEGES ON FUNCTION math.add(int, int) TO librarian, reader
# Note the separation of arguments with colons.
-- postgresql_privs: >
- db=library
- privs=ALL
- type=function
- obj=add(int:int)
- schema=math
- roles=librarian,reader
+- postgresql_privs:
+ db: library
+ privs: ALL
+ type: function
+ obj: add(int:int)
+ schema: math
+ roles: librarian,reader
# GRANT librarian, reader TO alice, bob WITH ADMIN OPTION
# Note that group role memberships apply cluster-wide and therefore are not
# restricted to database "library" here.
-- postgresql_privs: >
- db=library
- type=group
- objs=librarian,reader
- roles=alice,bob
- admin_option=yes
+- postgresql_privs:
+ db: library
+ type: group
+ objs: librarian,reader
+ roles: alice,bob
+ admin_option: yes
# GRANT ALL PRIVILEGES ON DATABASE library TO librarian
-# Note that here "db=postgres" specifies the database to connect to, not the
+# Note that here "db: postgres" specifies the database to connect to, not the
# database to grant privileges on (which is specified via the "objs" param)
-- postgresql_privs: >
- db=postgres
- privs=ALL
- type=database
- obj=library
- role=librarian
+- postgresql_privs:
+ db: postgres
+ privs: ALL
+ type: database
+ obj: library
+ role: librarian
# GRANT ALL PRIVILEGES ON DATABASE library TO librarian
# If objs is omitted for type "database", it defaults to the database
# to which the connection is established
-- postgresql_privs: >
- db=library
- privs=ALL
- type=database
- role=librarian
+- postgresql_privs:
+ db: library
+ privs: ALL
+ type: database
+ role: librarian
"""
try:
diff --git a/database/postgresql/postgresql_user.py b/database/postgresql/postgresql_user.py
index d8b0b8bb..532e8645 100644
--- a/database/postgresql/postgresql_user.py
+++ b/database/postgresql/postgresql_user.py
@@ -142,22 +142,41 @@ author: "Ansible Core Team"
EXAMPLES = '''
# Create django user and grant access to database and products table
-- postgresql_user: db=acme name=django password=ceec4eif7ya priv=CONNECT/products:ALL
+- postgresql_user:
+ db: acme
+ name: django
+ password: ceec4eif7ya
+ priv: "CONNECT/products:ALL"
# Create rails user, grant privilege to create other databases and demote rails from super user status
-- postgresql_user: name=rails password=secret role_attr_flags=CREATEDB,NOSUPERUSER
+- postgresql_user:
+ name: rails
+ password: secret
+ role_attr_flags: CREATEDB,NOSUPERUSER
# Remove test user privileges from acme
-- postgresql_user: db=acme name=test priv=ALL/products:ALL state=absent fail_on_user=no
+- postgresql_user:
+ db: acme
+ name: test
+ priv: "ALL/products:ALL"
+ state: absent
+ fail_on_user: no
# Remove test user from test database and the cluster
-- postgresql_user: db=test name=test priv=ALL state=absent
+- postgresql_user:
+ db: test
+ name: test
+ priv: ALL
+ state: absent
# Example privileges string format
INSERT,UPDATE/table:SELECT/anothertable:ALL
# Remove an existing user's password
-- postgresql_user: db=test user=test password=NULL
+- postgresql_user:
+ db: test
+ user: test
+ password: NULL
'''
import re
diff --git a/files/acl.py b/files/acl.py
index 2b898452..4974b6bb 100644
--- a/files/acl.py
+++ b/files/acl.py
@@ -97,19 +97,38 @@ notes:
EXAMPLES = '''
# Grant user Joe read access to a file
-- acl: name=/etc/foo.conf entity=joe etype=user permissions="r" state=present
+- acl:
+ name: /etc/foo.conf
+ entity: joe
+ etype: user
+ permissions: r
+ state: present
# Removes the acl for Joe on a specific file
-- acl: name=/etc/foo.conf entity=joe etype=user state=absent
+- acl:
+ name: /etc/foo.conf
+ entity: joe
+ etype: user
+ state: absent
# Sets default acl for joe on foo.d
-- acl: name=/etc/foo.d entity=joe etype=user permissions=rw default=yes state=present
+- acl:
+ name: /etc/foo.d
+ entity: joe
+ etype: user
+ permissions: rw
+ default: yes
+ state: present
# Same as previous but using entry shorthand
-- acl: name=/etc/foo.d entry="default:user:joe:rw-" state=present
+- acl:
+ name: /etc/foo.d
+ entry: "default:user:joe:rw-"
+ state: present
# Obtain the acl for a specific file
-- acl: name=/etc/foo.conf
+- acl:
+ name: /etc/foo.conf
register: acl_info
'''
diff --git a/files/assemble.py b/files/assemble.py
index 39edbdd3..d1d1bb34 100644
--- a/files/assemble.py
+++ b/files/assemble.py
@@ -95,13 +95,21 @@ extends_documentation_fragment:
EXAMPLES = '''
# Example from Ansible Playbooks
-- assemble: src=/etc/someapp/fragments dest=/etc/someapp/someapp.conf
+- assemble:
+ src: /etc/someapp/fragments
+ dest: /etc/someapp/someapp.conf
# When a delimiter is specified, it will be inserted in between each fragment
-- assemble: src=/etc/someapp/fragments dest=/etc/someapp/someapp.conf delimiter='### START FRAGMENT ###'
+- assemble:
+ src: /etc/someapp/fragments
+ dest: /etc/someapp/someapp.conf
+ delimiter: '### START FRAGMENT ###'
# Copy a new "sshd_config" file into place, after passing validation with sshd
-- assemble: src=/etc/ssh/conf.d/ dest=/etc/ssh/sshd_config validate='/usr/sbin/sshd -t -f %s'
+- assemble:
+ src: /etc/ssh/conf.d/
+ dest: /etc/ssh/sshd_config
+ validate: '/usr/sbin/sshd -t -f %s'
'''
import codecs
diff --git a/files/copy.py b/files/copy.py
index d42c285e..000b8ff2 100644
--- a/files/copy.py
+++ b/files/copy.py
@@ -102,19 +102,43 @@ notes:
EXAMPLES = '''
# Example from Ansible Playbooks
-- copy: src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode=0644
+- copy:
+ src: /srv/myfiles/foo.conf
+ dest: /etc/foo.conf
+ owner: foo
+ group: foo
+ mode: 0644
# The same example as above, but using a symbolic mode equivalent to 0644
-- copy: src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode="u=rw,g=r,o=r"
+- copy:
+ src: /srv/myfiles/foo.conf
+ dest: /etc/foo.conf
+ owner: foo
+ group: foo
+ mode: "u=rw,g=r,o=r"
# Another symbolic mode example, adding some permissions and removing others
-- copy: src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode="u+rw,g-wx,o-rwx"
+- copy:
+ src: /srv/myfiles/foo.conf
+ dest: /etc/foo.conf
+ owner: foo
+ group: foo
+ mode: "u+rw,g-wx,o-rwx"
# Copy a new "ntp.conf file into place, backing up the original if it differs from the copied version
-- copy: src=/mine/ntp.conf dest=/etc/ntp.conf owner=root group=root mode=644 backup=yes
+- copy:
+ src: /mine/ntp.conf
+ dest: /etc/ntp.conf
+ owner: root
+ group: root
+ mode: 0644
+ backup: yes
# Copy a new "sudoers" file into place, after passing validation with visudo
-- copy: src=/mine/sudoers dest=/etc/sudoers validate='visudo -cf %s'
+- copy:
+ src: /mine/sudoers
+ dest: /etc/sudoers
+ validate: 'visudo -cf %s'
'''
RETURN = '''
diff --git a/files/fetch.py b/files/fetch.py
index ad349642..9b3f0782 100644
--- a/files/fetch.py
+++ b/files/fetch.py
@@ -65,7 +65,7 @@ options:
will use the basename of the source file, similar to the copy module.
Obviously this is only handy if the filenames are unique.
requirements: []
-author:
+author:
- "Ansible Core Team"
- "Michael DeHaan"
notes:
@@ -79,14 +79,25 @@ notes:
EXAMPLES = '''
# Store file into /tmp/fetched/host.example.com/tmp/somefile
-- fetch: src=/tmp/somefile dest=/tmp/fetched
+- fetch:
+ src: /tmp/somefile
+ dest: /tmp/fetched
# Specifying a path directly
-- fetch: src=/tmp/somefile dest=/tmp/prefix-{{ inventory_hostname }} flat=yes
+- fetch:
+ src: /tmp/somefile
+ dest: /tmp/prefix-{{ inventory_hostname }}
+ flat: yes
# Specifying a destination path
-- fetch: src=/tmp/uniquefile dest=/tmp/special/ flat=yes
+- fetch:
+ src: /tmp/uniquefile
+ dest: /tmp/special/
+ flat: yes
# Storing in a path relative to the playbook
-- fetch: src=/tmp/uniquefile dest=special/prefix-{{ inventory_hostname }} flat=yes
+- fetch:
+ src: /tmp/uniquefile
+ dest: special/prefix-{{ inventory_hostname }}
+ flat: yes
'''
diff --git a/files/file.py b/files/file.py
index f19a9635..b7044ca2 100644
--- a/files/file.py
+++ b/files/file.py
@@ -88,21 +88,42 @@ options:
EXAMPLES = '''
# change file ownership, group and mode. When specifying mode using octal numbers, first digit should always be 0.
-- file: path=/etc/foo.conf owner=foo group=foo mode=0644
-- file: src=/file/to/link/to dest=/path/to/symlink owner=foo group=foo state=link
-- file: src=/tmp/{{ item.src }} dest={{ item.dest }} state=link
+- file:
+ path: /etc/foo.conf
+ owner: foo
+ group: foo
+ mode: 0644
+- file:
+ src: /file/to/link/to
+ dest: /path/to/symlink
+ owner: foo
+ group: foo
+ state: link
+- file:
+ src: /tmp/{{ item.src }}
+ dest: "{{ item.dest }}"
+ state: link
with_items:
- { src: 'x', dest: 'y' }
- { src: 'z', dest: 'k' }
# touch a file, using symbolic modes to set the permissions (equivalent to 0644)
-- file: path=/etc/foo.conf state=touch mode="u=rw,g=r,o=r"
+- file:
+ path: /etc/foo.conf
+ state: touch
+ mode: "u=rw,g=r,o=r"
# touch the same file, but add/remove some permissions
-- file: path=/etc/foo.conf state=touch mode="u+rw,g-wx,o-rwx"
+- file:
+ path: /etc/foo.conf
+ state: touch
+ mode: "u+rw,g-wx,o-rwx"
# create a directory if it doesn't exist
-- file: path=/etc/some_directory state=directory mode=0755
+- file:
+ path: /etc/some_directory
+ state: directory
+ mode: 0755
'''
@@ -217,6 +238,7 @@ def main():
if follow and state == 'link':
# use the current target of the link as the source
src = to_native(os.path.realpath(b_path), errors='strict')
+ b_src = to_bytes(os.path.realpath(b_path), errors='strict')
else:
module.fail_json(msg='src and dest are required for creating links')
diff --git a/files/find.py b/files/find.py
index 9eae9e1b..3fdf2646 100644
--- a/files/find.py
+++ b/files/find.py
@@ -66,7 +66,8 @@ options:
required: false
description:
- Type of file to select
- choices: [ "file", "directory" ]
+ - The 'link' and 'any' choices were added in version 2.3
+ choices: [ "file", "directory", "link", "any" ]
default: "file"
recurse:
required: false
@@ -118,19 +119,37 @@ options:
EXAMPLES = '''
# Recursively find /tmp files older than 2 days
-- find: paths="/tmp" age="2d" recurse=yes
+- find:
+ paths: "/tmp"
+ age: "2d"
+ recurse: yes
# Recursively find /tmp files older than 4 weeks and equal or greater than 1 megabyte
-- find: paths="/tmp" age="4w" size="1m" recurse=yes
+- find:
+ paths: "/tmp"
+ age: "4w"
+ size: "1m"
+ recurse: yes
# Recursively find /var/tmp files with last access time greater than 3600 seconds
-- find: paths="/var/tmp" age="3600" age_stamp=atime recurse=yes
+- find:
+ paths: "/var/tmp"
+ age: "3600"
+ age_stamp: atime
+ recurse: yes
# find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz
-- find: paths="/var/tmp" patterns="*.old,*.log.gz" size="10m"
+- find:
+ paths: "/var/tmp"
+ patterns: "*.old,*.log.gz"
+ size: "10m"
# find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz via regex
-- find: paths="/var/tmp" patterns="^.*?\.(?:old|log\.gz)$" size="10m" use_regex=True
+- find:
+ paths: "/var/tmp"
+ patterns: "^.*?\.(?:old|log\.gz)$"
+ size: "10m"
+ use_regex: True
'''
RETURN = '''
@@ -257,7 +276,7 @@ def main():
paths = dict(required=True, aliases=['name','path'], type='list'),
patterns = dict(default=['*'], type='list', aliases=['pattern']),
contains = dict(default=None, type='str'),
- file_type = dict(default="file", choices=['file', 'directory'], type='str'),
+ file_type = dict(default="file", choices=['file', 'directory', 'link', 'any'], type='str'),
age = dict(default=None, type='str'),
age_stamp = dict(default="mtime", choices=['atime','mtime','ctime'], type='str'),
size = dict(default=None, type='str'),
@@ -313,13 +332,17 @@ def main():
continue
try:
- st = os.stat(fsname)
+ st = os.lstat(fsname)
except:
msg+="%s was skipped as it does not seem to be a valid file or it cannot be accessed\n" % fsname
continue
r = {'path': fsname}
- if stat.S_ISDIR(st.st_mode) and params['file_type'] == 'directory':
+ if params['file_type'] == 'any':
+ if pfilter(fsobj, params['patterns'], params['use_regex']) and agefilter(st, now, age, params['age_stamp']):
+ r.update(statinfo(st))
+ filelist.append(r)
+ elif stat.S_ISDIR(st.st_mode) and params['file_type'] == 'directory':
if pfilter(fsobj, params['patterns'], params['use_regex']) and agefilter(st, now, age, params['age_stamp']):
r.update(statinfo(st))
@@ -336,6 +359,11 @@ def main():
r['checksum'] = module.sha1(fsname)
filelist.append(r)
+ elif stat.S_ISLNK(st.st_mode) and params['file_type'] == 'link':
+ if pfilter(fsobj, params['patterns'], params['use_regex']) and agefilter(st, now, age, params['age_stamp']):
+ r.update(statinfo(st))
+ filelist.append(r)
+
if not params['recurse']:
break
else:
diff --git a/files/ini_file.py b/files/ini_file.py
index 4f74bda5..69f092a1 100644
--- a/files/ini_file.py
+++ b/files/ini_file.py
@@ -80,10 +80,10 @@ options:
create:
required: false
choices: [ "yes", "no" ]
- default: "no"
+ default: "yes"
description:
- - If specified, the file will be created if it does not already exist.
- By default it will fail if the file is missing.
+ - If set to 'no', the module will fail if the file does not already exist.
+ By default it will create the file if it is missing.
version_added: "2.2"
notes:
- While it is possible to add an I(option) without specifying a I(value), this makes
@@ -95,13 +95,20 @@ author:
EXAMPLES = '''
# Ensure "fav=lemonade is in section "[drinks]" in specified file
-- ini_file: dest=/etc/conf section=drinks option=fav value=lemonade mode=0600 backup=yes
+- ini_file:
+ dest: /etc/conf
+ section: drinks
+ option: fav
+ value: lemonade
+ mode: 0600
+ backup: yes
-- ini_file: dest=/etc/anotherconf
- section=drinks
- option=temperature
- value=cold
- backup=yes
+- ini_file:
+ dest: /etc/anotherconf
+ section: drinks
+ option: temperature
+ value: cold
+ backup: yes
'''
import os
@@ -252,7 +259,7 @@ def main():
backup = dict(default='no', type='bool'),
state = dict(default='present', choices=['present', 'absent']),
no_extra_spaces = dict(required=False, default=False, type='bool'),
- create=dict(default=False, type='bool')
+ create=dict(default=True, type='bool')
),
add_file_common_args = True,
supports_check_mode = True
diff --git a/files/lineinfile.py b/files/lineinfile.py
index 045827f7..4b6088c2 100644
--- a/files/lineinfile.py
+++ b/files/lineinfile.py
@@ -120,26 +120,61 @@ options:
"""
EXAMPLES = r"""
-- lineinfile: dest=/etc/selinux/config regexp=^SELINUX= line=SELINUX=enforcing
-
-- lineinfile: dest=/etc/sudoers state=absent regexp="^%wheel"
-
-- lineinfile: dest=/etc/hosts regexp='^127\.0\.0\.1' line='127.0.0.1 localhost' owner=root group=root mode=0644
-
-- lineinfile: dest=/etc/httpd/conf/httpd.conf regexp="^Listen " insertafter="^#Listen " line="Listen 8080"
-
-- lineinfile: dest=/etc/services regexp="^# port for http" insertbefore="^www.*80/tcp" line="# port for http by default"
+- lineinfile:
+ dest: /etc/selinux/config
+ regexp: '^SELINUX='
+ line: 'SELINUX=enforcing'
+
+- lineinfile:
+ dest: /etc/sudoers
+ state: absent
+ regexp: '^%wheel'
+
+- lineinfile:
+ dest: /etc/hosts
+ regexp: '^127\.0\.0\.1'
+ line: '127.0.0.1 localhost'
+ owner: root
+ group: root
+ mode: 0644
+
+- lineinfile:
+ dest: /etc/httpd/conf/httpd.conf
+ regexp: '^Listen '
+ insertafter: '^#Listen '
+ line: 'Listen 8080'
+
+- lineinfile:
+ dest: /etc/services
+ regexp: '^# port for http'
+ insertbefore: '^www.*80/tcp'
+ line: '# port for http by default'
# Add a line to a file if it does not exist, without passing regexp
-- lineinfile: dest=/tmp/testfile line="192.168.1.99 foo.lab.net foo"
+- lineinfile:
+ dest: /tmp/testfile
+ line: '192.168.1.99 foo.lab.net foo'
# Fully quoted because of the ': ' on the line. See the Gotchas in the YAML docs.
-- lineinfile: "dest=/etc/sudoers state=present regexp='^%wheel' line='%wheel ALL=(ALL) NOPASSWD: ALL'"
-
-- lineinfile: dest=/opt/jboss-as/bin/standalone.conf regexp='^(.*)Xms(\d+)m(.*)$' line='\1Xms${xms}m\3' backrefs=yes
+- lineinfile: "
+ dest: /etc/sudoers
+ state: present
+ regexp: '^%wheel'
+ line: '%wheel ALL=(ALL) NOPASSWD: ALL'
+
+- lineinfile:
+ dest: /opt/jboss-as/bin/standalone.conf
+ regexp: '^(.*)Xms(\d+)m(.*)$'
+ line: '\1Xms${xms}m\3'
+ backrefs: yes
# Validate the sudoers file before saving
-- lineinfile: dest=/etc/sudoers state=present regexp='^%ADMIN ALL\=' line='%ADMIN ALL=(ALL) NOPASSWD:ALL' validate='visudo -cf %s'
+- lineinfile:
+ dest: /etc/sudoers
+ state: present
+ regexp: '^%ADMIN ALL='
+ line: '%ADMIN ALL=(ALL) NOPASSWD: ALL'
+ validate: 'visudo -cf %s'
"""
import re
diff --git a/files/replace.py b/files/replace.py
index ef66c223..d4e3ab9f 100644
--- a/files/replace.py
+++ b/files/replace.py
@@ -77,11 +77,24 @@ options:
"""
EXAMPLES = r"""
-- replace: dest=/etc/hosts regexp='(\s+)old\.host\.name(\s+.*)?$' replace='\1new.host.name\2' backup=yes
-
-- replace: dest=/home/jdoe/.ssh/known_hosts regexp='^old\.host\.name[^\n]*\n' owner=jdoe group=jdoe mode=644
-
-- replace: dest=/etc/apache/ports regexp='^(NameVirtualHost|Listen)\s+80\s*$' replace='\1 127.0.0.1:8080' validate='/usr/sbin/apache2ctl -f %s -t'
+- replace:
+ dest: /etc/hosts
+ regexp: '(\s+)old\.host\.name(\s+.*)?$'
+ replace: '\1new.host.name\2'
+ backup: yes
+
+- replace:
+ dest: /home/jdoe/.ssh/known_hosts
+ regexp: '^old\.host\.name[^\n]*\n'
+ owner: jdoe
+ group: jdoe
+ mode: 0644
+
+- replace:
+ dest: /etc/apache/ports
+ regexp: '^(NameVirtualHost|Listen)\s+80\s*$'
+ replace: '\1 127.0.0.1:8080'
+ validate: '/usr/sbin/apache2ctl -f %s -t'
"""
def write_changes(module,contents,dest):
diff --git a/files/stat.py b/files/stat.py
index c07cf699..363e94ad 100644
--- a/files/stat.py
+++ b/files/stat.py
@@ -53,25 +53,35 @@ options:
default: sha1
aliases: [ 'checksum_algo', 'checksum' ]
version_added: "2.0"
- mime:
+ get_mime:
description:
- Use file magic and return data about the nature of the file. this uses
the 'file' utility found on most Linux/Unix systems.
- This will add both `mime_type` and 'charset' fields to the return, if possible.
+ - In 2.3 this option changed from 'mime' to 'get_mime' and the default changed to 'Yes'
required: false
choices: [ Yes, No ]
- default: No
+ default: Yes
version_added: "2.1"
- aliases: [ 'mime_type', 'mime-type' ]
+ aliases: [ 'mime', 'mime_type', 'mime-type' ]
+ get_attributes:
+ description:
+ - Get file attributes using lsattr tool if present.
+ required: false
+ default: True
+ version_added: "2.3"
+ aliases: [ 'attributes', 'attr' ]
author: "Bruce Pennypacker (@bpennypacker)"
'''
EXAMPLES = '''
# Obtain the stats of /etc/foo.conf, and check that the file still belongs
# to 'root'. Fail otherwise.
-- stat: path=/etc/foo.conf
+- stat:
+ path: /etc/foo.conf
register: st
-- fail: msg="Whoops! file ownership has changed"
+- fail:
+ msg: "Whoops! file ownership has changed"
when: st.stat.pw_name != 'root'
# Determine if a path exists and is a symlink. Note that if the path does
@@ -79,35 +89,50 @@ EXAMPLES = '''
# therefore, we must test whether it is defined.
# Run this to understand the structure, the skipped ones do not pass the
# check performed by 'when'
-- stat: path=/path/to/something
+- stat:
+ path: /path/to/something
register: sym
-- debug: msg="islnk isn't defined (path doesn't exist)"
+
+- debug:
+ msg: "islnk isn't defined (path doesn't exist)"
when: sym.stat.islnk is not defined
-- debug: msg="islnk is defined (path must exist)"
+
+- debug:
+ msg: "islnk is defined (path must exist)"
when: sym.stat.islnk is defined
-- debug: msg="Path exists and is a symlink"
+
+- debug:
+ msg: "Path exists and is a symlink"
when: sym.stat.islnk is defined and sym.stat.islnk
-- debug: msg="Path exists and isn't a symlink"
+
+- debug:
+ msg: "Path exists and isn't a symlink"
when: sym.stat.islnk is defined and sym.stat.islnk == False
# 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.
-- stat: path=/path/to/something
+- stat:
+ path: /path/to/something
register: p
-- debug: msg="Path exists and is a directory"
+- debug:
+ msg: "Path exists and is a directory"
when: p.stat.isdir is defined and p.stat.isdir
# Don't do md5 checksum
-- stat: path=/path/to/myhugefile get_md5=no
+- stat:
+ path: /path/to/myhugefile
+ get_md5: no
# Use sha256 to calculate checksum
-- stat: path=/path/to/something checksum_algorithm=sha256
+- stat:
+ path: /path/to/something
+ checksum_algorithm: sha256
'''
RETURN = '''
stat:
- description: dictionary containing all the stat data
+ description: dictionary containing all the stat data, some platforms might add additional fields
returned: success
type: dictionary
contains:
@@ -307,16 +332,25 @@ stat:
returned: success, path exists and user can read the path
type: boolean
sample: False
+ version_added: 2.2
writeable:
description: Tells you if the invoking user has the right to write the path
returned: success, path exists and user can write the path
type: boolean
sample: False
+ version_added: 2.2
executable:
description: Tells you if the invoking user has the execute the path
returned: success, path exists and user can execute the path
type: boolean
sample: False
+ version_added: 2.2
+ attributes:
+ description: list of file attributes
+ returned: success, path exists and user can execute the path
+ type: boolean
+ sample: [ immutable, extent ]
+ version_added: 2.3
'''
import errno
@@ -326,11 +360,10 @@ import pwd
import stat
# import module snippets
-from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.basic import AnsibleModule, format_attributes
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_bytes
-
def format_output(module, path, st):
mode = st.st_mode
@@ -380,7 +413,7 @@ def format_output(module, path, st):
('st_birthtime', 'birthtime'),
# RISCOS
('st_ftype', 'file_type'),
- ('st_attrs', 'attributes'),
+ ('st_attrs', 'attrs'),
('st_obtype', 'object_type'),
# OS X
('st_rsize', 'real_size'),
@@ -401,10 +434,11 @@ def main():
follow=dict(default='no', type='bool'),
get_md5=dict(default='yes', type='bool'),
get_checksum=dict(default='yes', type='bool'),
+ get_mime=dict(default=True, type='bool', aliases=['mime', 'mime_type', 'mime-type']),
+ get_attributes=dict(default=True, type='bool', aliases=['attributes', 'attr']),
checksum_algorithm=dict(default='sha1', type='str',
choices=['sha1', 'sha224', 'sha256', 'sha384', 'sha512'],
aliases=['checksum_algo', 'checksum']),
- mime=dict(default=False, type='bool', aliases=['mime_type', 'mime-type']),
),
supports_check_mode=True
)
@@ -412,7 +446,8 @@ def main():
path = module.params.get('path')
b_path = to_bytes(path, errors='surrogate_or_strict')
follow = module.params.get('follow')
- get_mime = module.params.get('mime')
+ get_mime = module.params.get('get_mime')
+ get_attr = module.params.get('get_attributes')
get_md5 = module.params.get('get_md5')
get_checksum = module.params.get('get_checksum')
checksum_algorithm = module.params.get('checksum_algorithm')
@@ -469,15 +504,27 @@ def main():
# try to get mime data if requested
if get_mime:
output['mimetype'] = output['charset'] = 'unknown'
- filecmd = [module.get_bin_path('file', True), '-i', path]
- try:
- rc, out, err = module.run_command(filecmd)
- if rc == 0:
- mimetype, charset = out.split(':')[1].split(';')
- output['mimetype'] = mimetype.strip()
- output['charset'] = charset.split('=')[1].strip()
- except:
- pass
+ mimecmd = module.get_bin_path('file')
+ if mimecmd:
+ mimecmd = [mimecmd, '-i', path]
+ try:
+ rc, out, err = module.run_command(mimecmd)
+ if rc == 0:
+ mimetype, charset = out.split(':')[1].split(';')
+ output['mimetype'] = mimetype.strip()
+ output['charset'] = charset.split('=')[1].strip()
+ except:
+ pass
+
+ # try to get attr data
+ if get_attr:
+ output['version'] = None
+ output['attributes'] = []
+ output['attr_flags'] = ''
+ out = module.get_file_attributes(path)
+ for x in ('version', 'attributes', 'attr_flags'):
+ if x in out:
+ output[x] = out[x]
module.exit_json(changed=False, stat=output)
diff --git a/files/synchronize.py b/files/synchronize.py
index b48a1f1a..89541840 100644
--- a/files/synchronize.py
+++ b/files/synchronize.py
@@ -185,60 +185,97 @@ author: "Timothy Appnel (@tima)"
EXAMPLES = '''
# Synchronization of src on the control machine to dest on the remote hosts
-synchronize: src=some/relative/path dest=/some/absolute/path
+- synchronize:
+ src: some/relative/path
+ dest: /some/absolute/path
# Synchronization using rsync protocol (push)
-synchronize: src=some/relative/path/ dest=rsync://somehost.com/path/
+- synchronize:
+ src: some/relative/path/
+ dest: rsync://somehost.com/path/
# Synchronization using rsync protocol (pull)
-synchronize: mode=pull src=rsync://somehost.com/path/ dest=/some/absolute/path/
+- synchronize:
+ mode: pull
+ src: rsync://somehost.com/path/
+ dest: /some/absolute/path/
# Synchronization using rsync protocol on delegate host (push)
-synchronize: >
- src=/some/absolute/path/ dest=rsync://somehost.com/path/
- delegate_to: delegate.host
+- synchronize:
+ src: /some/absolute/path/
+ dest: rsync://somehost.com/path/
+ delegate_to: delegate.host
# Synchronization using rsync protocol on delegate host (pull)
-synchronize: >
- mode=pull src=rsync://somehost.com/path/ dest=/some/absolute/path/
- delegate_to: delegate.host
+- synchronize:
+ mode: pull
+ src: rsync://somehost.com/path/
+ dest: /some/absolute/path/
+ delegate_to: delegate.host
# Synchronization without any --archive options enabled
-synchronize: src=some/relative/path dest=/some/absolute/path archive=no
+- synchronize:
+ src: some/relative/path
+ dest: /some/absolute/path
+ archive: no
# Synchronization with --archive options enabled except for --recursive
-synchronize: src=some/relative/path dest=/some/absolute/path recursive=no
+- synchronize:
+ src: some/relative/path
+ dest: /some/absolute/path
+ recursive: no
# Synchronization with --archive options enabled except for --times, with --checksum option enabled
-synchronize: src=some/relative/path dest=/some/absolute/path checksum=yes times=no
+- synchronize:
+ src: some/relative/path
+ dest: /some/absolute/path
+ checksum: yes
+ times: no
# Synchronization without --archive options enabled except use --links
-synchronize: src=some/relative/path dest=/some/absolute/path archive=no links=yes
+- synchronize:
+ src: some/relative/path
+ dest: /some/absolute/path
+ archive: no
+ links: yes
# Synchronization of two paths both on the control machine
-local_action: synchronize src=some/relative/path dest=/some/absolute/path
+- synchronize
+ src: some/relative/path
+ dest: /some/absolute/path
+ delegate_to: localhost
# Synchronization of src on the inventory host to the dest on the localhost in pull mode
-synchronize: mode=pull src=some/relative/path dest=/some/absolute/path
+- synchronize:
+ mode: pull
+ src: some/relative/path
+ dest: /some/absolute/path
# Synchronization of src on delegate host to dest on the current inventory host.
-synchronize:
+- synchronize:
src: /first/absolute/path
dest: /second/absolute/path
-delegate_to: delegate.host
+ delegate_to: delegate.host
# Synchronize two directories on one remote host.
-synchronize:
+- synchronize:
src: /first/absolute/path
dest: /second/absolute/path
-delegate_to: "{{ inventory_hostname }}"
+ delegate_to: "{{ inventory_hostname }}"
# Synchronize and delete files in dest on the remote host that are not found in src of localhost.
-synchronize: src=some/relative/path dest=/some/absolute/path delete=yes recursive=yes
+- synchronize:
+ src: some/relative/path
+ dest: /some/absolute/path
+ delete: yes
+ recursive: yes
# Synchronize using an alternate rsync command
# This specific command is granted su privileges on the destination
-synchronize: src=some/relative/path dest=/some/absolute/path rsync_path="su -c rsync"
+- synchronize:
+ src: some/relative/path
+ dest: /some/absolute/path
+ rsync_path: "su -c rsync"
# Example .rsync-filter file in the source directory
- var # exclude any path whose last part is 'var'
@@ -246,7 +283,7 @@ synchronize: src=some/relative/path dest=/some/absolute/path rsync_path="su -c r
+ /var/conf # include /var/conf even though it was previously excluded
# Synchronize passing in extra rsync options
-synchronize:
+- synchronize:
src: /tmp/helloworld
dest: /var/www/helloworld
rsync_opts:
diff --git a/files/template.py b/files/template.py
index 5ee903a7..c7ff655c 100644
--- a/files/template.py
+++ b/files/template.py
@@ -25,12 +25,12 @@ description:
(U(http://jinja.pocoo.org/docs/)) - documentation on the template
formatting can be found in the Template Designer Documentation
(U(http://jinja.pocoo.org/docs/templates/)).
- - "Six additional variables can be used in templates: C(ansible_managed)
+ - "Six additional variables can be used in templates: C(ansible_managed)
(configurable via the C(defaults) section of C(ansible.cfg)) contains a string
which can be used to describe the template name, host, modification time of the
- template file and the owner uid, C(template_host) contains the node name of
+ template file and the owner uid, C(template_host) contains the node name of
the template's machine, C(template_uid) the owner, C(template_path) the
- absolute path of the template, C(template_fullpath) is the absolute path of the
+ absolute path of the template, C(template_fullpath) is the absolute path of the
template, and C(template_run_date) is the date that the template was rendered. Note that including
a string that uses a date in the template will result in the template being marked 'changed'
each time."
@@ -77,11 +77,24 @@ extends_documentation_fragment:
EXAMPLES = '''
# Example from Ansible Playbooks
-- template: src=/mytemplates/foo.j2 dest=/etc/file.conf owner=bin group=wheel mode=0644
+- template:
+ src: /mytemplates/foo.j2
+ dest: /etc/file.conf
+ owner: bin
+ group: wheel
+ mode: 0644
# The same example, but using symbolic modes equivalent to 0644
-- template: src=/mytemplates/foo.j2 dest=/etc/file.conf owner=bin group=wheel mode="u=rw,g=r,o=r"
+- template:
+ src: /mytemplates/foo.j2
+ dest: /etc/file.conf
+ owner: bin
+ group: wheel
+ mode: "u=rw,g=r,o=r"
# Copy a new "sudoers" file into place, after passing validation with visudo
-- template: src=/mine/sudoers dest=/etc/sudoers validate='visudo -cf %s'
+- template:
+ src: /mine/sudoers
+ dest: /etc/sudoers
+ validate: 'visudo -cf %s'
'''
diff --git a/files/unarchive.py b/files/unarchive.py
index b51d3979..3a69cc33 100644
--- a/files/unarchive.py
+++ b/files/unarchive.py
@@ -114,13 +114,21 @@ notes:
EXAMPLES = '''
# Example from Ansible Playbooks
-- unarchive: src=foo.tgz dest=/var/lib/foo
+- unarchive:
+ src: foo.tgz
+ dest: /var/lib/foo
# Unarchive a file that is already on the remote machine
-- unarchive: src=/tmp/foo.zip dest=/usr/local/bin remote_src=yes
+- unarchive:
+ src: /tmp/foo.zip
+ dest: /usr/local/bin
+ remote_src: yes
# Unarchive a file that needs to be downloaded (added in 2.0)
-- unarchive: src=https://example.com/example.zip dest=/usr/local/bin remote_src=yes
+- unarchive:
+ src: "https://example.com/example.zip"
+ dest: /usr/local/bin
+ remote_src: yes
'''
import re
@@ -339,7 +347,7 @@ class ZipArchive(object):
# Check first and seventh field in order to skip header/footer
if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue
if len(pcs[6]) != 15: continue
-
+
# Possible entries:
# -rw-rws--- 1.9 unx 2802 t- defX 11-Aug-91 13:48 perms.2660
# -rw-a-- 1.0 hpf 5358 Tl i4:3 4-Dec-91 11:33 longfilename.hpfs
diff --git a/files/xattr.py b/files/xattr.py
index 8f12c853..02af9f97 100644
--- a/files/xattr.py
+++ b/files/xattr.py
@@ -63,13 +63,20 @@ author: "Brian Coca (@bcoca)"
EXAMPLES = '''
# Obtain the extended attributes of /etc/foo.conf
-- xattr: name=/etc/foo.conf
+- xattr:
+ name: /etc/foo.conf
# Sets the key 'foo' to value 'bar'
-- xattr: path=/etc/foo.conf key=user.foo value=bar
+- xattr:
+ path: /etc/foo.conf
+ key: user.foo
+ value: bar
# Removes the key 'foo'
-- xattr: name=/etc/foo.conf key=user.foo state=absent
+- xattr:
+ name: /etc/foo.conf
+ key: user.foo
+ state: absent
'''
import operator
diff --git a/inventory/add_host.py b/inventory/add_host.py
index d2873e28..91363121 100644
--- a/inventory/add_host.py
+++ b/inventory/add_host.py
@@ -44,18 +44,24 @@ author:
EXAMPLES = '''
# add host to group 'just_created' with variable foo=42
-- add_host: name={{ ip_from_ec2 }} groups=just_created foo=42
+- add_host:
+ name: "{{ ip_from_ec2 }}"
+ groups: just_created
+ foo: 42
# add a host with a non-standard port local to your machines
-- add_host: name={{ new_ip }}:{{ new_port }}
+- add_host:
+ name: "{{ new_ip }}:{{ new_port }}"
# add a host alias that we reach through a tunnel (Ansible <= 1.9)
-- add_host: hostname={{ new_ip }}
- ansible_ssh_host={{ inventory_hostname }}
- ansible_ssh_port={{ new_port }}
+- add_host:
+ hostname: "{{ new_ip }}"
+ ansible_ssh_host: "{{ inventory_hostname }}"
+ ansible_ssh_port: "{{ new_port }}"
# add a host alias that we reach through a tunnel (Ansible >= 2.0)
-- add_host: hostname={{ new_ip }}
- ansible_host={{ inventory_hostname }}
- ansible_port={{ new_port }}
+- add_host:
+ hostname: "{{ new_ip }}"
+ ansible_host: "{{ inventory_hostname }}"
+ ansible_port: "{{ new_port }}"
'''
diff --git a/inventory/group_by.py b/inventory/group_by.py
index 4bfd2020..28e9a41e 100644
--- a/inventory/group_by.py
+++ b/inventory/group_by.py
@@ -34,7 +34,10 @@ notes:
EXAMPLES = '''
# Create groups based on the machine architecture
-- group_by: key=machine_{{ ansible_machine }}
+- group_by:
+ key: machine_{{ ansible_machine }}
+
# Create groups like 'kvm-host'
-- group_by: key=virt_{{ ansible_virtualization_type }}_{{ ansible_virtualization_role }}
+- group_by:
+ key: virt_{{ ansible_virtualization_type }}_{{ ansible_virtualization_role }}
'''
diff --git a/network/basics/get_url.py b/network/basics/get_url.py
index d2c8da12..e7a5860b 100644
--- a/network/basics/get_url.py
+++ b/network/basics/get_url.py
@@ -227,10 +227,14 @@ def url_get(module, url, dest, use_proxy, last_mod_time, force, timeout=10, head
if info['status'] == 304:
module.exit_json(url=url, dest=dest, changed=False, msg=info.get('msg', ''))
- # create a temporary file and copy content to do checksum-based replacement
+ # Exceptions in fetch_url may result in a status -1, the ensures a proper error to the user in all cases
+ if info['status'] == -1:
+ module.fail_json(msg=info['msg'], url=url, dest=dest)
+
if info['status'] != 200 and not url.startswith('file:/') and not (url.startswith('ftp:/') and info.get('msg', '').startswith('OK')):
module.fail_json(msg="Request failed", status_code=info['status'], response=info['msg'], url=url, dest=dest)
+ # create a temporary file and copy content to do checksum-based replacement
if tmp_dest != '':
# tmp_dest should be an existing dir
tmp_dest_is_dir = os.path.isdir(tmp_dest)
diff --git a/network/basics/uri.py b/network/basics/uri.py
index afff0875..c66ce399 100644
--- a/network/basics/uri.py
+++ b/network/basics/uri.py
@@ -153,20 +153,24 @@ author: "Romeo Theriault (@romeotheriault)"
'''
EXAMPLES = '''
-# Check that you can connect (GET) to a page and it returns a status 200
-- uri: url=http://www.example.com
+- name: Check that you can connect (GET) to a page and it returns a status 200
+ uri:
+ url: 'http://www.example.com'
# Check that a page returns a status 200 and fail if the word AWESOME is not
# in the page contents.
-- action: uri url=http://www.example.com return_content=yes
+- uri:
+ url: http://www.example.com
+ return_content: yes
register: webpage
-- action: fail
+- name: Fail if AWESOME is not in the page content
+ fail:
when: "'AWESOME' not in webpage.content"
-# Create a JIRA issue
-- uri:
+- name: Create a JIRA issue
+ uri:
url: https://your.jira.example.com/rest/api/2/issue/
method: POST
user: your_username
@@ -193,8 +197,8 @@ EXAMPLES = '''
return_content: yes
HEADER_Cookie: "{{login.set_cookie}}"
-# Queue build of a project in Jenkins:
-- uri:
+- name: Queue build of a project in Jenkins
+ uri:
url: "http://{{ jenkins.host }}/job/{{ jenkins.job }}/build?token={{ jenkins.token }}"
method: GET
user: "{{ jenkins.user }}"
diff --git a/network/cumulus/cl_bond.py b/network/cumulus/cl_bond.py
index 52da0bed..958edc7f 100644
--- a/network/cumulus/cl_bond.py
+++ b/network/cumulus/cl_bond.py
@@ -146,33 +146,39 @@ notes:
EXAMPLES = '''
# Options ['virtual_mac', 'virtual_ip'] are required together
# configure a bond interface with IP address
-cl_bond: name=bond0 slaves="swp4-5" ipv4=10.1.1.1/24
-notify: reload networking
+- cl_bond:
+ name: bond0
+ slaves: "swp4-5"
+ ipv4: 10.1.1.1/24
+ notify: reload networking
# configure bond as a dual-connected clag bond
-cl_bond: name=bond1 slaves="swp1s0 swp2s0" clag_id=1
-notify: reload networking
+- cl_bond:
+ name: bond1
+ slaves: "swp1s0 swp2s0"
+ clag_id: 1
+ notify: reload networking
# define cl_bond once in tasks file
# then write interface config in variables file
# with just the options you want.
-cl_bond:
- name: "{{ item.key }}"
- slaves: "{{ item.value.slaves }}"
- clag_id: "{{ item.value.clag_id|default(omit) }}"
- ipv4: "{{ item.value.ipv4|default(omit) }}"
- ipv6: "{{ item.value.ipv6|default(omit) }}"
- alias_name: "{{ item.value.alias_name|default(omit) }}"
- addr_method: "{{ item.value.addr_method|default(omit) }}"
- mtu: "{{ item.value.mtu|default(omit) }}"
- vids: "{{ item.value.vids|default(omit) }}"
- virtual_ip: "{{ item.value.virtual_ip|default(omit) }}"
- virtual_mac: "{{ item.value.virtual_mac|default(omit) }}"
- mstpctl_portnetwork: "{{ item.value.mstpctl_portnetwork|default('no') }}"
- mstpctl_portadminedge: "{{ item.value.mstpctl_portadminedge|default('no') }}"
- mstpctl_bpduguard: "{{ item.value.mstpctl_bpduguard|default('no') }}"
-with_dict: cl_bonds
-notify: reload networking
+- cl_bond:
+ name: "{{ item.key }}"
+ slaves: "{{ item.value.slaves }}"
+ clag_id: "{{ item.value.clag_id|default(omit) }}"
+ ipv4: "{{ item.value.ipv4|default(omit) }}"
+ ipv6: "{{ item.value.ipv6|default(omit) }}"
+ alias_name: "{{ item.value.alias_name|default(omit) }}"
+ addr_method: "{{ item.value.addr_method|default(omit) }}"
+ mtu: "{{ item.value.mtu|default(omit) }}"
+ vids: "{{ item.value.vids|default(omit) }}"
+ virtual_ip: "{{ item.value.virtual_ip|default(omit) }}"
+ virtual_mac: "{{ item.value.virtual_mac|default(omit) }}"
+ mstpctl_portnetwork: "{{ item.value.mstpctl_portnetwork|default('no') }}"
+ mstpctl_portadminedge: "{{ item.value.mstpctl_portadminedge|default('no') }}"
+ mstpctl_bpduguard: "{{ item.value.mstpctl_bpduguard|default('no') }}"
+ with_dict: "{{ cl_bonds }}"
+ notify: reload networking
# In vars file
# ============
diff --git a/network/cumulus/cl_bridge.py b/network/cumulus/cl_bridge.py
index 256fa427..abeb0758 100644
--- a/network/cumulus/cl_bridge.py
+++ b/network/cumulus/cl_bridge.py
@@ -101,40 +101,47 @@ notes:
EXAMPLES = '''
# Options ['virtual_mac', 'virtual_ip'] are required together
# configure a bridge vlan aware bridge.
-cl_bridge: name=br0 ports='swp1-12' vlan_aware='yes'
-notify: reload networking
+- cl_bridge:
+ name: br0
+ ports: 'swp1-12'
+ vlan_aware: 'yes'
+ notify: reload networking
# configure bridge interface to define a default set of vlans
-cl_bridge: name=bridge ports='swp1-12' vlan_aware='yes' vids='1-100'
-notify: reload networking
+- cl_bridge:
+ name: bridge
+ ports: 'swp1-12'
+ vlan_aware: 'yes'
+ vids: '1-100'
+ notify: reload networking
# define cl_bridge once in tasks file
# then write interface config in variables file
# with just the options you want.
-cl_bridge:
- name: "{{ item.key }}"
- ports: "{{ item.value.ports }}"
- vlan_aware: "{{ item.value.vlan_aware|default(omit) }}"
- ipv4: "{{ item.value.ipv4|default(omit) }}"
- ipv6: "{{ item.value.ipv6|default(omit) }}"
- alias_name: "{{ item.value.alias_name|default(omit) }}"
- addr_method: "{{ item.value.addr_method|default(omit) }}"
- mtu: "{{ item.value.mtu|default(omit) }}"
- vids: "{{ item.value.vids|default(omit) }}"
- virtual_ip: "{{ item.value.virtual_ip|default(omit) }}"
- virtual_mac: "{{ item.value.virtual_mac|default(omit) }}"
- mstpctl_treeprio: "{{ item.value.mstpctl_treeprio|default(omit) }}"
-with_dict: cl_bridges
-notify: reload networking
+- cl_bridge:
+ name: "{{ item.key }}"
+ ports: "{{ item.value.ports }}"
+ vlan_aware: "{{ item.value.vlan_aware|default(omit) }}"
+ ipv4: "{{ item.value.ipv4|default(omit) }}"
+ ipv6: "{{ item.value.ipv6|default(omit) }}"
+ alias_name: "{{ item.value.alias_name|default(omit) }}"
+ addr_method: "{{ item.value.addr_method|default(omit) }}"
+ mtu: "{{ item.value.mtu|default(omit) }}"
+ vids: "{{ item.value.vids|default(omit) }}"
+ virtual_ip: "{{ item.value.virtual_ip|default(omit) }}"
+ virtual_mac: "{{ item.value.virtual_mac|default(omit) }}"
+ mstpctl_treeprio: "{{ item.value.mstpctl_treeprio|default(omit) }}"
+ with_dict: "{{ cl_bridges }}"
+ notify: reload networking
# In vars file
# ============
cl_bridge:
- br0:
- alias_name: 'vlan aware bridge'
- ports: ['swp1', 'swp3']
- vlan_aware: true
- vids: ['1-100']
+ br0:
+ alias_name: 'vlan aware bridge'
+ ports: ['swp1', 'swp3']
+ vlan_aware: true
+ vids: ['1-100']
'''
RETURN = '''
diff --git a/network/cumulus/cl_img_install.py b/network/cumulus/cl_img_install.py
index 00e4f903..cfd5f454 100644
--- a/network/cumulus/cl_img_install.py
+++ b/network/cumulus/cl_img_install.py
@@ -59,32 +59,40 @@ Example playbook entries using the cl_img_install module
## Download and install the image from a webserver.
- - name: install image using using http url. Switch slots so the subsequent
- will load the new version
- cl_img_install: version=2.0.1
- src='http://10.1.1.1/CumulusLinux-2.0.1.bin'
- switch_slot=yes
+- name: Install image using using http url. Switch slots so the subsequent will load the new version
+ cl_img_install:
+ version: 2.0.1
+ src: 'http://10.1.1.1/CumulusLinux-2.0.1.bin'
+ switch_slot: yes
## Copy the software from the ansible server to the switch.
## The module will get the code version from the filename
## The code will be installed in the alternate slot but the slot will not be primary
## A subsequent reload will not run the new code
- - name: download cumulus linux to local system
- get_url: src=ftp://cumuluslinux.bin dest=/root/CumulusLinux-2.0.1.bin
+- name: Download cumulus linux to local system
+ get_url:
+ src: 'ftp://cumuluslinux.bin'
+ dest: /root/CumulusLinux-2.0.1.bin
- - name: install image from local filesystem. Get version from the filename
- cl_img_install: src='/root/CumulusLinux-2.0.1.bin'
+- name: Install image from local filesystem. Get version from the filename.
+ cl_img_install:
+ src: /root/CumulusLinux-2.0.1.bin
## If the image name has been changed from the original name, use the `version` option
## to inform the module exactly what code version is been installed
- - name: download cumulus linux to local system
- get_url: src=ftp://CumulusLinux-2.0.1.bin dest=/root/image.bin
+- name: Download cumulus linux to local system
+ get_url:
+ src: 'ftp://CumulusLinux-2.0.1.bin'
+ dest: /root/image.bin
- - name: install image and switch slots. only reboot needed
- cl_img_install: version=2.0.1 src=/root/image.bin switch_slot=yes'
+- name: install image and switch slots. only reboot needed
+ cl_img_install:
+ version: 2.0.1
+ src: /root/image.bin
+ switch_slot: yes
'''
RETURN = '''
diff --git a/network/cumulus/cl_interface.py b/network/cumulus/cl_interface.py
index 3fd87bf9..475f9ce2 100644
--- a/network/cumulus/cl_interface.py
+++ b/network/cumulus/cl_interface.py
@@ -114,45 +114,55 @@ notes:
EXAMPLES = '''
# Options ['virtual_mac', 'virtual_ip'] are required together
-# configure a front panel port with an IP
-cl_interface: name=swp1 ipv4=10.1.1.1/24
-notify: reload networking
-
-# configure front panel to use DHCP
-cl_interface: name=swp2 addr_family=dhcp
-notify: reload networking
-
-# configure a SVI for vlan 100 interface with an IP
-cl_interface: name=bridge.100 ipv4=10.1.1.1/24
-notify: reload networking
-
-# configure subinterface with an IP
-cl_interface: name=bond0.100 alias_name='my bond' ipv4=10.1.1.1/24
-notify: reload networking
+- name: Configure a front panel port with an IP
+ cl_interface:
+ name: swp1
+ ipv4: 10.1.1.1/24
+ notify: reload networking
+
+- name: Configure front panel to use DHCP
+ cl_interface:
+ name: swp2
+ addr_family: dhcp
+ notify: reload networking
+
+- name: Configure a SVI for vlan 100 interface with an IP
+ cl_interface:
+ name: bridge.100
+ ipv4: 10.1.1.1/24
+ notify: reload networking
+
+- name: Configure subinterface with an IP
+ cl_interface:
+ name: bond0.100
+ alias_name: 'my bond'
+ ipv4: 10.1.1.1/24
+ notify: reload networking
# define cl_interfaces once in tasks
# then write interfaces in variables file
# with just the options you want.
-cl_interface:
- name: "{{ item.key }}"
- ipv4: "{{ item.value.ipv4|default(omit) }}"
- ipv6: "{{ item.value.ipv6|default(omit) }}"
- alias_name: "{{ item.value.alias_name|default(omit) }}"
- addr_method: "{{ item.value.addr_method|default(omit) }}"
- speed: "{{ item.value.link_speed|default(omit) }}"
- mtu: "{{ item.value.mtu|default(omit) }}"
- clagd_enable: "{{ item.value.clagd_enable|default(omit) }}"
- clagd_peer_ip: "{{ item.value.clagd_peer_ip|default(omit) }}"
- clagd_sys_mac: "{{ item.value.clagd_sys_mac|default(omit) }}"
- clagd_priority: "{{ item.value.clagd_priority|default(omit) }}"
- vids: "{{ item.value.vids|default(omit) }}"
- virtual_ip: "{{ item.value.virtual_ip|default(omit) }}"
- virtual_mac: "{{ item.value.virtual_mac|default(omit) }}"
- mstpctl_portnetwork: "{{ item.value.mstpctl_portnetwork|default('no') }}"
- mstpctl_portadminedge: "{{ item.value.mstpctl_portadminedge|default('no') }}"
- mstpctl_bpduguard: "{{ item.value.mstpctl_bpduguard|default('no') }}"
-with_dict: cl_interfaces
-notify: reload networking
+ - name: Create interfaces
+ cl_interface:
+ name: "{{ item.key }}"
+ ipv4: "{{ item.value.ipv4 | default(omit) }}"
+ ipv6: "{{ item.value.ipv6 | default(omit) }}"
+ alias_name: "{{ item.value.alias_name | default(omit) }}"
+ addr_method: "{{ item.value.addr_method | default(omit) }}"
+ speed: "{{ item.value.link_speed | default(omit) }}"
+ mtu: "{{ item.value.mtu | default(omit) }}"
+ clagd_enable: "{{ item.value.clagd_enable | default(omit) }}"
+ clagd_peer_ip: "{{ item.value.clagd_peer_ip | default(omit) }}"
+ clagd_sys_mac: "{{ item.value.clagd_sys_mac | default(omit) }}"
+ clagd_priority: "{{ item.value.clagd_priority | default(omit) }}"
+ vids: "{{ item.value.vids | default(omit) }}"
+ virtual_ip: "{{ item.value.virtual_ip | default(omit) }}"
+ virtual_mac: "{{ item.value.virtual_mac | default(omit) }}"
+ mstpctl_portnetwork: "{{ item.value.mstpctl_portnetwork | default('no') }}"
+ mstpctl_portadminedge: "{{ item.value.mstpctl_portadminedge | default('no') }}"
+ mstpctl_bpduguard: "{{ item.value.mstpctl_bpduguard | default('no') }}"
+ with_dict: "{{ cl_interfaces }}"
+ notify: reload networking
# In vars file
diff --git a/network/cumulus/cl_license.py b/network/cumulus/cl_license.py
index 7690d8ac..8097cda5 100644
--- a/network/cumulus/cl_license.py
+++ b/network/cumulus/cl_license.py
@@ -55,33 +55,37 @@ options:
'''
EXAMPLES = '''
-Example playbook using the cl_license module to manage licenses on Cumulus Linux
-
----
- - hosts: all
- tasks:
- - name: install license using http url
- cl_license: src='http://10.1.1.1/license.txt'
- notify: restart switchd
-
- - name: Triggers switchd to be restarted right away, before play, or role
- is over. This is desired behaviour
- meta: flush_handlers
-
- - name: configure interfaces
- template: src=interfaces.j2 dest=/etc/network/interfaces
- notify: restart networking
-
- handlers:
- - name: restart switchd
- service: name=switchd state=restarted
- - name: restart networking
- service: name=networking state=reloaded
-
-----
+# Example playbook using the cl_license module to manage licenses on Cumulus Linux
+
+- hosts: all
+ tasks:
+ - name: install license using http url
+ cl_license:
+ src: 'http://10.1.1.1/license.txt'
+ notify: restart switchd
+
+ - name: Triggers switchd to be restarted right away, before play, or role
+ is over. This is desired behaviour
+ meta: flush_handlers
+
+ - name: Configure interfaces
+ template:
+ src: interfaces.j2
+ dest: /etc/network/interfaces
+ notify: restart networking
+
+ handlers:
+ - name: restart switchd
+ service:
+ name: switchd
+ state: restarted
+ - name: restart networking
+ service:
+ name: networking
+ state: reloaded
# Force all switches to accept a new license. Typically not needed
-ansible -m cl_license -a "src='http://10.1.1.1/new_lic' force=yes" -u root all
+ansible -m cl_license -a "src='http://10.1.1.1/new_lic' force=yes" -u root all
----
diff --git a/network/cumulus/cl_ports.py b/network/cumulus/cl_ports.py
index 02728203..9ed48089 100644
--- a/network/cumulus/cl_ports.py
+++ b/network/cumulus/cl_ports.py
@@ -48,7 +48,9 @@ attributes defined in the ports.conf file on Cumulus Linux
## Unganged port config using simple args
- name: configure ports.conf setup
- cl_ports: speed_4_by_10g="swp1, swp32" speed_40g="swp2-31"
+ cl_ports:
+ speed_4_by_10g: "swp1, swp32"
+ speed_40g: "swp2-31"
notify: restart switchd
## Unganged port configuration on certain ports using complex args
diff --git a/network/ios/ios_command.py b/network/ios/ios_command.py
index c5923e4e..4204a73a 100644
--- a/network/ios/ios_command.py
+++ b/network/ios/ios_command.py
@@ -148,6 +148,12 @@ from ansible.module_utils.six import string_types
VALID_KEYS = ['command', 'prompt', 'response']
+def to_lines(stdout):
+ for item in stdout:
+ if isinstance(item, string_types):
+ item = str(item).split('\n')
+ yield item
+
def parse_commands(module):
for cmd in module.params['commands']:
if isinstance(cmd, string_types):
@@ -210,9 +216,7 @@ def main():
module.fail_json(msg=str(exc), failed_conditions=exc.failed_conditions)
except NetworkError:
exc = get_exception()
- module.disconnect()
- module.fail_json(msg=str(exc), stdout=exc.kwargs.get('stdout'))
-
+ module.fail_json(msg=str(exc))
result = dict(changed=False, stdout=list())
@@ -224,6 +228,7 @@ def main():
result['stdout'].append(output)
result['warnings'] = warnings
+ result['stdout_lines'] = list(to_lines(result['stdout']))
module.exit_json(**result)
diff --git a/network/ios/ios_config.py b/network/ios/ios_config.py
index 4f6786ee..6c07d2cf 100644
--- a/network/ios/ios_config.py
+++ b/network/ios/ios_config.py
@@ -391,7 +391,7 @@ def main():
except NetworkError:
exc = get_exception()
module.disconnect()
- module.fail_json(msg=str(exc), stdout=exc.kwargs.get('stdout'))
+ module.fail_json(msg=str(exc))
module.disconnect()
module.exit_json(**result)
diff --git a/network/junos/junos_config.py b/network/junos/junos_config.py
index f0814a0b..af013476 100644
--- a/network/junos/junos_config.py
+++ b/network/junos/junos_config.py
@@ -242,7 +242,7 @@ def load_config(module, result):
kwargs['commit'] = not module.check_mode
if module.params['src']:
- config_format = module.params['src_format'] or guess_format(candidate)
+ config_format = module.params['src_format'] or guess_format(str(candidate))
elif module.params['lines']:
config_format = 'set'
kwargs['config_format'] = config_format
diff --git a/network/junos/junos_facts.py b/network/junos/junos_facts.py
index 1e6973dd..d321b9f1 100644
--- a/network/junos/junos_facts.py
+++ b/network/junos/junos_facts.py
@@ -44,12 +44,12 @@ options:
- The C(config_format) argument is used to specify the desired
format of the configuration file. Devices support three
configuration file formats. By default, the configuration
- from the device is returned as text. The other options include
- set and xml. If the xml option is chosen, the configuration file
- is returned as both xml and json.
+ from the device is returned as text. The other option xml.
+ If the xml option is chosen, the configuration file is
+ returned as both xml and json.
required: false
default: text
- choices: ['xml', 'text', 'set']
+ choices: ['xml', 'text']
requirements:
- junos-eznc
notes:
@@ -68,10 +68,10 @@ EXAMPLES = """
junos_facts:
config: yes
-- name: collect default set of facts and configuration in set format
+- name: collect default set of facts and configuration in text format
junos_facts:
config: yes
- config_format: set
+ config_format: text
- name: collect default set of facts and configuration in XML and JSON format
junos_facts:
@@ -95,7 +95,7 @@ def main():
"""
spec = dict(
config=dict(type='bool'),
- config_format=dict(default='text', choices=['xml', 'set', 'text']),
+ config_format=dict(default='text', choices=['xml', 'text']),
transport=dict(default='netconf', choices=['netconf'])
)
@@ -116,7 +116,7 @@ def main():
config_format = module.params['config_format']
resp_config = module.config.get_config(config_format=config_format)
- if config_format in ['text', 'set']:
+ if config_format in ['text']:
facts['config'] = resp_config
elif config_format == "xml":
facts['config'] = xml_to_string(resp_config)
diff --git a/network/nxos/nxos_bgp.py b/network/nxos/nxos_bgp.py
index 5ec5135b..18ca8402 100644
--- a/network/nxos/nxos_bgp.py
+++ b/network/nxos/nxos_bgp.py
@@ -286,8 +286,8 @@ options:
EXAMPLES = '''
-# configure a simple asn
-- nxos_bgp:
+- name: Configure a simple ASN
+ nxos_bgp:
asn: 65535
vrf: test
router_id: 1.1.1.1
@@ -757,7 +757,7 @@ def state_present(module, existing, proposed, candidate):
elif value is False:
commands.append('no {0}'.format(key))
elif value == 'default':
- if key in PARAM_TO_DEFAULT_KEYMAP.keys():
+ if key in PARAM_TO_DEFAULT_KEYMAP:
commands.append('{0} {1}'.format(key, PARAM_TO_DEFAULT_KEYMAP[key]))
elif existing_commands.get(key):
existing_value = existing_commands.get(key)
diff --git a/network/nxos/nxos_bgp_af.py b/network/nxos/nxos_bgp_af.py
index 0eb920f3..1f02b113 100644
--- a/network/nxos/nxos_bgp_af.py
+++ b/network/nxos/nxos_bgp_af.py
@@ -889,7 +889,7 @@ def state_present(module, existing, proposed, candidate):
commands.append('no {0}'.format(key))
elif value == 'default':
- if key in PARAM_TO_DEFAULT_KEYMAP.keys():
+ if key in PARAM_TO_DEFAULT_KEYMAP:
commands.append('{0} {1}'.format(key, PARAM_TO_DEFAULT_KEYMAP[key]))
elif existing_commands.get(key):
diff --git a/network/nxos/nxos_feature.py b/network/nxos/nxos_feature.py
index 15d49cc7..a00c71a4 100644
--- a/network/nxos/nxos_feature.py
+++ b/network/nxos/nxos_feature.py
@@ -41,12 +41,24 @@ options:
'''
EXAMPLES = '''
-# Ensure lacp is enabled
-- nxos_feature: feature=lacp state=enabled host={{ inventory_hostname }}
-# Ensure ospf is disabled
-- nxos_feature: feature=ospf state=disabled host={{ inventory_hostname }}
-# Ensure vpc is enabled
-- nxos_feature: feature=vpc state=enabled host={{ inventory_hostname }}
+- name: Ensure lacp is enabled
+ nxos_feature:
+ feature: lacp
+ state: enabled
+ host: "{{ inventory_hostname }}"
+
+- name: Ensure ospf is disabled
+ nxos_feature:
+ feature: ospf
+ state: disabled
+ host: "{{ inventory_hostname }}"
+
+- name: Ensure vpc is enabled
+ nxos_feature:
+ feature: vpc
+ state: enabled
+ host: "{{ inventory_hostname }}"
+
'''
RETURN = '''
@@ -355,7 +367,7 @@ def get_available_features(feature, module):
if 'enabled' in state:
state = 'enabled'
- if feature not in available_features.keys():
+ if feature not in available_features:
available_features[feature] = state
else:
if (available_features[feature] == 'disabled' and
@@ -443,7 +455,7 @@ def main():
state = module.params['state'].lower()
available_features = get_available_features(feature, module)
- if feature not in available_features.keys():
+ if feature not in available_features:
module.fail_json(
msg='Invalid feature name.',
features_currently_supported=available_features,
diff --git a/network/nxos/nxos_hsrp.py b/network/nxos/nxos_hsrp.py
index d21fcaa6..ec6e5893 100644
--- a/network/nxos/nxos_hsrp.py
+++ b/network/nxos/nxos_hsrp.py
@@ -81,12 +81,33 @@ options:
'''
EXAMPLES = '''
-# ensure hsrp is configured with following params on a SVI
-- nxos_hsrp: group=10 vip=10.1.1.1 priority=150 interface=vlan10 preempt=enabled host=68.170.147.165
-# ensure hsrp is configured with following params on a SVI
-- nxos_hsrp: group=10 vip=10.1.1.1 priority=150 interface=vlan10 preempt=enabled host=68.170.147.165 auth_type=text auth_string=CISCO
-# removing hsrp config for given interface, group, and vip
-- nxos_hsrp: group=10 interface=vlan10 vip=10.1.1.1 host=68.170.147.165 state=absent
+- name: Ensure HSRP is configured with following params on a SVI
+ nxos_hsrp:
+ group: 10
+ vip: 10.1.1.1
+ priority: 150
+ interface: vlan10
+ preempt: enabled
+ host: 68.170.147.165
+
+- name: Ensure HSRP is configured with following params on a SVI
+ nxos_hsrp:
+ group: 10
+ vip: 10.1.1.1
+ priority: 150
+ interface: vlan10
+ preempt: enabled
+ host: 68.170.147.165
+ auth_type: text
+ auth_string: CISCO
+
+- name: Remove HSRP config for given interface, group, and VIP
+ nxos_hsrp:
+ group: 10
+ interface: vlan10
+ vip: 10.1.1.1
+ host: 68.170.147.165
+ state: absent
'''
RETURN = '''
diff --git a/network/nxos/nxos_igmp.py b/network/nxos/nxos_igmp.py
index 05827a34..d1ac322c 100644
--- a/network/nxos/nxos_igmp.py
+++ b/network/nxos/nxos_igmp.py
@@ -61,24 +61,21 @@ options:
choices: ['present', 'default']
'''
EXAMPLES = '''
-# default igmp global params (all params except restart)
-- nxos_igmp: state=default host={{ inventory_hostname }}
-# ensure the following igmp global config exists on the device
-- nxos_igmp: flush_routes=true enforce_rtr_alert=true host={{ inventory_hostname }}
-# restart the igmp process
-- nxos_igmp: restart=true host={{ inventory_hostname }}
-'''
-
-EXAMPLES = '''
-# configure a simple asn
-- nxos_bgp:
- asn=65535
- vrf=test
- router_id=1.1.1.1
- state=present
- username: "{{ un }}"
- password: "{{ pwd }}"
- host: "{{ inventory_hostname }}"
+- name: Default igmp global params (all params except restart)
+ nxos_igmp:
+ state: default
+ host: "{{ inventory_hostname }}"
+
+- name: Ensure the following igmp global config exists on the device
+ nxos_igmp:
+ flush_routes: true
+ enforce_rtr_alert: true
+ host: "{{ inventory_hostname }}"
+
+- name: Restart the igmp process
+ nxos_igmp:
+ restart: true
+ host: "{{ inventory_hostname }}"
'''
RETURN = '''
diff --git a/network/nxos/nxos_igmp_interface.py b/network/nxos/nxos_igmp_interface.py
index 1f5aa5d9..902d5808 100644
--- a/network/nxos/nxos_igmp_interface.py
+++ b/network/nxos/nxos_igmp_interface.py
@@ -823,7 +823,7 @@ def main():
if state == 'absent':
for each in CANNOT_ABSENT:
- if each in proposed.keys():
+ if each in proposed:
module.fail_json(msg='only params: oif_prefix, oif_source, '
'oif_routemap can be used when '
'state=absent')
diff --git a/network/nxos/nxos_interface.py b/network/nxos/nxos_interface.py
index 7c1186ee..ac1c773d 100644
--- a/network/nxos/nxos_interface.py
+++ b/network/nxos/nxos_interface.py
@@ -85,23 +85,47 @@ options:
'''
EXAMPLES = '''
-# Ensure an interface is a Layer 3 port and that it has the proper description
-- nxos_interface: interface=Ethernet1/1 description='Configured by Ansible' mode=layer3 host=68.170.147.165
-# Admin down an interface
-- nxos_interface: interface=Ethernet2/1 host=68.170.147.165 admin_state=down
-# Remove all loopback interfaces
-- nxos_interface: interface=loopback state=absent host=68.170.147.165
-# Remove all logical interfaces
-- nxos_interface: interface_type={{ item }} state=absent host={{ inventory_hostname }}
+- name Ensure an interface is a Layer 3 port and that it has the proper description
+ nxos_interface:
+ interface: Ethernet1/1
+ description: 'Configured by Ansible'
+ mode: layer3
+ host: 68.170.147.165
+
+- name Admin down an interface
+ nxos_interface:
+ interface: Ethernet2/1
+ host: 68.170.147.165
+ admin_state: down
+
+- name Remove all loopback interfaces
+ nxos_interface:
+ interface: loopback
+ state: absent
+ host: 68.170.147.165
+
+- name Remove all logical interfaces
+ nxos_interface:
+ interface_type: "{{ item }} "
+ state: absent
+ host: "{{ inventory_hostname }}"
+
with_items:
- loopback
- portchannel
- svi
- nve
-# Admin up all ethernet interfaces
-- nxos_interface: interface=ethernet host=68.170.147.165 admin_state=up
-# Admin down ALL interfaces (physical and logical)
-- nxos_interface: interface=all host=68.170.147.165 admin_state=down
+- name Admin up all ethernet interfaces
+ nxos_interface:
+ interface: ethernet
+ host: 68.170.147.165
+ admin_state: up
+
+- name Admin down ALL interfaces (physical and logical)
+ nxos_interface:
+ interface: all
+ host: 68.170.147.165
+ admin_state: down
'''
RETURN = '''
proposed:
diff --git a/network/nxos/nxos_interface_ospf.py b/network/nxos/nxos_interface_ospf.py
index 5cf050e8..2e5a291d 100644
--- a/network/nxos/nxos_interface_ospf.py
+++ b/network/nxos/nxos_interface_ospf.py
@@ -118,7 +118,7 @@ EXAMPLES = '''
interface: ethernet1/32
ospf: 1
area: 1
- cost=default
+ cost: default
username: "{{ un }}"
password: "{{ pwd }}"
host: "{{ inventory_hostname }}"
diff --git a/network/nxos/nxos_ip_interface.py b/network/nxos/nxos_ip_interface.py
index eef79543..416ebadd 100644
--- a/network/nxos/nxos_ip_interface.py
+++ b/network/nxos/nxos_ip_interface.py
@@ -57,10 +57,23 @@ options:
'''
EXAMPLES = '''
-# ensure ipv4 address is configured on Ethernet1/32
-- nxos_ip_interface: interface=Ethernet1/32 transport=nxapi version=v4 state=present addr=20.20.20.20 mask=24
-# ensure ipv6 address is configured on Ethernet1/31
-- nxos_ip_interface: interface=Ethernet1/31 transport=cli version=v6 state=present addr=2001::db8:800:200c:cccb mask=64
+- name: Ensure ipv4 address is configured on Ethernet1/32
+ nxos_ip_interface:
+ interface: Ethernet1/32
+ transport: nxapi
+ version: v4
+ state: present
+ addr: 20.20.20.20
+ mask: 24
+
+- name: Ensure ipv6 address is configured on Ethernet1/31
+ nxos_ip_interface:
+ interface: Ethernet1/31
+ transport: cli
+ version: v6
+ state: present
+ addr: '2001::db8:800:200c:cccb'
+ mask: 64
'''
RETURN = '''
@@ -560,7 +573,7 @@ def get_config_ip_commands(delta, interface, existing, version):
# loop used in the situation that just an IP address or just a
# mask is changing, not both.
for each in ['addr', 'mask']:
- if each not in delta.keys():
+ if each not in delta:
delta[each] = existing[each]
if version == 'v4':
diff --git a/network/nxos/nxos_ping.py b/network/nxos/nxos_ping.py
index ea4ecb68..5764de8f 100644
--- a/network/nxos/nxos_ping.py
+++ b/network/nxos/nxos_ping.py
@@ -50,10 +50,17 @@ options:
'''
EXAMPLES = '''
-# test reachability to 8.8.8.8 using mgmt vrf
-- nxos_ping: dest=8.8.8.8 vrf=management host=68.170.147.165
-# Test reachability to a few different public IPs using mgmt vrf
-- nxos_ping: dest=nxos_ping vrf=management host=68.170.147.165
+- name: Test reachability to 8.8.8.8 using mgmt vrf
+ nxos_ping:
+ dest: 8.8.8.8
+ vrf: management
+ host: 68.170.147.165
+
+- name: Test reachability to a few different public IPs using mgmt vrf
+ nxos_ping:
+ dest: nxos_ping
+ vrf: management
+ host: 68.170.147.165
with_items:
- 8.8.8.8
- 4.4.4.4
diff --git a/network/nxos/nxos_static_route.py b/network/nxos/nxos_static_route.py
index 10a1f849..a0e2a78b 100644
--- a/network/nxos/nxos_static_route.py
+++ b/network/nxos/nxos_static_route.py
@@ -321,7 +321,7 @@ def get_existing(module, prefix, warnings):
group_route = match_route.groupdict()
for key in key_map:
- if key not in group_route.keys():
+ if key not in group_route:
group_route[key] = ''
group_route['prefix'] = prefix
group_route['vrf'] = module.params['vrf']
diff --git a/network/nxos/nxos_switchport.py b/network/nxos/nxos_switchport.py
index 387c7c7c..006a2dcd 100644
--- a/network/nxos/nxos_switchport.py
+++ b/network/nxos/nxos_switchport.py
@@ -79,16 +79,42 @@ options:
default: null
'''
EXAMPLES = '''
-# ENSURE Eth1/5 is in its default switchport state
-- nxos_switchport: interface=eth1/5 state=unconfigured host={{ inventory_hostname }}
-# ENSURE Eth1/5 is configured for access vlan 20
-- nxos_switchport: interface=eth1/5 mode=access access_vlan=20 host={{ inventory_hostname }}
-# ENSURE Eth1/5 only has vlans 5-10 as trunk vlans
-- nxos_switchport: interface=eth1/5 mode=trunk native_vlan=10 trunk_vlans=5-10 host={{ inventory_hostname }}
-# Ensure eth1/5 is a trunk port and ensure 2-50 are being tagged (doesn't mean others aren't also being tagged)
-- nxos_switchport: interface=eth1/5 mode=trunk native_vlan=10 trunk_vlans=2-50 host={{ inventory_hostname }}
-# Ensure these VLANs are not being tagged on the trunk
-- nxos_switchport: interface=eth1/5 mode=trunk trunk_vlans=51-4094 host={{ inventory_hostname }} state=absent
+- name: Ensure Eth1/5 is in its default switchport state
+ nxos_switchport:
+ interface: eth1/5
+ state: unconfigured
+ host: "{{ inventory_hostname }}"
+
+- name: Ensure Eth1/5 is configured for access vlan 20
+ nxos_switchport:
+ interface: eth1/5
+ mode: access
+ access_vlan: 20
+ host: "{{ inventory_hostname }}"
+
+- name: Ensure Eth1/5 only has vlans 5-10 as trunk vlans
+ nxos_switchport:
+ interface: eth1/5
+ mode: trunk
+ native_vlan: 10
+ trunk_vlans: 5-10
+ host: "{{ inventory_hostname }}"
+
+- name: Ensure eth1/5 is a trunk port and ensure 2-50 are being tagged (doesn't mean others aren't also being tagged)
+ nxos_switchport:
+ interface: eth1/5
+ mode: trunk
+ native_vlan: 10
+ trunk_vlans: 2-50
+ host: "{{ inventory_hostname }}"
+
+- name: Ensure these VLANs are not being tagged on the trunk
+ nxos_switchport:
+ interface: eth1/5
+ mode: trunk
+ trunk_vlans: 51-4094
+ host: "{{ inventory_hostname }} "
+ state: absent
'''
RETURN = '''
diff --git a/network/nxos/nxos_vlan.py b/network/nxos/nxos_vlan.py
index cb06bd84..184d8b49 100644
--- a/network/nxos/nxos_vlan.py
+++ b/network/nxos/nxos_vlan.py
@@ -71,16 +71,33 @@ options:
'''
EXAMPLES = '''
-# Ensure a range of VLANs are not present on the switch
-- nxos_vlan: vlan_range="2-10,20,50,55-60,100-150" host=68.170.147.165 username=cisco password=cisco state=absent transport=nxapi
-
-# Ensure VLAN 50 exists with the name WEB and is in the shutdown state
-- nxos_vlan: vlan_id=50 host=68.170.147.165 admin_state=down name=WEB transport=nxapi username=cisco password=cisco
-
-# Ensure VLAN is NOT on the device
-- nxos_vlan: vlan_id=50 host=68.170.147.165 state=absent transport=nxapi username=cisco password=cisco
-
-
+- name: Ensure a range of VLANs are not present on the switch
+ nxos_vlan:
+ vlan_range: "2-10,20,50,55-60,100-150"
+ host: 68.170.147.165
+ username: cisco
+ password: cisco
+ state: absent
+ transport: nxapi
+
+- name: Ensure VLAN 50 exists with the name WEB and is in the shutdown state
+ nxos_vlan:
+ vlan_id: 50
+ host: 68.170.147.165
+ admin_state: down
+ name: WEB
+ transport: nxapi
+ username: cisco
+ password: cisco
+
+- name: Ensure VLAN is NOT on the device
+ nxos_vlan:
+ vlan_id: 50
+ host: 68.170.147.165
+ state: absent
+ transport: nxapi
+ username: cisco
+ password: cisco
'''
RETURN = '''
diff --git a/network/nxos/nxos_vpc_interface.py b/network/nxos/nxos_vpc_interface.py
index dcc1c213..0f930cac 100644
--- a/network/nxos/nxos_vpc_interface.py
+++ b/network/nxos/nxos_vpc_interface.py
@@ -501,7 +501,7 @@ def main():
if vpc:
mapping = get_existing_portchannel_to_vpc_mappings(module)
- if vpc in mapping.keys() and portchannel != mapping[vpc].strip('Po'):
+ if vpc in mapping and portchannel != mapping[vpc].strip('Po'):
module.fail_json(msg="This vpc is already configured on "
"another portchannel. Remove it first "
"before trying to assign it here. ",
diff --git a/network/nxos/nxos_vrf.py b/network/nxos/nxos_vrf.py
index 8c8c2c17..8dde538f 100644
--- a/network/nxos/nxos_vrf.py
+++ b/network/nxos/nxos_vrf.py
@@ -76,8 +76,12 @@ options:
'''
EXAMPLES = '''
-# ensure ntc VRF exists on switch
-- nxos_vrf: vrf=ntc username="{{ un }}" password="{{ pwd }}" host="{{ inventory_hostname }}"
+- name: Ensure ntc VRF exists on switch
+ nxos_vrf:
+ vrf: ntc
+ username: "{{ un }}"
+ password: "{{ pwd }}"
+ host: "{{ inventory_hostname }}"
'''
RETURN = '''
diff --git a/network/nxos/nxos_vrf_interface.py b/network/nxos/nxos_vrf_interface.py
index fe80c0f8..cd3c5704 100644
--- a/network/nxos/nxos_vrf_interface.py
+++ b/network/nxos/nxos_vrf_interface.py
@@ -52,10 +52,19 @@ options:
'''
EXAMPLES = '''
-# ensure vrf ntc exists on Eth1/1
-- nxos_vrf_interface: vrf=ntc interface=Ethernet1/1 host=68.170.147.165 state=present
-# ensure ntc VRF does not exist on Eth1/1
-- nxos_vrf_interface: vrf=ntc interface=Ethernet1/1 host=68.170.147.165 state=absent
+- name: Ensure vrf ntc exists on Eth1/1
+ nxos_vrf_interface:
+ vrf: ntc
+ interface: Ethernet1/1
+ host: 68.170.147.165
+ state: present
+
+- name: Ensure ntc VRF does not exist on Eth1/1
+ nxos_vrf_interface:
+ vrf: ntc
+ interface: Ethernet1/1
+ host: 68.170.147.165
+ state: absent
'''
RETURN = '''
diff --git a/network/nxos/nxos_vrrp.py b/network/nxos/nxos_vrrp.py
index c389a90d..a034b0e2 100644
--- a/network/nxos/nxos_vrrp.py
+++ b/network/nxos/nxos_vrrp.py
@@ -74,12 +74,31 @@ options:
'''
EXAMPLES = '''
-# ensure vrrp group 100 and vip 10.1.100.1 is on vlan10
-- nxos_vrrp: interface=vlan10 group=100 vip=10.1.100.1 host=68.170.147.165
-# ensure removal of the vrrp group config # vip is required to ensure the user knows what they are removing
-- nxos_vrrp: interface=vlan10 group=100 vip=10.1.100.1 state=absent host=68.170.147.165
-# re-config with more params
-- nxos_vrrp: interface=vlan10 group=100 vip=10.1.100.1 preempt=false priority=130 authentication=AUTHKEY host=68.170.147.165
+- name: Ensure vrrp group 100 and vip 10.1.100.1 is on vlan10
+ nxos_vrrp:
+ interface: vlan10
+ group: 100
+ vip: 10.1.100.1
+ host: 68.170.147.165
+
+- name: Ensure removal of the vrrp group config
+ # vip is required to ensure the user knows what they are removing
+ nxos_vrrp:
+ interface: vlan10
+ group: 100
+ vip: 10.1.100.1
+ state: absent
+ host: 68.170.147.165
+
+- name: Re-config with more params
+ nxos_vrrp:
+ interface: vlan10
+ group: 100
+ vip: 10.1.100.1
+ preempt: false
+ priority: 130
+ authentication: AUTHKEY
+ host: 68.170.147.165
'''
RETURN = '''
diff --git a/network/vyos/vyos_command.py b/network/vyos/vyos_command.py
index 4c24e9e7..cced7b2c 100644
--- a/network/vyos/vyos_command.py
+++ b/network/vyos/vyos_command.py
@@ -28,6 +28,10 @@ description:
to validate key parameters before returning successfully. If the
conditional statements are not met in the wait period, the task
fails.
+ - Certain C(show) commands in VyOS produce many lines of output and
+ use a custom pager that can cause this module to hang. If the
+ value of the environment variable C(ANSIBLE_VYOS_TERMINAL_LENGTH)
+ is not set, the default number of 10000 is used.
extends_documentation_fragment: vyos
options:
commands:
@@ -43,15 +47,15 @@ options:
- Specifies what to evaluate from the output of the command
and what conditionals to apply. This argument will cause
the task to wait for a particular conditional to be true
- before moving forward. If the conditional is not true
- by the configured I(retries), the task fails. See examples.
+ before moving forward. If the conditional is not true
+ by the configured I(retries), the task fails. See examples.
required: false
default: null
aliases: ['waitfor']
match:
description:
- The I(match) argument is used in conjunction with the
- I(wait_for) argument to specify the match policy. Valid
+ I(wait_for) argument to specify the match policy. Valid
values are C(all) or C(any). If the value is set to C(all)
then all conditionals in the wait_for must be satisfied. If
the value is set to C(any) then only one of the values must be
@@ -75,6 +79,10 @@ options:
trying the command again.
required: false
default: 1
+
+notes:
+ - Running C(show system boot-messages all) will cause the module to hang since
+ VyOS is using a custom pager setting to display the output of that command.
"""
EXAMPLES = """
diff --git a/packaging/language/easy_install.py b/packaging/language/easy_install.py
index 017f6b81..96d21ea8 100644
--- a/packaging/language/easy_install.py
+++ b/packaging/language/easy_install.py
@@ -90,10 +90,14 @@ author: "Matt Wright (@mattupstate)"
EXAMPLES = '''
# Examples from Ansible Playbooks
-- easy_install: name=pip state=latest
+- easy_install:
+ name: pip
+ state: latest
# Install Bottle into the specified virtualenv.
-- easy_install: name=bottle virtualenv=/webapps/myapp/venv
+- easy_install:
+ name: bottle
+ virtualenv: /webapps/myapp/venv
'''
def _is_package_installed(module, name, easy_install, executable_arguments):
diff --git a/packaging/language/gem.py b/packaging/language/gem.py
index acd088dc..18884159 100644
--- a/packaging/language/gem.py
+++ b/packaging/language/gem.py
@@ -97,13 +97,21 @@ author:
EXAMPLES = '''
# Installs version 1.0 of vagrant.
-- gem: name=vagrant version=1.0 state=present
+- gem:
+ name: vagrant
+ version: 1.0
+ state: present
# Installs latest available version of rake.
-- gem: name=rake state=latest
+- gem:
+ name: rake
+ state: latest
# Installs rake version 1.0 from a local gem on disk.
-- gem: name=rake gem_source=/path/to/gems/rake-1.0.gem state=present
+- gem:
+ name: rake
+ gem_source: /path/to/gems/rake-1.0.gem
+ state: present
'''
import re
diff --git a/packaging/language/pip.py b/packaging/language/pip.py
index 7c8aa8cb..e49e2750 100755
--- a/packaging/language/pip.py
+++ b/packaging/language/pip.py
@@ -142,46 +142,73 @@ author: "Matt Wright (@mattupstate)"
EXAMPLES = '''
# Install (Bottle) python package.
-- pip: name=bottle
+- pip:
+ name: bottle
# Install (Bottle) python package on version 0.11.
-- pip: name=bottle version=0.11
+- pip:
+ name: bottle
+ version: 0.11
# Install (MyApp) using one of the remote protocols (bzr+,hg+,git+,svn+). You do not have to supply '-e' option in extra_args.
-- pip: name='svn+http://myrepo/svn/MyApp#egg=MyApp'
+- pip:
+ name: 'svn+http://myrepo/svn/MyApp#'
+ egg: MyApp'
# Install MyApp using one of the remote protocols (bzr+,hg+,git+) in a non editable way.
-- pip: name='git+http://myrepo/app/MyApp' editable=false
+- pip:
+ name: 'git+http://myrepo/app/MyApp'
+ editable: false
# Install (MyApp) from local tarball
-- pip: name='file:///path/to/MyApp.tar.gz'
+- pip:
+ name: 'file:///path/to/MyApp.tar.gz'
# Install (Bottle) into the specified (virtualenv), inheriting none of the globally installed modules
-- pip: name=bottle virtualenv=/my_app/venv
+- pip:
+ name: bottle
+ virtualenv: /my_app/venv
# Install (Bottle) into the specified (virtualenv), inheriting globally installed modules
-- pip: name=bottle virtualenv=/my_app/venv virtualenv_site_packages=yes
+- pip:
+ name: bottle
+ virtualenv: /my_app/venv
+ virtualenv_site_packages: yes
# Install (Bottle) into the specified (virtualenv), using Python 2.7
-- pip: name=bottle virtualenv=/my_app/venv virtualenv_command=virtualenv-2.7
+- pip:
+ name: bottle
+ virtualenv: /my_app/venv
+ virtualenv_command: virtualenv-2.7
# Install specified python requirements.
-- pip: requirements=/my_app/requirements.txt
+- pip:
+ requirements: /my_app/requirements.txt
# Install specified python requirements in indicated (virtualenv).
-- pip: requirements=/my_app/requirements.txt virtualenv=/my_app/venv
+- pip:
+ requirements: /my_app/requirements.txt
+ virtualenv: /my_app/venv
# Install specified python requirements and custom Index URL.
-- pip: requirements=/my_app/requirements.txt extra_args='-i https://example.com/pypi/simple'
+- pip:
+ requirements: /my_app/requirements.txt
+ extra_args: '-i https://example.com/pypi/simple'
# Install (Bottle) for Python 3.3 specifically,using the 'pip-3.3' executable.
-- pip: name=bottle executable=pip-3.3
+- pip:
+ name: bottle
+ executable: pip-3.3
# Install (Bottle), forcing reinstallation if it's already installed
-- pip: name=bottle state=forcereinstall
+- pip:
+ name: bottle
+ state: forcereinstall
# Install (Bottle) while ensuring the umask is 0022 (to ensure other users can use it)
-- pip: name=bottle umask=0022
+- pip:
+ name: bottle
+ umask: 0022
become: True
'''
diff --git a/packaging/os/apt.py b/packaging/os/apt.py
index 20306cd6..5d20dbee 100644
--- a/packaging/os/apt.py
+++ b/packaging/os/apt.py
@@ -177,7 +177,7 @@ EXAMPLES = '''
apt:
upgrade: dist
update_cache: yes
- dpkg_options: force-confold,force-confdef
+ dpkg_options: 'force-confold,force-confdef'
- name: Install a .deb package
apt:
diff --git a/packaging/os/apt_key.py b/packaging/os/apt_key.py
index 516255e1..753fb830 100644
--- a/packaging/os/apt_key.py
+++ b/packaging/os/apt_key.py
@@ -83,28 +83,47 @@ options:
EXAMPLES = '''
# Add an apt key by id from a keyserver
-- apt_key: keyserver=keyserver.ubuntu.com id=36A1D7869245C8950F966E92D8576A8BA88D21E9
+- apt_key:
+ keyserver: keyserver.ubuntu.com
+ id: 36A1D7869245C8950F966E92D8576A8BA88D21E9
# Add an Apt signing key, uses whichever key is at the URL
-- apt_key: url=https://ftp-master.debian.org/keys/archive-key-6.0.asc state=present
+- apt_key:
+ url: "https://ftp-master.debian.org/keys/archive-key-6.0.asc"
+ state: present
# Add an Apt signing key, will not download if present
-- apt_key: id=473041FA url=https://ftp-master.debian.org/keys/archive-key-6.0.asc state=present
+- apt_key:
+ id: 473041FA
+ url: "https://ftp-master.debian.org/keys/archive-key-6.0.asc"
+ state: present
# Remove an Apt signing key, uses whichever key is at the URL
-- apt_key: url=https://ftp-master.debian.org/keys/archive-key-6.0.asc state=absent
+- apt_key:
+ url: "https://ftp-master.debian.org/keys/archive-key-6.0.asc"
+ state: absent
# Remove a Apt specific signing key, leading 0x is valid
-- apt_key: id=0x473041FA state=absent
+- apt_key:
+ id: 0x473041FA
+ state: absent
# Add a key from a file on the Ansible server
-- apt_key: data="{{ lookup('file', 'apt.gpg') }}" state=present
+- apt_key:
+ data: "{{ lookup('file', 'apt.gpg') }}"
+ state: present
# Add an Apt signing key to a specific keyring file
-- apt_key: id=473041FA url=https://ftp-master.debian.org/keys/archive-key-6.0.asc keyring=/etc/apt/trusted.gpg.d/debian.gpg state=present
+- apt_key:
+ id: 473041FA
+ url: "https://ftp-master.debian.org/keys/archive-key-6.0.asc"
+ keyring: /etc/apt/trusted.gpg.d/debian.gpg
# Add Apt signing key on remote server to keyring
-- apt_key: id=473041FA file=/tmp/apt.gpg state=present
+- apt_key:
+ id: 473041FA
+ file: /tmp/apt.gpg
+ state: present
'''
diff --git a/packaging/os/apt_repository.py b/packaging/os/apt_repository.py
index dac098da..aedf1cb2 100644
--- a/packaging/os/apt_repository.py
+++ b/packaging/os/apt_repository.py
@@ -84,22 +84,36 @@ requirements:
EXAMPLES = '''
# Add specified repository into sources list.
-apt_repository: repo='deb http://archive.canonical.com/ubuntu hardy partner' state=present
+- apt_repository:
+ repo: 'deb http://archive.canonical.com/ubuntu hardy partner'
+ state: present
# Add specified repository into sources list using specified filename.
-apt_repository: repo='deb http://dl.google.com/linux/chrome/deb/ stable main' state=present filename='google-chrome'
+- apt_repository:
+ repo: 'deb http://dl.google.com/linux/chrome/deb/ stable main'
+ state: present
+ filename: 'google-chrome'
# Add source repository into sources list.
-apt_repository: repo='deb-src http://archive.canonical.com/ubuntu hardy partner' state=present
+- apt_repository:
+ repo: 'deb-src http://archive.canonical.com/ubuntu hardy partner'
+ state: present
# Remove specified repository from sources list.
-apt_repository: repo='deb http://archive.canonical.com/ubuntu hardy partner' state=absent
+- apt_repository:
+ repo: 'deb http://archive.canonical.com/ubuntu hardy partner'
+ state: absent
# Add nginx stable repository from PPA and install its signing key.
# On Ubuntu target:
-apt_repository: repo='ppa:nginx/stable'
+- apt_repository:
+ repo: 'ppa:nginx/stable'
+
# On Debian target
-apt_repository: repo='ppa:nginx/stable' codename='trusty'
+- apt_repository:
+ repo: 'ppa:nginx/stable'
+ codename: 'trusty'
+ repo: 'ppa:nginx/stable'
'''
import glob
diff --git a/packaging/os/apt_rpm.py b/packaging/os/apt_rpm.py
index 59eccfee..e8a702e9 100755
--- a/packaging/os/apt_rpm.py
+++ b/packaging/os/apt_rpm.py
@@ -50,13 +50,25 @@ notes: []
EXAMPLES = '''
# install package foo
-- apt_rpm: pkg=foo state=present
+- apt_rpm:
+ pkg: foo
+ state: present
+
# remove package foo
-- apt_rpm: pkg=foo state=absent
-# description: remove packages foo and bar
-- apt_rpm: pkg=foo,bar state=absent
-# description: update the package database and install bar (bar will be the updated if a newer version exists)
-- apt_rpm: name=bar state=present update_cache=yes
+- apt_rpm:
+ pkg: foo
+ state: absent
+
+# description: remove packages foo and bar
+- apt_rpm:
+ pkg: foo,bar
+ state: absent
+
+# description: update the package database and install bar (bar will be the updated if a newer version exists)
+- apt_rpm:
+ name: bar
+ state: present
+ update_cache: yes
'''
diff --git a/packaging/os/package.py b/packaging/os/package.py
index 2ae7c7fb..d40ed3d4 100644
--- a/packaging/os/package.py
+++ b/packaging/os/package.py
@@ -53,9 +53,13 @@ notes:
'''
EXAMPLES = '''
- name: install the latest version of ntpdate
- package: name=ntpdate state=latest
+ package:
+ name: ntpdate
+ state: latest
# This uses a variable as this changes per distribution.
- name: remove the apache package
- package: name={{apache}} state=absent
+ package:
+ name: "{{ apache }}"
+ state: absent
'''
diff --git a/packaging/os/redhat_subscription.py b/packaging/os/redhat_subscription.py
index 2bef4cbb..ea56ac55 100644
--- a/packaging/os/redhat_subscription.py
+++ b/packaging/os/redhat_subscription.py
@@ -114,30 +114,41 @@ options:
EXAMPLES = '''
# Register as user (joe_user) with password (somepass) and auto-subscribe to available content.
-- redhat_subscription: state=present username=joe_user password=somepass autosubscribe=true
+- redhat_subscription:
+ state: present
+ username: joe_user
+ password: somepass
+ autosubscribe: true
# Same as above but with pulling existing system data.
-- redhat_subscription: state=present username=joe_user password=somepass
- consumer_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+- redhat_subscription:
+ state: present
+ username: joe_user
+ password: somepass
+ consumer_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
# Register with activationkey (1-222333444) and consume subscriptions matching
# the names (Red hat Enterprise Server) and (Red Hat Virtualization)
-- redhat_subscription: state=present
- activationkey=1-222333444
- pool='^(Red Hat Enterprise Server|Red Hat Virtualization)$'
+- redhat_subscription:
+ state: present
+ activationkey: 1-222333444
+ pool: '^(Red Hat Enterprise Server|Red Hat Virtualization)$'
# Update the consumed subscriptions from the previous example (remove the Red
# Hat Virtualization subscription)
-- redhat_subscription: state=present
- activationkey=1-222333444
- pool='^Red Hat Enterprise Server$'
+- redhat_subscription:
+ state: present
+ activationkey: 1-222333444
+ pool: '^Red Hat Enterprise Server$'
# Register as user credentials into given environment (against Red Hat
# Satellite 6.x), and auto-subscribe to available content.
-- redhat_subscription: state=present
- username=joe_user password=somepass
- environment=Library
- autosubscribe=true
+- redhat_subscription:
+ state: present
+ username: joe_user
+ password: somepass
+ environment: Library
+ autosubscribe: yes
'''
import os
diff --git a/packaging/os/rhn_channel.py b/packaging/os/rhn_channel.py
index 00711831..9ec24483 100644
--- a/packaging/os/rhn_channel.py
+++ b/packaging/os/rhn_channel.py
@@ -26,7 +26,7 @@ description:
version_added: "1.1"
author: "Vincent Van der Kussen (@vincentvdk)"
notes:
- - this module fetches the system id from RHN.
+ - this module fetches the system id from RHN.
requirements:
- none
options:
@@ -46,7 +46,7 @@ options:
required: false
default: present
url:
- description:
+ description:
- The full url to the RHN/Satellite api
required: true
user:
@@ -60,7 +60,12 @@ options:
'''
EXAMPLES = '''
-- rhn_channel: name=rhel-x86_64-server-v2vwin-6 sysname=server01 url=https://rhn.redhat.com/rpc/api user=rhnuser password=guessme
+- rhn_channel:
+ name: rhel-x86_64-server-v2vwin-6
+ sysname: server01
+ url: 'https://rhn.redhat.com/rpc/api'
+ user: rhnuser
+ password: guessme
'''
import xmlrpclib
diff --git a/packaging/os/rhn_register.py b/packaging/os/rhn_register.py
index f30cf090..1a99fed8 100644
--- a/packaging/os/rhn_register.py
+++ b/packaging/os/rhn_register.py
@@ -83,30 +83,44 @@ options:
EXAMPLES = '''
# Unregister system from RHN.
-- rhn_register: state=absent username=joe_user password=somepass
+- rhn_register:
+ state: absent
+ username: joe_user
+ password: somepass
# Register as user (joe_user) with password (somepass) and auto-subscribe to available content.
-- rhn_register: state=present username=joe_user password=somepass
+- rhn_register:
+ state: present
+ username: joe_user
+ password: somepass
# Register with activationkey (1-222333444) and enable extended update support.
-- rhn_register: state=present activationkey=1-222333444 enable_eus=true
+- rhn_register:
+ state: present
+ activationkey: 1-222333444
+ enable_eus: true
# Register with activationkey (1-222333444) and set a profilename which may differ from the hostname.
-- rhn_register: state=present activationkey=1-222333444 profilename=host.example.com.custom
+- rhn_register:
+ state: present
+ activationkey: 1-222333444
+ profilename: host.example.com.custom
# Register as user (joe_user) with password (somepass) against a satellite
# server specified by (server_url).
-- rhn_register: >
- state=present
- username=joe_user
- password=somepass
- server_url=https://xmlrpc.my.satellite/XMLRPC
+- rhn_register:
+ state: present
+ username: joe_user
+ password: somepass'
+ server_url: 'https://xmlrpc.my.satellite/XMLRPC'
# Register as user (joe_user) with password (somepass) and enable
# channels (rhel-x86_64-server-6-foo-1) and (rhel-x86_64-server-6-bar-1).
-- rhn_register: state=present username=joe_user
- password=somepass
- channels=rhel-x86_64-server-6-foo-1,rhel-x86_64-server-6-bar-1
+- rhn_register:
+ state: present
+ username: joe_user
+ password: somepass
+ channels: rhel-x86_64-server-6-foo-1,rhel-x86_64-server-6-bar-1
'''
import sys
@@ -147,9 +161,10 @@ class Rhn(RegistrationBase):
# configuration. Yeah, I know this should be subclassed ... but, oh
# well
def get_option_default(self, key, default=''):
- # ignore pep8 W601 errors for this line
- # setting this to use 'in' does not work in the rhn library
- if self.has_key(key):
+ # the class in rhn-client-tools that this comes from didn't
+ # implement __contains__() until 2.5.x. That's why we check if
+ # the key is present in the dictionary that is the actual storage
+ if key in self.dict:
return self[key]
else:
return default
diff --git a/packaging/os/rpm_key.py b/packaging/os/rpm_key.py
index 4899d5cd..19f36419 100644
--- a/packaging/os/rpm_key.py
+++ b/packaging/os/rpm_key.py
@@ -52,13 +52,19 @@ options:
EXAMPLES = '''
# Example action to import a key from a url
-- rpm_key: state=present key=http://apt.sw.be/RPM-GPG-KEY.dag.txt
+- rpm_key:
+ state: present
+ key: 'http://apt.sw.be/RPM-GPG-KEY.dag.txt'
# Example action to import a key from a file
-- rpm_key: state=present key=/path/to/key.gpg
+- rpm_key:
+ state: present
+ key: /path/to/key.gpg
# Example action to ensure a key is not present in the db
-- rpm_key: state=absent key=DEADB33F
+- rpm_key:
+ state: absent
+ key: DEADB33F
'''
import re
import os.path
diff --git a/packaging/os/yum.py b/packaging/os/yum.py
index 7356880f..cc9b0040 100644
--- a/packaging/os/yum.py
+++ b/packaging/os/yum.py
@@ -156,31 +156,50 @@ author:
EXAMPLES = '''
- name: install the latest version of Apache
- yum: name=httpd state=latest
+ yum:
+ name: httpd
+ state: latest
- name: remove the Apache package
- yum: name=httpd state=absent
+ yum:
+ name: httpd
+ state: absent
- name: install the latest version of Apache from the testing repo
- yum: name=httpd enablerepo=testing state=present
+ yum:
+ name: httpd
+ enablerepo: testing
+ state: present
- name: install one specific version of Apache
- yum: name=httpd-2.2.29-1.4.amzn1 state=present
+ yum:
+ name: httpd-2.2.29-1.4.amzn1
+ state: present
- name: upgrade all packages
- yum: name=* state=latest
+ yum:
+ name: '*'
+ state: latest
- name: install the nginx rpm from a remote repo
- yum: name=http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm state=present
+ yum:
+ name: 'http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm'
+ state: present
- name: install nginx rpm from a local file
- yum: name=/usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm state=present
+ yum:
+ name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
+ state: present
- name: install the 'Development tools' package group
- yum: name="@Development tools" state=present
+ yum:
+ name: "@Development tools"
+ state: present
- name: install the 'Gnome desktop' environment group
- yum: name="@^gnome-desktop-environment" state=present
+ yum:
+ name: "@^gnome-desktop-environment"
+ state: present
'''
# 64k. Number of bytes to read at a time when manually downloading pkgs via a url
@@ -858,7 +877,7 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
# or virtual provides (like "python-*" or "smtp-daemon") while
# updates contains name only.
this_name_only = '-'.join(this.split('-')[:-2])
- if spec in pkgs['update'] and this_name_only in updates.keys():
+ if spec in pkgs['update'] and this_name_only in updates:
nothing_to_do = False
will_update.add(spec)
# Massage the updates list
diff --git a/source_control/git.py b/source_control/git.py
index 06965f03..7b076576 100644
--- a/source_control/git.py
+++ b/source_control/git.py
@@ -194,22 +194,35 @@ notes:
EXAMPLES = '''
# Example git checkout from Ansible Playbooks
-- git: repo=git://foosball.example.org/path/to/repo.git
- dest=/srv/checkout
- version=release-0.22
+- git:
+ repo: 'git://foosball.example.org/path/to/repo.git'
+ dest: /srv/checkout
+ version: release-0.22
# Example read-write git checkout from github
-- git: repo=ssh://git@github.com/mylogin/hello.git dest=/home/mylogin/hello
+- git:
+ repo: 'ssh://git@github.com/mylogin/hello.git'
+ dest: /home/mylogin/hello
# Example just ensuring the repo checkout exists
-- git: repo=git://foosball.example.org/path/to/repo.git dest=/srv/checkout update=no
+- git:
+ repo: 'git://foosball.example.org/path/to/repo.git'
+ dest: /srv/checkout
+ update: no
# Example just get information about the repository whether or not it has
# already been cloned locally.
-- git: repo=git://foosball.example.org/path/to/repo.git dest=/srv/checkout clone=no update=no
+- git:
+ repo: 'git://foosball.example.org/path/to/repo.git'
+ dest: /srv/checkout
+ clone: no
+ update: no
# Example checkout a github repo and use refspec to fetch all pull requests
-- git: repo=https://github.com/ansible/ansible-examples.git dest=/src/ansible-examples refspec=+refs/pull/*:refs/heads/*
+- git:
+ repo: 'https://github.com/ansible/ansible-examples.git'
+ dest: /src/ansible-examples
+ refspec: '+refs/pull/*:refs/heads/*'
'''
import os
@@ -971,8 +984,7 @@ def main():
remote_url_changed = remote_url and remote_url != repo and remote_url != unfrackgitpath(repo)
else:
remote_url_changed = set_remote_url(git_path, module, repo, dest, remote)
- if remote_url_changed:
- result.update(remote_url_changed=True)
+ result.update(remote_url_changed=remote_url_changed)
if need_fetch:
if module.check_mode:
diff --git a/source_control/hg.py b/source_control/hg.py
index e0e50e2c..effc8a7c 100644
--- a/source_control/hg.py
+++ b/source_control/hg.py
@@ -95,11 +95,19 @@ requirements: [ ]
EXAMPLES = '''
# Ensure the current working copy is inside the stable branch and deletes untracked files if any.
-- hg: repo=https://bitbucket.org/user/repo1 dest=/home/user/repo1 revision=stable purge=yes
+- hg:
+ repo: 'https://bitbucket.org/user/repo1'
+ dest: /home/user/repo1
+ revision: stable
+ purge: yes
# Example just get information about the repository whether or not it has
# already been cloned locally.
-- hg: repo=git://bitbucket.org/user/repo dest=/srv/checkout clone=no update=no
+- hg:
+ repo: 'git://bitbucket.org/user/repo'
+ dest: /srv/checkout
+ clone: no
+ update: no
'''
import os
diff --git a/source_control/subversion.py b/source_control/subversion.py
index 449cd3cd..49a0e22f 100644
--- a/source_control/subversion.py
+++ b/source_control/subversion.py
@@ -104,14 +104,22 @@ options:
EXAMPLES = '''
# Checkout subversion repository to specified folder.
-- subversion: repo=svn+ssh://an.example.org/path/to/repo dest=/src/checkout
+- subversion:
+ repo: 'svn+ssh://an.example.org/path/to/repo'
+ dest: /src/checkout
# Export subversion directory to folder
-- subversion: repo=svn+ssh://an.example.org/path/to/repo dest=/src/export export=True
+- subversion:
+ repo: 'svn+ssh://an.example.org/path/to/repo'
+ dest: /src/export
# Example just get information about the repository whether or not it has
# already been cloned locally.
-- subversion: repo=svn+ssh://an.example.org/path/to/repo dest=/srv/checkout checkout=no update=no
+- subversion:
+ repo: 'svn+ssh://an.example.org/path/to/repo'
+ dest: /srv/checkout
+ checkout: no
+ update: no
'''
import re
diff --git a/system/authorized_key.py b/system/authorized_key.py
index 084ce95f..6cfd856e 100644
--- a/system/authorized_key.py
+++ b/system/authorized_key.py
@@ -92,21 +92,27 @@ author: "Ansible Core Team"
EXAMPLES = '''
# Example using key data from a local file on the management machine
-- authorized_key: user=charlie key="{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}"
+- authorized_key:
+ user: charlie
+ key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}"
# Using github url as key source
-- authorized_key: user=charlie key=https://github.com/charlie.keys
+- authorized_key:
+ user: charlie
+ key: 'https://github.com/charlie.keys'
# Using alternate directory locations:
- authorized_key:
user: charlie
key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}"
- path: '/etc/ssh/authorized_keys/charlie'
+ path: /etc/ssh/authorized_keys/charlie
manage_dir: no
# Using with_file
- name: Set up authorized_keys for the deploy user
- authorized_key: user=deploy key="{{ item }}"
+ authorized_key:
+ user: deploy
+ key: "{{ item }}"
with_file:
- public_keys/doe-jane
- public_keys/doe-john
@@ -114,19 +120,28 @@ EXAMPLES = '''
# Using key_options:
- authorized_key:
user: charlie
- key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}"
+ key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}"
key_options: 'no-port-forwarding,from="10.0.1.1"'
# Using validate_certs:
-- authorized_key: user=charlie key=https://github.com/user.keys validate_certs=no
+- authorized_key:
+ user: charlie
+ key: 'https://github.com/user.keys'
+ validate_certs: no
# Set up authorized_keys exclusively with one key
-- authorized_key: user=root key="{{ item }}" state=present exclusive=yes
+- authorized_key:
+ user: root
+ key: "{{ item }}"
+ state: present
+ exclusive: yes
with_file:
- public_keys/doe-jane
# Copies the key from the user who is running ansible to the remote machine user ubuntu
-- authorized_key: user=ubuntu key="{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
+- authorized_key:
+ user: ubuntu
+ key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
become: yes
'''
diff --git a/system/cron.py b/system/cron.py
index 2ab23ef6..9dd5b5c9 100644
--- a/system/cron.py
+++ b/system/cron.py
@@ -171,32 +171,59 @@ author:
EXAMPLES = '''
# Ensure a job that runs at 2 and 5 exists.
# 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
# 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"
-- 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
-- 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
# 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
-- cron: name="yum autoupdate" weekday="2" minute=0 hour=12
- user="root" job="YUMINTERACTIVE=0 /usr/sbin/yum-autoupdate"
- cron_file=ansible_yum-autoupdate
+- cron:
+ name: 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
-- 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
-- cron: name=APP_HOME env=yes state=absent
+- cron:
+ name: APP_HOME
+ env: yes
+ state: absent
'''
import os
diff --git a/system/group.py b/system/group.py
index f6628727..ceffd753 100644
--- a/system/group.py
+++ b/system/group.py
@@ -53,7 +53,9 @@ options:
EXAMPLES = '''
# Example group command from Ansible Playbooks
-- group: name=somegroup state=present
+- group:
+ name: somegroup
+ state: present
'''
import grp
@@ -144,7 +146,7 @@ class SunOS(Group):
This overrides the following methods from the generic class:-
- group_add()
- """
+ """
platform = 'SunOS'
distribution = None
@@ -269,6 +271,11 @@ class DarwinGroup(Group):
cmd += [ '-o', 'create' ]
if self.gid is not None:
cmd += [ '-i', self.gid ]
+ elif 'system' in kwargs and kwargs['system'] == True:
+ gid = self.get_lowest_available_system_gid()
+ if gid != False:
+ self.gid = str(gid)
+ cmd += [ '-i', self.gid ]
cmd += [ '-L', self.name ]
(rc, out, err) = self.execute_command(cmd)
return (rc, out, err)
@@ -291,6 +298,26 @@ class DarwinGroup(Group):
(rc, out, err) = self.execute_command(cmd)
return (rc, out, err)
return (None, '', '')
+
+ def get_lowest_available_system_gid(self):
+ # check for lowest available system gid (< 500)
+ try:
+ cmd = [self.module.get_bin_path('dscl', True)]
+ cmd += [ '/Local/Default', '-list', '/Groups', 'PrimaryGroupID']
+ (rc, out, err) = self.execute_command(cmd)
+ lines = out.splitlines()
+ highest = 0
+ for group_info in lines:
+ parts = group_info.split(' ')
+ if len(parts) > 1:
+ gid = int(parts[-1])
+ if gid > highest and gid < 500:
+ highest = gid
+ if highest == 0 or highest == 499:
+ return False
+ return (highest + 1)
+ except:
+ return False
class OpenBsdGroup(Group):
"""
diff --git a/system/hostname.py b/system/hostname.py
index 4c4285f6..92fd6758 100644
--- a/system/hostname.py
+++ b/system/hostname.py
@@ -40,7 +40,8 @@ options:
'''
EXAMPLES = '''
-- hostname: name=web01
+- hostname:
+ name: web01
'''
import socket
diff --git a/system/mount.py b/system/mount.py
index ea76a0a9..1d7fa8ac 100644
--- a/system/mount.py
+++ b/system/mount.py
@@ -308,6 +308,15 @@ def unset_mount(module, args):
return (args['name'], changed)
+def _set_fstab_args(args):
+ result = []
+ if 'fstab' in args and args['fstab'] != '/etc/fstab':
+ if get_platform().lower().endswith('bsd'):
+ result.append('-F')
+ else:
+ result.append('-T')
+ result.append(args['fstab'])
+ return result
def mount(module, args):
"""Mount up a path or remount if needed."""
@@ -317,13 +326,9 @@ def mount(module, args):
cmd = [mount_bin]
if ismount(name):
- cmd += ['-o', 'remount']
+ return remount(module, mount_bin, args)
- if args['fstab'] != '/etc/fstab':
- if get_platform() == 'FreeBSD':
- cmd += ['-F', args['fstab']]
- elif get_platform() == 'Linux':
- cmd += ['-T', args['fstab']]
+ cmd += _set_fstab_args(args)
cmd += [name]
@@ -348,6 +353,40 @@ def umount(module, dest):
else:
return rc, out+err
+def remount(module, mount_bin, args):
+ ''' will try to use -o remount first and fallback to unmount/mount if unsupported'''
+ msg = ''
+ cmd = [mount_bin]
+
+ # multiplatform remount opts
+ if get_platform().lower().endswith('bsd'):
+ cmd += ['-u']
+ else:
+ cmd += ['-o', 'remount' ]
+
+ cmd += _set_fstab_args(args)
+ cmd += [ args['name'], ]
+ out = err = ''
+ try:
+ if get_platform().lower().endswith('bsd'):
+ # Note: Forcing BSDs to do umount/mount due to BSD remount not
+ # working as expected (suspect bug in the BSD mount command)
+ # Interested contributor could rework this to use mount options on
+ # the CLI instead of relying on fstab
+ # https://github.com/ansible/ansible-modules-core/issues/5591
+ rc = 1
+ else:
+ rc, out, err = module.run_command(cmd)
+ except:
+ rc = 1
+
+ if rc != 0:
+ msg = out + err
+ if ismount(args['name']):
+ rc, msg = umount(module, args['name'])
+ if rc == 0:
+ rc, msg = mount(module, args)
+ return rc, msg
# Note if we wanted to put this into module_utils we'd have to get permission
# from @jupeter -- https://github.com/ansible/ansible-modules-core/pull/2923
@@ -369,7 +408,7 @@ def is_bind_mounted(module, linux_mounts, dest, src=None, fstype=None):
is_mounted = False
- if get_platform() == 'Linux':
+ if get_platform() == 'Linux' and linux_mounts is not None:
if src is None:
# That's for unmounted/absent
if dest in linux_mounts:
@@ -410,7 +449,7 @@ def get_linux_mounts(module):
try:
f = open(mntinfo_file)
except IOError:
- module.fail_json(msg="Cannot open file %s" % mntinfo_file)
+ return
lines = map(str.strip, f.readlines())
@@ -575,6 +614,11 @@ def main():
if get_platform() == 'Linux':
linux_mounts = get_linux_mounts(module)
+ if linux_mounts is None:
+ args['warnings'] = (
+ 'Cannot open file /proc/self/mountinfo. '
+ 'Bind mounts might be misinterpreted.')
+
# Override defaults with user specified params
for key in ('src', 'fstype', 'passno', 'opts', 'dump', 'fstab'):
if module.params[key] is not None:
@@ -650,8 +694,7 @@ def main():
elif 'bind' in args.get('opts', []):
changed = True
- if is_bind_mounted(
- module, linux_mounts, name, args['src'], args['fstype']):
+ if is_bind_mounted( module, linux_mounts, name, args['src'], args['fstype']):
changed = False
if changed and not module.check_mode:
diff --git a/system/seboolean.py b/system/seboolean.py
index 4581c133..973b5b2d 100644
--- a/system/seboolean.py
+++ b/system/seboolean.py
@@ -50,7 +50,10 @@ author: "Stephen Fromm (@sfromm)"
EXAMPLES = '''
# 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:
diff --git a/system/selinux.py b/system/selinux.py
index 2debb95a..2afd4756 100644
--- a/system/selinux.py
+++ b/system/selinux.py
@@ -49,9 +49,19 @@ author: "Derek Carter (@goozbach) <goozbach@friocorte.com>"
'''
EXAMPLES = '''
-- selinux: policy=targeted state=enforcing
-- selinux: policy=targeted state=permissive
-- selinux: state=disabled
+# Enable SELinux
+- selinux:
+ 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
diff --git a/system/service.py b/system/service.py
index c8781b1c..a71e6382 100644
--- a/system/service.py
+++ b/system/service.py
@@ -74,29 +74,51 @@ options:
description:
- Additional arguments provided on the command line
aliases: [ 'args' ]
+ use:
+ description:
+ - The service module actually uses system specific modules, normally through auto detection, this setting can force a specific module.
+ - Normally it uses the value of the 'ansible_service_mgr' fact and falls back to the old 'service' module when none matching is found.
+ default: 'auto'
+ version_added: 2.2
'''
EXAMPLES = '''
# 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
-- service: name=httpd state=stopped
+- service:
+ name: httpd
+ state: stopped
# 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
-- service: name=httpd state=reloaded
+- service:
+ name: httpd
+ state: reloaded
# 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
-- 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
-- service: name=network state=restarted args=eth0
+- service:
+ name: network
+ state: restarted
+ args: eth0
'''
diff --git a/system/sysctl.py b/system/sysctl.py
index 3df8e1fe..9a6787e2 100644
--- a/system/sysctl.py
+++ b/system/sysctl.py
@@ -76,25 +76,37 @@ author: "David CHANIAL (@davixx) <david.chanial@gmail.com>"
EXAMPLES = '''
# Set vm.swappiness to 5 in /etc/sysctl.conf
-- sysctl:
- name: vm.swappiness
+- sysctl:
+ name: vm.swappiness
value: 5
state: present
# Remove kernel.panic entry from /etc/sysctl.conf
- sysctl:
name: kernel.panic
- state: absent
+ state: absent
sysctl_file: /etc/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
-- 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
-- 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
'''
# ==============================================================
diff --git a/system/systemd.py b/system/systemd.py
index fdaeae64..d835b85f 100644
--- a/system/systemd.py
+++ b/system/systemd.py
@@ -73,17 +73,27 @@ requirements:
EXAMPLES = '''
# Example action to start service httpd, if not running
- systemd: state=started name=httpd
+
# Example action to stop service cron on debian, if running
- 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
-- 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
-- systemd: name=httpd state=reloaded
+- systemd:
+ name: httpd
+ state: reloaded
+
# Example action to enable service httpd and ensure it is not masked
- systemd:
name: httpd
enabled: yes
masked: no
+
# Example action to enable a timer for dnf-automatic
- systemd:
name: dnf-automatic.timer
@@ -221,16 +231,15 @@ status:
}
'''
-import os
-import glob
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils._text import to_bytes, to_native
+from ansible.module_utils.service import sysv_exists, sysv_is_enabled, fail_if_missing
+from ansible.module_utils._text import to_native
# ===========================================
# Main control flow
def main():
- # init
+ # initialize
module = AnsibleModule(
argument_spec = dict(
name = dict(required=True, type='str', aliases=['unit', 'service']),
@@ -244,7 +253,6 @@ def main():
required_one_of=[['state', 'enabled', 'masked', 'daemon_reload']],
)
- # initialize
systemctl = module.get_bin_path('systemctl')
if module.params['user']:
systemctl = systemctl + " --user"
@@ -255,6 +263,7 @@ def main():
'name': unit,
'changed': False,
'status': {},
+ 'warnings': [],
}
# Run daemon-reload first, if requested
@@ -263,44 +272,52 @@ def main():
if rc != 0:
module.fail_json(msg='failure %d during daemon-reload: %s' % (rc, err))
- #TODO: check if service exists
+ found = False
+ is_initd = sysv_exists(unit)
+ is_systemd = False
+
+ # check service data, cannot error out on rc as it changes across versions, assume not found
(rc, out, err) = module.run_command("%s show '%s'" % (systemctl, unit))
- if rc != 0:
- module.fail_json(msg='failure %d running systemctl show for %r: %s' % (rc, unit, err))
-
- # load return of systemctl show into dictionary for easy access and return
- k = None
- multival = []
- for line in to_native(out).split('\n'): # systemd can have multiline values delimited with {}
- if line.strip():
- if k is None:
- if '=' in line:
- k,v = line.split('=', 1)
- if v.lstrip().startswith('{'):
- if not v.rstrip().endswith('}'):
+ if rc == 0:
+ # load return of systemctl show into dictionary for easy access and return
+ multival = []
+ if out:
+ k = None
+ for line in to_native(out).split('\n'): # systemd can have multiline values delimited with {}
+ if line.strip():
+ if k is None:
+ if '=' in line:
+ k,v = line.split('=', 1)
+ if v.lstrip().startswith('{'):
+ if not v.rstrip().endswith('}'):
+ multival.append(line)
+ continue
+ result['status'][k] = v.strip()
+ k = None
+ else:
+ if line.rstrip().endswith('}'):
+ result['status'][k] = '\n'.join(multival).strip()
+ multival = []
+ k = None
+ else:
multival.append(line)
- continue
- result['status'][k] = v.strip()
- k = None
- else:
- if line.rstrip().endswith('}'):
- result['status'][k] = '\n'.join(multival).strip()
- multival = []
- k = None
- else:
- multival.append(line)
+ is_systemd = 'LoadState' in result['status'] and result['status']['LoadState'] != 'not-found'
- if 'LoadState' in result['status'] and result['status']['LoadState'] == 'not-found':
- module.fail_json(msg='Could not find the requested service "%r": %s' % (unit, err))
- elif 'LoadError' in result['status']:
- module.fail_json(msg="Failed to get the service status '%s': %s" % (unit, result['status']['LoadError']))
+ # Check for loading error
+ if is_systemd and 'LoadError' in result['status']:
+ module.fail_json(msg="Error loading unit file '%s': %s" % (unit, result['status']['LoadError']))
- # mask/unmask the service, if requested
+ # Does service exist?
+ found = is_systemd or is_initd
+ if is_initd and not is_systemd:
+ result['warnings'].append('The service (%s) is actually an init script but the system is managed by systemd' % unit)
+
+ # mask/unmask the service, if requested, can operate on services before they are installed
if module.params['masked'] is not None:
- masked = (result['status']['LoadState'] == 'masked')
+ # state is not masked unless systemd affirms otherwise
+ masked = ('LoadState' in result['status'] and result['status']['LoadState'] == 'masked')
- # Change?
if masked != module.params['masked']:
result['changed'] = True
if module.params['masked']:
@@ -311,10 +328,21 @@ def main():
if not module.check_mode:
(rc, out, err) = module.run_command("%s %s '%s'" % (systemctl, action, unit))
if rc != 0:
+ # some versions of system CAN mask/unmask non existing services, we only fail on missing if they don't
+ fail_if_missing(module, found, unit, "cannot %s" % (action))
module.fail_json(msg="Unable to %s service %s: %s" % (action, unit, err))
+
# Enable/disable service startup at boot if requested
if module.params['enabled'] is not None:
+
+ if module.params['enabled']:
+ action = 'enable'
+ else:
+ action = 'disable'
+
+ fail_if_missing(module, found, unit, "cannot %s" % (action))
+
# do we need to enable the service?
enabled = False
(rc, out, err) = module.run_command("%s is-enabled '%s'" % (systemctl, unit))
@@ -323,11 +351,8 @@ def main():
if rc == 0:
enabled = True
elif rc == 1:
- # Deals with init scripts
# if both init script and unit file exist stdout should have enabled/disabled, otherwise use rc entries
- initscript = '/etc/init.d/' + unit
- if os.path.exists(initscript) and os.access(initscript, os.X_OK) and \
- (not out.startswith('disabled') or bool(glob.glob('/etc/rc?.d/S??' + unit))):
+ if is_initd and (not out.startswith('disabled') or sysv_is_enabled(unit)):
enabled = True
# default to current state
@@ -336,19 +361,16 @@ def main():
# Change enable/disable if needed
if enabled != module.params['enabled']:
result['changed'] = True
- if module.params['enabled']:
- action = 'enable'
- else:
- action = 'disable'
-
if not module.check_mode:
(rc, out, err) = module.run_command("%s %s '%s'" % (systemctl, action, unit))
if rc != 0:
- module.fail_json(msg="Unable to %s service %s: %s" % (action, unit, err))
+ module.fail_json(msg="Unable to %s service %s: %s" % (action, unit, out + err))
result['enabled'] = not enabled
+ # set service state if requested
if module.params['state'] is not None:
+ fail_if_missing(module, found, unit, "cannot check nor set state")
# default to desired state
result['state'] = module.params['state']
@@ -359,17 +381,15 @@ def main():
if module.params['state'] == 'started':
if result['status']['ActiveState'] != 'active':
action = 'start'
- result['changed'] = True
elif module.params['state'] == 'stopped':
if result['status']['ActiveState'] == 'active':
action = 'stop'
- result['changed'] = True
else:
action = module.params['state'][:-2] # remove 'ed' from restarted/reloaded
result['state'] = 'started'
- result['changed'] = True
if action:
+ result['changed'] = True
if not module.check_mode:
(rc, out, err) = module.run_command("%s %s '%s'" % (systemctl, action, unit))
if rc != 0:
diff --git a/system/user.py b/system/user.py
index c424beea..dd079b64 100644
--- a/system/user.py
+++ b/system/user.py
@@ -160,7 +160,7 @@ options:
default: rsa
version_added: "0.9"
description:
- - Optionally specify the type of SSH key to generate.
+ - Optionally specify the type of SSH key to generate.
Available SSH key types will depend on implementation
present on target host.
ssh_key_file:
@@ -201,19 +201,38 @@ options:
EXAMPLES = '''
# 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
-- 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'
-- 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
-- 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
-- user: name=james18 shell=/bin/zsh groups=developers expires=1422403387
+- user:
+ name: james18
+ shell: /bin/zsh
+ groups: developers
+ expires: 1422403387
'''
import os
@@ -1697,7 +1716,7 @@ class DarwinUser(User):
self.chown_homedir(int(self.uid), int(self.group), self.home)
for field in self.fields:
- if self.__dict__.has_key(field[0]) and self.__dict__[field[0]]:
+ if field[0] in self.__dict__ and self.__dict__[field[0]]:
cmd = self._get_dscl()
cmd += [ '-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]]
@@ -1734,7 +1753,7 @@ class DarwinUser(User):
self._make_group_numerical()
for field in self.fields:
- if self.__dict__.has_key(field[0]) and self.__dict__[field[0]]:
+ if field[0] in self.__dict__ and self.__dict__[field[0]]:
current = self._get_user_property(field[1])
if current is None or current != self.__dict__[field[0]]:
cmd = self._get_dscl()
diff --git a/utilities/helper/meta.py b/utilities/helper/meta.py
index 7e2863ff..76bcf739 100644
--- a/utilities/helper/meta.py
+++ b/utilities/helper/meta.py
@@ -47,19 +47,28 @@ author:
EXAMPLES = '''
# force all notified handlers to run at this point, not waiting for normal sync points
-- template: src=new.j2 dest=/etc/config.txt
+- template:
+ src: new.j2
+ dest: /etc/config.txt
notify: myhandler
- meta: flush_handlers
# reload inventory, useful with dynamic inventories when play makes changes to the existing hosts
-- cloud_guest: name=newhost state=present # this is fake module
-- meta: refresh_inventory
+- cloud_guest: # this is fake module
+ name: newhost
+ state: present
-# clear gathered facts from all currently targeted hosts
-- meta: clear_facts
+- name: Refresh inventory to ensure new instaces exist in inventory
+ meta: refresh_inventory
+
+- name: Clear gathered facts from all currently targeted hosts
+ meta: clear_facts
# bring host back to play after failure
-- copy: src=file dest=/etc/file
+- copy:
+ src: file
+ dest: /etc/file
remote_user: imightnothavepermission
+
- meta: clear_host_errors
'''
diff --git a/utilities/logic/async_wrapper.py b/utilities/logic/async_wrapper.py
index 0d8c41ac..c58b8ee5 100644
--- a/utilities/logic/async_wrapper.py
+++ b/utilities/logic/async_wrapper.py
@@ -115,6 +115,18 @@ def _filter_non_json_lines(data):
return ('\n'.join(lines), warnings)
+
+def _get_interpreter(module_path):
+ module_fd = open(module_path, 'rb')
+ try:
+ head = module_fd.read(1024)
+ if head[0:2] != '#!':
+ return None
+ return head[2:head.index('\n')].strip().split(' ')
+ finally:
+ module_fd.close()
+
+
def _run_module(wrapped_cmd, jid, job_path):
tmp_job_path = job_path + ".tmp"
@@ -130,6 +142,11 @@ def _run_module(wrapped_cmd, jid, job_path):
stderr = ''
try:
cmd = shlex.split(wrapped_cmd)
+ # call the module interpreter directly (for non-binary modules)
+ # this permits use of a script for an interpreter on non-Linux platforms
+ interpreter = _get_interpreter(cmd[0])
+ if interpreter:
+ cmd = interpreter + cmd
script = subprocess.Popen(cmd, shell=False, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(outdata, stderr) = script.communicate()
if PY3:
diff --git a/utilities/logic/debug.py b/utilities/logic/debug.py
index 89d9254a..f28dc538 100644
--- a/utilities/logic/debug.py
+++ b/utilities/logic/debug.py
@@ -44,23 +44,29 @@ options:
required: False
default: 0
version_added: "2.1"
-author:
+author:
- "Dag Wieers (@dagwieers)"
- "Michael DeHaan"
'''
EXAMPLES = '''
# 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
- shell: /usr/bin/uptime
register: result
-- debug: var=result verbosity=2
+- debug:
+ var: result
+ verbosity: 2
- name: Display all variables/facts known for a host
- debug: var=hostvars[inventory_hostname] verbosity=4
+ debug:
+ var: hostvars[inventory_hostname]
+ verbosity: 4
'''
diff --git a/utilities/logic/fail.py b/utilities/logic/fail.py
index 75a7c81d..0957b597 100644
--- a/utilities/logic/fail.py
+++ b/utilities/logic/fail.py
@@ -39,6 +39,7 @@ author: "Dag Wieers (@dagwieers)"
EXAMPLES = '''
# 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"
'''
diff --git a/utilities/logic/include.py b/utilities/logic/include.py
index bdca4298..e5c2face 100644
--- a/utilities/logic/include.py
+++ b/utilities/logic/include.py
@@ -34,7 +34,8 @@ EXAMPLES = """
# include a play after another play
- hosts: localhost
tasks:
- - debug: msg="play1"
+ - debug:
+ msg: "play1"
- include: otherplays.yml
@@ -42,15 +43,21 @@ EXAMPLES = """
# include task list in play
- hosts: all
tasks:
- - debug: msg=task1
+ - debug:
+ msg: task1
+
- include: stuff.yml
- - debug: msg=task10
+
+ - debug:
+ msg: task10
# dyanmic include task list in play
- hosts: all
tasks:
- - debug: msg=task1
- - include: {{hostvar}}.yml
+ - debug:
+ msg: task1
+
+ - include: "{{ hostvar }}.yml"
static: no
when: hostvar is defined
"""
diff --git a/utilities/logic/include_role.py b/utilities/logic/include_role.py
index 2ddbc623..40208764 100644
--- a/utilities/logic/include_role.py
+++ b/utilities/logic/include_role.py
@@ -59,7 +59,8 @@ notes:
'''
EXAMPLES = """
-- include_role: name=myrole
+- include_role:
+ name: myrole
- name: Run tasks/other.yml instead of 'main'
include_role:
diff --git a/utilities/logic/include_vars.py b/utilities/logic/include_vars.py
index 87747bb7..571ddf58 100644
--- a/utilities/logic/include_vars.py
+++ b/utilities/logic/include_vars.py
@@ -61,15 +61,17 @@ EXAMPLES = """
name: stuff
# 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
# Load a variable file based on the OS type, or a default if not found.
- include_vars: "{{ item }}"
with_first_found:
- - "{{ ansible_distribution }}.yml"
- - "{{ ansible_os_family }}.yml"
- - "default.yml"
+ - "{{ ansible_distribution }}.yml"
+ - "{{ ansible_os_family }}.yml"
+ - "default.yml"
# bare include (free-form)
- include_vars: myvars.yml
diff --git a/utilities/logic/pause.py b/utilities/logic/pause.py
index 75d2db1a..5290a632 100644
--- a/utilities/logic/pause.py
+++ b/utilities/logic/pause.py
@@ -47,11 +47,13 @@ notes:
EXAMPLES = '''
# 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:
# 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"
'''
diff --git a/utilities/logic/set_fact.py b/utilities/logic/set_fact.py
index edd41119..881f69fe 100644
--- a/utilities/logic/set_fact.py
+++ b/utilities/logic/set_fact.py
@@ -42,7 +42,9 @@ notes:
EXAMPLES = '''
# Example 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
- set_fact:
diff --git a/utilities/logic/wait_for.py b/utilities/logic/wait_for.py
index d57d18d7..46be2ff0 100644
--- a/utilities/logic/wait_for.py
+++ b/utilities/logic/wait_for.py
@@ -27,6 +27,8 @@ import socket
import sys
import time
+from ansible.module_utils._text import to_native
+
HAS_PSUTIL = False
try:
import psutil
@@ -123,30 +125,50 @@ author:
EXAMPLES = '''
# 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_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_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_for: path=/tmp/foo
+- wait_for:
+ path: /tmp/foo
# 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_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_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
# 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):
@@ -489,7 +511,7 @@ def main():
if not response:
# Server shutdown
break
- data += response
+ data += to_native(response, errors='surrogate_or_strict')
if re.search(compiled_search_re, data):
matched = True
break
diff --git a/web_infrastructure/apache2_module.py b/web_infrastructure/apache2_module.py
index 9f9df923..2e5060d3 100644
--- a/web_infrastructure/apache2_module.py
+++ b/web_infrastructure/apache2_module.py
@@ -47,10 +47,14 @@ requirements: ["a2enmod","a2dismod"]
EXAMPLES = '''
# enables the Apache2 module "wsgi"
-- apache2_module: state=present name=wsgi
+- apache2_module:
+ state: present
+ name: wsgi
# disables the Apache2 module "wsgi"
-- apache2_module: state=absent name=wsgi
+- apache2_module:
+ state: absent
+ name: wsgi
'''
import re
diff --git a/web_infrastructure/django_manage.py b/web_infrastructure/django_manage.py
index 3ce815dc..f334f398 100644
--- a/web_infrastructure/django_manage.py
+++ b/web_infrastructure/django_manage.py
@@ -99,24 +99,34 @@ author: "Scott Anderson (@tastychutney)"
EXAMPLES = """
# 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
-- 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
-- django_manage: >
- command=syncdb
- app_path={{ django_dir }}
- settings={{ settings_app_name }}
- pythonpath={{ settings_dir }}
- virtualenv={{ virtualenv_dir }}
+- django_manage:
+ command: syncdb
+ app_path: "{{ django_dir }}"
+ settings: "{{ settings_app_name }}"
+ pythonpath: "{{ settings_dir }}"
+ virtualenv: "{{ virtualenv_dir }}"
# 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.
-- 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 }}"
"""
diff --git a/web_infrastructure/htpasswd.py b/web_infrastructure/htpasswd.py
index f1a4e482..84a2cbdd 100644
--- a/web_infrastructure/htpasswd.py
+++ b/web_infrastructure/htpasswd.py
@@ -74,11 +74,26 @@ author: "Ansible Core Team"
EXAMPLES = """
# 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
-- 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
-- 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
"""
diff --git a/web_infrastructure/supervisorctl.py b/web_infrastructure/supervisorctl.py
index bd6baa98..97cd3a0c 100644
--- a/web_infrastructure/supervisorctl.py
+++ b/web_infrastructure/supervisorctl.py
@@ -83,16 +83,28 @@ author:
EXAMPLES = '''
# Manage the state of program to be in 'started' state.
-- supervisorctl: name=my_app state=started
+- supervisorctl:
+ name: my_app
+ state: started
# Manage the state of program group to be in 'started' state.
-- supervisorctl: name='my_apps:' state=started
+- supervisorctl:
+ name: 'my_apps:'
+ state: started
# Restart my_app, reading supervisorctl configuration from a specified file.
-- supervisorctl: name=my_app state=restarted config=/var/opt/my_project/supervisord.conf
+- supervisorctl:
+ name: my_app
+ state: restarted
+ config: /var/opt/my_project/supervisord.conf
# Restart my_app, connecting to supervisord with credentials and server URL.
-- supervisorctl: name=my_app state=restarted username=test password=testpass server_url=http://localhost:9001
+- supervisorctl:
+ name: my_app
+ state: restarted
+ username: test
+ password: testpass
+ server_url: 'http://localhost:9001'
'''
diff --git a/windows/async_wrapper.ps1 b/windows/async_wrapper.ps1
index 6463ef3f..a79a6d6b 100644
--- a/windows/async_wrapper.ps1
+++ b/windows/async_wrapper.ps1
@@ -397,7 +397,7 @@ Function Start-Watchdog {
$exec_cmd = [Ansible.Async.NativeProcessUtil]::SearchPath("powershell.exe")
$exec_args = "`"$exec_cmd`" -NoProfile -ExecutionPolicy Bypass -EncodedCommand $encoded_command"
- If(-not [Ansible.Async.NativeProcessUtil]::CreateProcess($exec_cmd, $exec_args, [IntPtr]::Zero, [IntPtr]::Zero, $true, $pstartup_flags, [IntPtr]::Zero, $env:windir, [ref]$si, [ref]$pi)) {
+ If(-not [Ansible.Async.NativeProcessUtil]::CreateProcess($exec_cmd, $exec_args, [IntPtr]::Zero, [IntPtr]::Zero, $false, $pstartup_flags, [IntPtr]::Zero, $env:windir, [ref]$si, [ref]$pi)) {
#throw New-Object System.ComponentModel.Win32Exception
throw "create bang $([System.Runtime.InteropServices.Marshal]::GetLastWin32Error())"
}
diff --git a/windows/win_copy.py b/windows/win_copy.py
index 4f65d682..89bab5e9 100755
--- a/windows/win_copy.py
+++ b/windows/win_copy.py
@@ -47,25 +47,22 @@ author: "Jon Hawkesworth (@jhawkesworth)"
'''
EXAMPLES = '''
-# Copy a single file
-- win_copy: src=/srv/myfiles/foo.conf dest=c:\\TEMP\\foo.conf
-
-# Copy the contents of files/temp_files dir into c:\temp\. Includes any sub dirs under files/temp_files
-# Note the use of unix style path in the dest.
-# This is necessary because \ is yaml escape sequence
-- win_copy: src=files/temp_files/ dest=c:/temp/
-
-# Copy the files/temp_files dir and any files or sub dirs into c:\temp
-# Copies the folder because there is no trailing / on 'files/temp_files'
-- win_copy: src=files/temp_files dest=c:/temp/
+- name: Copy a single file
+ win_copy:
+ src: /srv/myfiles/foo.conf
+ dest: c:\TEMP\foo.conf
+- name: Copy files/temp_files to c:\temp
+ win_copy:
+ src: files/temp_files/
+ dest: c:\temp
'''
RETURN = '''
dest:
description: destination file/path
returned: changed
type: string
- sample: "c:/temp/"
+ sample: 'c:\temp'
src:
description: source file used for the copy on the target machine
returned: changed
diff --git a/windows/win_file.py b/windows/win_file.py
index 895da567..989c128e 100644
--- a/windows/win_file.py
+++ b/windows/win_file.py
@@ -46,27 +46,37 @@ options:
If C(file), the file will NOT be created if it does not exist, see the M(copy)
or M(template) module if you want that behavior. If C(absent),
directories will be recursively deleted, and files will be removed.
- If C(touch), an empty file will be created if the c(path) does not
+ If C(touch), an empty file will be created if the C(path) does not
exist, while an existing file or directory will receive updated file access and
- modification times (similar to the way `touch` works from the command line).
+ modification times (similar to the way C(touch) works from the command line).
required: false
default: file
choices: [ file, directory, touch, absent ]
'''
EXAMPLES = '''
-# create a file
-- win_file: path=C:\\temp\\foo.conf
+- name: Create a file
+ win_file:
+ path: C:\temp\foo.conf
+ state: file
-# touch a file (creates if not present, updates modification time if present)
-- win_file: path=C:\\temp\\foo.conf state=touch
+- name: Touch a file (creates if not present, updates modification time if present)
+ win_file:
+ path: C:\temp\foo.conf
+ state: touch
-# remove a file, if present
-- win_file: path=C:\\temp\\foo.conf state=absent
+- name: Remove a file, if present
+ win_file:
+ path: C:\temp\foo.conf
+ state: absent
-# create directory structure
-- win_file: path=C:\\temp\\folder\\subfolder state=directory
+- name: Create directory structure
+ win_file:
+ path: C:\temp\folder\subfolder
+ state: directory
-# remove directory structure
-- win_file: path=C:\\temp state=absent
+- name: Remove directory structure
+ win_file:
+ path: C:\temp
+ state: absent
'''
diff --git a/windows/win_get_url.py b/windows/win_get_url.py
index 041eb563..e4fe725c 100644
--- a/windows/win_get_url.py
+++ b/windows/win_get_url.py
@@ -45,9 +45,9 @@ options:
default: null
force:
description:
- - If C(yes), will always download the file. If C(no), will only
+ - If C(yes), will always download the file. If C(no), will only
download the file if it does not exist or the remote file has been
- modified more recently than the local file. This works by sending
+ modified more recently than the local file. This works by sending
an http HEAD request to retrieve last modified time of the requested
resource, so for this to work, the remote web server must support
HEAD requests.
@@ -95,22 +95,22 @@ $ ansible -i hosts -c winrm -m win_get_url -a "url=http://www.example.com/earthr
# Playbook example
- name: Download earthrise.jpg to 'C:\\Users\\RandomUser\\earthrise.jpg'
win_get_url:
- url: 'http://www.example.com/earthrise.jpg'
- dest: 'C:\\Users\\RandomUser\\earthrise.jpg'
+ url: http://www.example.com/earthrise.jpg
+ dest: C:\Users\RandomUser\earthrise.jpg
-- name: Download earthrise.jpg to 'C:\\Users\\RandomUser\\earthrise.jpg' only if modified
+- name: Download earthrise.jpg to 'C:\Users\RandomUser\earthrise.jpg' only if modified
win_get_url:
- url: 'http://www.example.com/earthrise.jpg'
- dest: 'C:\\Users\\RandomUser\\earthrise.jpg'
+ url: http://www.example.com/earthrise.jpg
+ dest: C:\Users\RandomUser\earthrise.jpg
force: no
-- name: Download earthrise.jpg to 'C:\\Users\\RandomUser\\earthrise.jpg' through a proxy server.
+- name: Download earthrise.jpg to 'C:\Users\RandomUser\earthrise.jpg' through a proxy server.
win_get_url:
- url: 'http://www.example.com/earthrise.jpg'
- dest: 'C:\\Users\\RandomUser\\earthrise.jpg'
- proxy_url: 'http://10.0.0.1:8080'
- proxy_username: 'username'
- proxy_password: 'password'
+ url: http://www.example.com/earthrise.jpg
+ dest: C:\Users\RandomUser\earthrise.jpg
+ proxy_url: http://10.0.0.1:8080
+ proxy_username: username
+ proxy_password: password
'''
RETURN = '''
url:
diff --git a/windows/win_group.py b/windows/win_group.py
index 5e8b0ada..409065cb 100644
--- a/windows/win_group.py
+++ b/windows/win_group.py
@@ -54,13 +54,13 @@ author: "Chris Hoffman (@chrishoffman)"
'''
EXAMPLES = '''
- # Create a new group
+- name: Create a new group
win_group:
name: deploy
description: Deploy Group
state: present
- # Remove a group
+- name: Remove a group
win_group:
name: deploy
state: absent
diff --git a/windows/win_lineinfile.py b/windows/win_lineinfile.py
index bc378f49..35c478d2 100644
--- a/windows/win_lineinfile.py
+++ b/windows/win_lineinfile.py
@@ -10,11 +10,11 @@
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = """
---
@@ -31,11 +31,11 @@ options:
aliases: [ name, destfile ]
description:
- The path of the file to modify.
- - Note that the Windows path delimiter '\' must be escaped as '\\' (see examples below)
+ - Note that the Windows path delimiter C(\) must be escaped as C(\\) when the line is double quoted.
regexp:
required: false
description:
- - "The regular expression to look for in every line of the file. For C(state=present), the pattern to replace if found; only the last line found will be replaced. For C(state=absent), the pattern of the line to remove. Uses .NET compatible regular expressions; see U(https://msdn.microsoft.com/en-us/library/hs600312%28v=vs.110%29.aspx)."
+ - "The regular expression to look for in every line of the file. For C(state=present), the pattern to replace if found; only the last line found will be replaced. For C(state=absent), the pattern of the line to remove. Uses .NET compatible regular expressions; see U(https://msdn.microsoft.com/en-us/library/hs600312%28v=vs.110%29.aspx)."
state:
required: false
choices: [ present, absent ]
@@ -58,13 +58,13 @@ options:
default: EOF
description:
- Used with C(state=present). If specified, the line will be inserted after the last match of specified regular expression. A special value is available; C(EOF) for inserting the line at the end of the file.
- - If specified regular expression has no matches, EOF will be used instead. May not be used with C(backrefs).
+ - If specified regular expression has no matches, EOF will be used instead. May not be used with C(backrefs).
choices: [ 'EOF', '*regex*' ]
insertbefore:
required: false
description:
- Used with C(state=present). If specified, the line will be inserted before the last match of specified regular expression. A value is available; C(BOF) for inserting the line at the beginning of the file.
- - If specified regular expression has no matches, the line will be inserted at the end of the file. May not be used with C(backrefs).
+ - If specified regular expression has no matches, the line will be inserted at the end of the file. May not be used with C(backrefs).
choices: [ 'BOF', '*regex*' ]
create:
required: false
@@ -81,7 +81,7 @@ options:
validate:
required: false
description:
- - Validation to run before copying into place. Use %s in the command to indicate the current file to validate.
+ - Validation to run before copying into place. Use %s in the command to indicate the current file to validate.
- The command is passed securely so shell features like expansion and pipes won't work.
default: None
encoding:
@@ -94,26 +94,49 @@ options:
newline:
required: false
description:
- - "Specifies the line separator style to use for the modified file. This defaults to the windows line separator (\r\n). Note that the indicated line separator will be used for file output regardless of the original line separator that appears in the input file."
+ - "Specifies the line separator style to use for the modified file. This defaults to the windows line separator (C(\r\n)). Note that the indicated line separator will be used for file output regardless of the original line separator that appears in the input file."
choices: [ "windows", "unix" ]
default: "windows"
"""
-EXAMPLES = """
-- win_lineinfile: dest=C:\\temp\\example.conf regexp=^name= line="name=JohnDoe"
+EXAMPLES = r"""
+- win_lineinfile:
+ dest: C:\temp\example.conf
+ regexp: '^name='
+ line: 'name=JohnDoe'
-- win_lineinfile: dest=C:\\temp\\example.conf state=absent regexp="^name="
+- win_lineinfile:
+ dest: C:\temp\example.conf
+ regexp: '^name='
+ state: absent
-- win_lineinfile: dest=C:\\temp\\example.conf regexp='^127\.0\.0\.1' line='127.0.0.1 localhost'
+- win_lineinfile:
+ dest: C:\temp\example.conf
+ regexp: '^127\.0\.0\.1'
+ line: '127.0.0.1 localhost'
-- win_lineinfile: dest=C:\\temp\\httpd.conf regexp="^Listen " insertafter="^#Listen " line="Listen 8080"
+- win_lineinfile:
+ dest: C:\temp\httpd.conf
+ regexp: '^Listen '
+ insertafter: '^#Listen '
+ line: Listen 8080
-- win_lineinfile: dest=C:\\temp\\services regexp="^# port for http" insertbefore="^www.*80/tcp" line="# port for http by default"
+- win_lineinfile:
+ dest: C:\temp\services
+ regexp: '^# port for http'
+ insertbefore: '^www.*80/tcp'
+ line: '# port for http by default'
# Create file if it doesn't exist with a specific encoding
-- win_lineinfile: dest=C:\\temp\\utf16.txt create="yes" encoding="utf-16" line="This is a utf-16 encoded file"
+- win_lineinfile:
+ dest: C:\temp\utf16.txt
+ create: yes
+ encoding: utf-16
+ line: This is a utf-16 encoded file
# Add a line to a file and ensure the resulting file uses unix line separators
-- win_lineinfile: dest=C:\\temp\\testfile.txt line="Line added to file" newline="unix"
-
+- win_lineinfile:
+ dest: C:\temp\testfile.txt
+ line: Line added to file
+ newline: unix
"""
diff --git a/windows/win_msi.py b/windows/win_msi.py
index d426c164..b167aadc 100644
--- a/windows/win_msi.py
+++ b/windows/win_msi.py
@@ -55,21 +55,24 @@ options:
- Specify whether to wait for install or uninstall to complete before continuing.
choices:
- true
- - yes
- false
- - no
default: false
author: "Matt Martz (@sivel)"
'''
EXAMPLES = '''
-# Install an MSI file
-- win_msi: path=C:\\\\7z920-x64.msi
+- name: Install an MSI file
+ win_msi:
+ path: C:\7z920-x64.msi
-# Install an MSI, and wait for it to complete before continuing
-- win_msi: path=C:\\\\7z920-x64.msi wait=true
+- name: Install an MSI, and wait for it to complete before continuing
+ win_msi:
+ path: C:\7z920-x64.msi
+ wait: true
-# Uninstall an MSI file
-- win_msi: path=C:\\\\7z920-x64.msi state=absent
+- name: Uninstall an MSI file
+ win_msi:
+ path: C:\7z920-x64.msi
+ state: absent
'''
diff --git a/windows/win_service.py b/windows/win_service.py
index 1f0f6326..0fb9ec48 100644
--- a/windows/win_service.py
+++ b/windows/win_service.py
@@ -59,12 +59,12 @@ author: "Chris Hoffman (@chrishoffman)"
'''
EXAMPLES = '''
- # Restart a service
+- name: Restart a service
win_service:
name: spooler
state: restarted
- # Set service startup mode to auto and ensure it is started
+- name: Set service startup mode to auto and ensure it is started
win_service:
name: spooler
start_mode: auto
diff --git a/windows/win_stat.py b/windows/win_stat.py
index e2665598..f2624b45 100644
--- a/windows/win_stat.py
+++ b/windows/win_stat.py
@@ -50,11 +50,12 @@ author: "Chris Church (@cchurch)"
'''
EXAMPLES = '''
-# Obtain information about a file
-
-- win_stat: path=C:\\foo.ini
+- name: Obtain information about a file
+ win_stat:
+ path: C:\foo.ini
register: file_info
-- debug: var=file_info
+- debug:
+ var: file_info
'''