Debian Codegraph @

ansible_collections/community/general/plugins/modules/jboss.py

raw
1 #!/usr/bin/python
2
3 # Copyright (c) 2013, Jeroen Hoekx <[email protected]>
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7 from __future__ import annotations
8
9 DOCUMENTATION = r"""
10 module: jboss
11 short_description: Deploy applications to JBoss
12 description:
13 - Deploy applications to JBoss standalone using the filesystem.
14 deprecated:
15 removed_in: 14.0.0
16 why: The module has not been very actively maintained and there is a better alternative.
17 alternative: >-
18 Use the C(middleware_automation.wildfly.wildfly_app_deploy) role to deploy applications in JBoss or WildFly.
19 See U(https://galaxy.ansible.com/ui/repo/published/middleware_automation/wildfly/content/role/wildfly_app_deploy/) for details.
20 extends_documentation_fragment:
21 - community.general._attributes
22 attributes:
23 check_mode:
24 support: full
25 diff_mode:
26 support: none
27 options:
28 deployment:
29 required: true
30 description:
31 - The name of the deployment.
32 type: str
33 src:
34 description:
35 - The remote path of the application ear or war to deploy.
36 - Required when O(state=present).
37 - Ignored when O(state=absent).
38 type: path
39 deploy_path:
40 default: /var/lib/jbossas/standalone/deployments
41 description:
42 - The location in the filesystem where the deployment scanner listens.
43 type: path
44 state:
45 choices: [present, absent]
46 default: "present"
47 description:
48 - Whether the application should be deployed or undeployed.
49 type: str
50 notes:
51 - The JBoss standalone deployment-scanner has to be enabled in C(standalone.xml).
52 - The module can wait until O(deployment) file is deployed/undeployed by deployment-scanner. Duration of waiting time depends
53 on scan-interval parameter from C(standalone.xml).
54 - Ensure no identically named application is deployed through the JBoss CLI.
55 seealso:
56 - name: WildFly reference
57 description: Complete reference of the WildFly documentation.
58 link: https://docs.wildfly.org
59 author:
60 - Jeroen Hoekx (@jhoekx)
61 """
62
63 EXAMPLES = r"""
64 - name: Deploy a hello world application to the default deploy_path
65 community.general.jboss:
66 src: /tmp/hello-1.0-SNAPSHOT.war
67 deployment: hello.war
68 state: present
69
70 - name: Update the hello world application to the non-default deploy_path
71 community.general.jboss:
72 src: /tmp/hello-1.1-SNAPSHOT.war
73 deploy_path: /opt/wildfly/deployment
74 deployment: hello.war
75 state: present
76
77 - name: Undeploy the hello world application from the default deploy_path
78 community.general.jboss:
79 deployment: hello.war
80 state: absent
81 """
82
83 RETURN = r""" # """
84
85 import os
86 import time
87
88 from ansible.module_utils.basic import AnsibleModule
89
90 DEFAULT_DEPLOY_PATH = "/var/lib/jbossas/standalone/deployments"
91
92
93 def is_deployed(deploy_path, deployment):
94 return os.path.exists(os.path.join(deploy_path, f"{deployment}.deployed"))
95
96
97 def is_undeployed(deploy_path, deployment):
98 return os.path.exists(os.path.join(deploy_path, f"{deployment}.undeployed"))
99
100
101 def is_failed(deploy_path, deployment):
102 return os.path.exists(os.path.join(deploy_path, f"{deployment}.failed"))
103
104
105 def main():
106 module = AnsibleModule(
107 argument_spec=dict(
108 src=dict(type="path"),
109 deployment=dict(type="str", required=True),
110 deploy_path=dict(type="path", default=DEFAULT_DEPLOY_PATH),
111 state=dict(type="str", choices=["absent", "present"], default="present"),
112 ),
113 required_if=[("state", "present", ("src",))],
114 supports_check_mode=True,
115 )
116
117 result = dict(changed=False)
118
119 src = module.params["src"]
120 deployment = module.params["deployment"]
121 deploy_path = module.params["deploy_path"]
122 state = module.params["state"]
123
124 if not os.path.exists(deploy_path):
125 module.fail_json(msg="deploy_path does not exist.")
126
127 if state == "absent" and src:
128 module.warn("Parameter src is ignored when state=absent")
129 elif state == "present" and not os.path.exists(src):
130 module.fail_json(msg=f"Source file {src} does not exist.")
131
132 deployed = is_deployed(deploy_path, deployment)
133
134 # === when check_mode ===
135 if module.check_mode:
136 if state == "present":
137 if not deployed:
138 result["changed"] = True
139
140 elif deployed:
141 if module.sha1(src) != module.sha1(os.path.join(deploy_path, deployment)):
142 result["changed"] = True
143
144 elif state == "absent" and deployed:
145 result["changed"] = True
146
147 module.exit_json(**result)
148 # =======================
149
150 if state == "present" and not deployed:
151 if is_failed(deploy_path, deployment):
152 # Clean up old failed deployment
153 os.remove(os.path.join(deploy_path, f"{deployment}.failed"))
154
155 module.preserved_copy(src, os.path.join(deploy_path, deployment))
156 while not deployed:
157 deployed = is_deployed(deploy_path, deployment)
158 if is_failed(deploy_path, deployment):
159 module.fail_json(msg=f"Deploying {deployment} failed.")
160 time.sleep(1)
161 result["changed"] = True
162
163 if state == "present" and deployed:
164 if module.sha1(src) != module.sha1(os.path.join(deploy_path, deployment)):
165 os.remove(os.path.join(deploy_path, f"{deployment}.deployed"))
166 module.preserved_copy(src, os.path.join(deploy_path, deployment))
167 deployed = False
168 while not deployed:
169 deployed = is_deployed(deploy_path, deployment)
170 if is_failed(deploy_path, deployment):
171 module.fail_json(msg=f"Deploying {deployment} failed.")
172 time.sleep(1)
173 result["changed"] = True
174
175 if state == "absent" and deployed:
176 os.remove(os.path.join(deploy_path, f"{deployment}.deployed"))
177 while deployed:
178 deployed = not is_undeployed(deploy_path, deployment)
179 if is_failed(deploy_path, deployment):
180 module.fail_json(msg=f"Undeploying {deployment} failed.")
181 time.sleep(1)
182 result["changed"] = True
183
184 module.exit_json(**result)
185
186
187 if __name__ == "__main__":
188 main()