Skip to content

Commit

Permalink
Fixup removed and deprecated modules
Browse files Browse the repository at this point in the history
* Removed modules no longer have documentation
  Decided this was causing people to think that modules were supported
  even after being removed.  This change is a new strategy to have the
  error message trying to use a removed module point people to the older
  documentation.

* Add stubs for modules removed in 2.7
  These are freshly removed so we want people who are still using them
  when they upgrade Ansible to have a hint as to where to find information
  on how to port.

* Finish properly undeprecating include
  include was undeprecated earlier but not all of the pieces that marked
  it as deprecated were reverted.  This change fixes the remaining
  pieces
  • Loading branch information
abadger committed Aug 24, 2018
1 parent 8ec973b commit b2932a4
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 1,718 deletions.
46 changes: 37 additions & 9 deletions lib/ansible/module_utils/common/removed.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
# Copyright (c) 2018, Ansible Project
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)

from ansible.module_utils._text import to_text
import json
import sys

from ansible.module_utils._text import to_native

def removed_module(msg=u'This module has been removed. The module documentation may contain hints for porting'):

def removed_module(removed_in, msg='This module has been removed. The module documentation for'
' Ansible-%(version)s may contain hints for porting'):
"""
When a module is removed, we want the documentation available for a few releases to aid in
porting playbooks. So leave the documentation but remove the actual code and instead have this
boilerplate::
Returns module failure along with a message about the module being removed
:arg removed_in: The version that the module was removed in
:kwarg msg: Message to use in the module's failure message. The default says that the module
has been removed and what version of the Ansible documentation to search for porting help.
Remove the actual code and instead have boilerplate like this::
from ansible.module_utils.common.removed import removed_module
if __name__ == '__main__':
removed_module()
removed_module("2.4")
"""
# We may not have an AnsibleModule when this is called
msg = to_text(msg).translate({ord(u'"'): u'\\"'})
print('\n{{"msg": "{0}", "failed": true}}'.format(msg))
results = {'failed': True}

# Convert numbers into strings
removed_in = to_native(removed_in)

version = removed_in.split('.')
try:
numeric_minor = int(version[-1])
except Exception as e:
last_version = None
else:
version = version[:-1]
version.append(to_native(numeric_minor - 1))
last_version = '.'.join(version)

if last_version is None:
results['warnings'] = ['removed modules should specify the version they were removed in']
results['msg'] = 'This module has been removed'
else:
results['msg'] = msg % {'version': last_version}

print('\n{0}\n'.format(json.dumps(results)))
sys.exit(1)
80 changes: 3 additions & 77 deletions lib/ansible/modules/cloud/amazon/_ec2_ami_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,12 @@


ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['deprecated'],
'status': ['removed'],
'supported_by': 'community'}


DOCUMENTATION = '''
---
module: ec2_ami_search
short_description: Retrieve AWS AMI information for a given operating system.
deprecated:
removed_in: "2.2"
why: Various AWS modules have been combined and replaced with M(ec2_ami_facts).
alternative: Use M(ec2_ami_find) instead.
version_added: "1.6"
description:
- Look up the most recent AMI on AWS for a given operating system.
- Returns C(ami), C(aki), C(ari), C(serial), C(tag)
- If there is no AKI or ARI associated with an image, these will be C(null).
- Only supports images from cloud-images.ubuntu.com
- 'Example output: C({"ami": "ami-69f5a900", "changed": false, "aki": "aki-88aa75e1", "tag": "release", "ari": null, "serial": "20131024"})'
options:
distro:
description: Linux distribution (e.g., C(ubuntu))
required: true
choices: ["ubuntu"]
release:
description: short name of the release (e.g., C(precise))
required: true
stream:
description: Type of release.
required: false
default: "server"
choices: ["server", "desktop"]
store:
description: Back-end store for instance
required: false
default: "ebs"
choices: ["ebs", "ebs-io1", "ebs-ssd", "instance-store"]
arch:
description: CPU architecture
required: false
default: "amd64"
choices: ["i386", "amd64"]
region:
description: EC2 region
required: false
default: us-east-1
choices: ["ap-northeast-1", "ap-southeast-1", "ap-northeast-2",
"ap-southeast-2", "ca-central-1", "eu-central-1", "eu-west-1",
"eu-west-2", "sa-east-1", "us-east-1", "us-east-2", "us-west-1",
"us-west-2", "us-gov-west-1"]
virt:
description: virutalization type
required: false
default: paravirtual
choices: ["paravirtual", "hvm"]
author: "Ansible Core Team (deprecated)"
'''

EXAMPLES = '''
- name: Launch an Ubuntu 12.04 (Precise Pangolin) EC2 instance
hosts: 127.0.0.1
connection: local
tasks:
- name: Get the Ubuntu precise AMI
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
'''

from ansible.module_utils.common.removed import removed_module


if __name__ == '__main__':
removed_module()
removed_module(removed_in='2.2')
19 changes: 19 additions & 0 deletions lib/ansible/modules/cloud/amazon/_ec2_facts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2018, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['removed'],
'supported_by': 'community'}


from ansible.module_utils.common.removed import removed_module


if __name__ == '__main__':
removed_module(removed_in='2.7')
142 changes: 3 additions & 139 deletions lib/ansible/modules/cloud/amazon/_ec2_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,148 +7,12 @@


ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['deprecated'],
'status': ['removed'],
'supported_by': 'certified'}


DOCUMENTATION = '''
---
module: ec2_vpc
short_description: configure AWS virtual private clouds
description:
- Create or terminates AWS virtual private clouds. This module has a dependency on python-boto.
version_added: "1.4"
deprecated:
removed_in: "2.5"
why: Replaced by dedicated modules.
alternative: Use M(ec2_vpc_net) along with supporting modules including M(ec2_vpc_igw), M(ec2_vpc_route_table), M(ec2_vpc_subnet),
M(ec2_vpc_dhcp_option), M(ec2_vpc_nat_gateway), M(ec2_vpc_nacl).
options:
cidr_block:
description:
- "The cidr block representing the VPC, e.g. C(10.0.0.0/16), required when I(state=present)."
instance_tenancy:
description:
- "The supported tenancy options for instances launched into the VPC."
default: "default"
choices: [ "default", "dedicated" ]
dns_support:
description:
- Toggles the "Enable DNS resolution" flag.
type: bool
default: 'yes'
dns_hostnames:
description:
- Toggles the "Enable DNS hostname support for instances" flag.
type: bool
default: 'yes'
subnets:
description:
- 'A dictionary array of subnets to add of the form C({ cidr: ..., az: ... , resource_tags: ... }).'
- Where C(az) is the desired availability zone of the subnet, optional.
- 'Tags C(resource_tags) use dictionary form C({ "Environment":"Dev", "Tier":"Web", ...}), optional.'
- C(resource_tags) see resource_tags for VPC below. The main difference is subnet tags not specified here will be deleted.
- All VPC subnets not in this list will be removed as well.
- As of 1.8, if the subnets parameter is not specified, no existing subnets will be modified.'
vpc_id:
description:
- A VPC id to terminate when I(state=absent).
resource_tags:
description:
- 'A dictionary array of resource tags of the form C({ tag1: value1, tag2: value2 }).
- Tags in this list are used in conjunction with CIDR block to uniquely identify a VPC in lieu of vpc_id. Therefore,
if CIDR/Tag combination does not exist, a new VPC will be created. VPC tags not on this list will be ignored. Prior to 1.7,
specifying a resource tag was optional.'
required: true
version_added: "1.6"
internet_gateway:
description:
- Toggle whether there should be an Internet gateway attached to the VPC.
type: bool
default: 'no'
route_tables:
description:
- >
A dictionary array of route tables to add of the form:
C({ subnets: [172.22.2.0/24, 172.22.3.0/24,], routes: [{ dest: 0.0.0.0/0, gw: igw},], resource_tags: ... }). Where the subnets list is
those subnets the route table should be associated with, and the routes list is a list of routes to be in the table. The special keyword
for the gw of igw specifies that you should the route should go through the internet gateway attached to the VPC. gw also accepts instance-ids,
interface-ids, and vpc-peering-connection-ids in addition igw. resource_tags is optional and uses dictionary form: C({ "Name": "public", ... }).
This module is currently unable to affect the "main" route table due to some limitations in boto, so you must explicitly define the associated
subnets or they will be attached to the main table implicitly. As of 1.8, if the route_tables parameter is not specified, no existing routes
will be modified.
wait:
description:
- Wait for the VPC to be in state 'available' before returning.
type: bool
default: 'no'
wait_timeout:
description:
- How long before wait gives up, in seconds.
default: 300
state:
description:
- Create or terminate the VPC.
required: true
choices: [ "present", "absent" ]
author: "Carson Gee (@carsongee)"
extends_documentation_fragment:
- aws
- ec2
'''

EXAMPLES = '''
# Note: None of these examples set aws_access_key, aws_secret_key, or region.
# It is assumed that their matching environment variables are set.
# Basic creation example:
- ec2_vpc:
state: present
cidr_block: 172.23.0.0/16
resource_tags: { "Environment":"Development" }
region: us-west-2
# Full creation example with subnets and optional availability zones.
# The absence or presence of subnets deletes or creates them respectively.
- ec2_vpc:
state: present
cidr_block: 172.22.0.0/16
resource_tags: { "Environment":"Development" }
subnets:
- cidr: 172.22.1.0/24
az: us-west-2c
resource_tags: { "Environment":"Dev", "Tier" : "Web" }
- cidr: 172.22.2.0/24
az: us-west-2b
resource_tags: { "Environment":"Dev", "Tier" : "App" }
- cidr: 172.22.3.0/24
az: us-west-2a
resource_tags: { "Environment":"Dev", "Tier" : "DB" }
internet_gateway: True
route_tables:
- subnets:
- 172.22.2.0/24
- 172.22.3.0/24
routes:
- dest: 0.0.0.0/0
gw: igw
- subnets:
- 172.22.1.0/24
routes:
- dest: 0.0.0.0/0
gw: igw
region: us-west-2
register: vpc
# Removal of a VPC by id
- ec2_vpc:
state: absent
vpc_id: vpc-aaaaaaa
region: us-west-2
# If you have added elements not managed by this module, e.g. instances, NATs, etc then
# the delete will fail until those dependencies are removed.
'''

from ansible.module_utils.common.removed import removed_module


if __name__ == '__main__':
removed_module()
removed_module(removed_in="2.5")
19 changes: 19 additions & 0 deletions lib/ansible/modules/cloud/amazon/_s3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2018, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['removed'],
'supported_by': 'community'}


from ansible.module_utils.common.removed import removed_module


if __name__ == '__main__':
removed_module(removed_in='2.7')
Loading

0 comments on commit b2932a4

Please sign in to comment.