| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2018, Dag Wieers (@dagwieers) <[email protected]> |
| 5 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["deprecated"], "supported_by": "community"} |
| 12 |
|
| 13 |
DOCUMENTATION = r""" |
| 14 |
--- |
| 15 |
module: mso_schema_template_deploy |
| 16 |
short_description: Deploy schema templates to sites |
| 17 |
description: |
| 18 |
- Deploy schema templates to sites. |
| 19 |
- Prior to deploy a schema validation is executed for MSO releases running on the ND platform. |
| 20 |
- When schema validation fails, M(cisco.mso.mso_schema_template_deploy) fails and deploy will not be executed. |
| 21 |
author: |
| 22 |
- Dag Wieers (@dagwieers) |
| 23 |
options: |
| 24 |
schema: |
| 25 |
description: |
| 26 |
- The name of the schema. |
| 27 |
type: str |
| 28 |
required: true |
| 29 |
template: |
| 30 |
description: |
| 31 |
- The name of the template. |
| 32 |
type: str |
| 33 |
required: true |
| 34 |
aliases: [ name ] |
| 35 |
site: |
| 36 |
description: |
| 37 |
- The name of the site B(to undeploy). |
| 38 |
type: str |
| 39 |
state: |
| 40 |
description: |
| 41 |
- Use C(deploy) to deploy schema template. |
| 42 |
- Use C(status) to get deployment status. |
| 43 |
- Use C(undeploy) to deploy schema template from a site. |
| 44 |
type: str |
| 45 |
choices: [ deploy, status, undeploy ] |
| 46 |
default: deploy |
| 47 |
|
| 48 |
deprecated: |
| 49 |
removed_in: '3.0.0' |
| 50 |
why: Due to changes in the ND and NDO API, a new module (cisco.mso.ndo_template_deploy) has been released for |
| 51 |
ND v2.2 (NDO v4.1) and later. |
| 52 |
alternative: Use M(cisco.mso.ndo_template_deploy) instead. |
| 53 |
seealso: |
| 54 |
- module: cisco.mso.mso_schema_site |
| 55 |
- module: cisco.mso.mso_schema_template |
| 56 |
extends_documentation_fragment: cisco.mso.modules |
| 57 |
""" |
| 58 |
|
| 59 |
EXAMPLES = r""" |
| 60 |
- name: Deploy a schema template |
| 61 |
cisco.mso.mso_schema_template_deploy: |
| 62 |
host: mso_host |
| 63 |
username: admin |
| 64 |
password: SomeSecretPassword |
| 65 |
schema: Schema 1 |
| 66 |
template: Template 1 |
| 67 |
state: deploy |
| 68 |
|
| 69 |
- name: Undeploy a schema template |
| 70 |
cisco.mso.mso_schema_template_deploy: |
| 71 |
host: mso_host |
| 72 |
username: admin |
| 73 |
password: SomeSecretPassword |
| 74 |
schema: Schema 1 |
| 75 |
template: Template 1 |
| 76 |
site: Site 1 |
| 77 |
state: undeploy |
| 78 |
|
| 79 |
- name: Get deployment status |
| 80 |
cisco.mso.mso_schema_template_deploy: |
| 81 |
host: mso_host |
| 82 |
username: admin |
| 83 |
password: SomeSecretPassword |
| 84 |
schema: Schema 1 |
| 85 |
template: Template 1 |
| 86 |
state: status |
| 87 |
register: status_result |
| 88 |
""" |
| 89 |
|
| 90 |
RETURN = r""" |
| 91 |
""" |
| 92 |
|
| 93 |
from ansible.module_utils.basic import AnsibleModule |
| 94 |
from ansible_collections.cisco.mso.plugins.module_utils.mso import MSOModule, mso_argument_spec |
| 95 |
|
| 96 |
|
| 97 |
def main(): |
| 98 |
argument_spec = mso_argument_spec() |
| 99 |
argument_spec.update( |
| 100 |
schema=dict(type="str", required=True), |
| 101 |
template=dict(type="str", required=True, aliases=["name"]), |
| 102 |
site=dict(type="str"), |
| 103 |
state=dict(type="str", default="deploy", choices=["deploy", "status", "undeploy"]), |
| 104 |
) |
| 105 |
|
| 106 |
module = AnsibleModule( |
| 107 |
argument_spec=argument_spec, |
| 108 |
supports_check_mode=True, |
| 109 |
required_if=[ |
| 110 |
["state", "undeploy", ["site"]], |
| 111 |
], |
| 112 |
) |
| 113 |
|
| 114 |
schema = module.params.get("schema") |
| 115 |
template = module.params.get("template").replace(" ", "") |
| 116 |
site = module.params.get("site") |
| 117 |
state = module.params.get("state") |
| 118 |
|
| 119 |
mso = MSOModule(module) |
| 120 |
|
| 121 |
# Get schema id |
| 122 |
schema_id = mso.lookup_schema(schema) |
| 123 |
|
| 124 |
payload = dict( |
| 125 |
schemaId=schema_id, |
| 126 |
templateName=template, |
| 127 |
) |
| 128 |
|
| 129 |
qs = None |
| 130 |
if state == "deploy": |
| 131 |
if mso.platform == "nd": |
| 132 |
mso.validate_schema(schema_id) |
| 133 |
path = "execute/schema/{0}/template/{1}".format(schema_id, template) |
| 134 |
elif state == "status": |
| 135 |
path = "status/schema/{0}/template/{1}".format(schema_id, template) |
| 136 |
elif state == "undeploy": |
| 137 |
path = "execute/schema/{0}/template/{1}".format(schema_id, template) |
| 138 |
site_id = mso.lookup_site(site) |
| 139 |
qs = dict(undeploy=site_id) |
| 140 |
|
| 141 |
if not module.check_mode: |
| 142 |
status = mso.request(path, method="GET", data=payload, qs=qs) |
| 143 |
mso.exit_json(**status) |
| 144 |
else: |
| 145 |
mso.exit_json() |
| 146 |
|
| 147 |
|
| 148 |
if __name__ == "__main__": |
| 149 |
main() |