ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

mso_schema_template_deploy.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# Copyright: (c) 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7from __future__ import absolute_import, division, print_function
8__metaclass__ = type
9
10ANSIBLE_METADATA = {'metadata_version': '1.1',
11 'status': ['preview'],
12 'supported_by': 'community'}
13
14DOCUMENTATION = r'''
15---
16module: mso_schema_template_deploy
17short_description: Deploy schema templates to sites
18description:
19- Deploy schema templates to sites.
20author:
21- Dag Wieers (@dagwieers)
22version_added: '2.8'
23options:
24 schema:
25 description:
26 - The name of the schema.
27 type: str
28 required: yes
29 template:
30 description:
31 - The name of the template.
32 type: str
33 aliases: [ name ]
34 site:
35 description:
36 - The name of the site B(to undeploy).
37 type: str
38 state:
39 description:
40 - Use C(deploy) to deploy schema template.
41 - Use C(status) to get deployment status.
42 - Use C(undeploy) to deploy schema template from a site.
43 type: str
44 choices: [ deploy, status, undeploy ]
45 default: deploy
46seealso:
47- module: mso_schema_site
48- module: mso_schema_template
49extends_documentation_fragment: mso
50'''
51
52EXAMPLES = r'''
53- name: Deploy a schema template
54 mso_schema_template_deploy:
55 host: mso_host
56 username: admin
57 password: SomeSecretPassword
58 schema: Schema 1
59 template: Template 1
60 state: deploy
61 delegate_to: localhost
62
63- name: Undeploy a schema template
64 mso_schema_template_deploy:
65 host: mso_host
66 username: admin
67 password: SomeSecretPassword
68 schema: Schema 1
69 template: Template 1
70 site: Site 1
71 state: undeploy
72 delegate_to: localhost
73
74- name: Get deployment status
75 mso_schema:
76 host: mso_host
77 username: admin
78 password: SomeSecretPassword
79 schema: Schema 1
80 template: Template 1
81 state: status
82 delegate_to: localhost
83 register: status_result
84'''
85
86RETURN = r'''
87'''
88
89from ansible.module_utils.basic import AnsibleModule
90from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec
91
92
93def main():
94 argument_spec = mso_argument_spec()
95 argument_spec.update(
96 schema=dict(type='str', required=True),
97 template=dict(type='str', required=True, aliases=['name']),
98 site=dict(type='str'),
99 state=dict(type='str', default='deploy', choices=['deploy', 'status', 'undeploy']),
100 )
101
102 module = AnsibleModule(
103 argument_spec=argument_spec,
104 supports_check_mode=True,
105 required_if=[
106 ['state', 'undeploy', ['site']],
107 ],
108 )
109
110 schema = module.params['schema']
111 template = module.params['template']
112 site = module.params['site']
113 state = module.params['state']
114
115 mso = MSOModule(module)
116
117 # Get schema
118 schema_id = mso.lookup_schema(schema)
119
120 payload = dict(
121 schemaId=schema_id,
122 templateName=template,
123 )
124
125 qs = None
126 if state == 'deploy':
127 path = 'execute/schema/{0}/template/{1}'.format(schema_id, template)
128 elif state == 'status':
129 path = 'status/schema/{0}/template/{1}'.format(schema_id, template)
130 elif state == 'undeploy':
131 path = 'execute/schema/{0}/template/{1}'.format(schema_id, template)
132 site_id = mso.lookup_site(site)
133 qs = dict(undeploy=site_id)
134
135 if not module.check_mode:
136 status = mso.request(path, method='GET', data=payload, qs=qs)
137
138 mso.exit_json(**status)
139
140
141if __name__ == "__main__":
142 main()