mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-02 02:16:23 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -122,6 +122,7 @@ import os
|
|||
|
||||
try:
|
||||
import yaml
|
||||
|
||||
HAS_YAML = True
|
||||
except ImportError:
|
||||
HAS_YAML = False
|
||||
|
|
@ -130,8 +131,8 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
|
||||
|
||||
def read_serverless_config(module):
|
||||
path = module.params.get('service_path')
|
||||
full_path = os.path.join(path, 'serverless.yml')
|
||||
path = module.params.get("service_path")
|
||||
full_path = os.path.join(path, "serverless.yml")
|
||||
|
||||
try:
|
||||
with open(full_path) as sls_config:
|
||||
|
|
@ -143,7 +144,7 @@ def read_serverless_config(module):
|
|||
|
||||
def get_service_name(module, stage):
|
||||
config = read_serverless_config(module)
|
||||
if config.get('service') is None:
|
||||
if config.get("service") is None:
|
||||
module.fail_json(msg="Could not read `service` key from serverless.yml file")
|
||||
|
||||
if stage:
|
||||
|
|
@ -155,66 +156,68 @@ def get_service_name(module, stage):
|
|||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
service_path=dict(type='path', required=True),
|
||||
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||
region=dict(type='str', default=''),
|
||||
stage=dict(type='str', default=''),
|
||||
deploy=dict(type='bool', default=True),
|
||||
serverless_bin_path=dict(type='path'),
|
||||
force=dict(type='bool', default=False),
|
||||
verbose=dict(type='bool', default=False),
|
||||
service_path=dict(type="path", required=True),
|
||||
state=dict(type="str", default="present", choices=["absent", "present"]),
|
||||
region=dict(type="str", default=""),
|
||||
stage=dict(type="str", default=""),
|
||||
deploy=dict(type="bool", default=True),
|
||||
serverless_bin_path=dict(type="path"),
|
||||
force=dict(type="bool", default=False),
|
||||
verbose=dict(type="bool", default=False),
|
||||
),
|
||||
)
|
||||
|
||||
if not HAS_YAML:
|
||||
module.fail_json(msg='yaml is required for this module')
|
||||
module.fail_json(msg="yaml is required for this module")
|
||||
|
||||
service_path = module.params.get('service_path')
|
||||
state = module.params.get('state')
|
||||
region = module.params.get('region')
|
||||
stage = module.params.get('stage')
|
||||
deploy = module.params.get('deploy', True)
|
||||
force = module.params.get('force', False)
|
||||
verbose = module.params.get('verbose', False)
|
||||
serverless_bin_path = module.params.get('serverless_bin_path')
|
||||
service_path = module.params.get("service_path")
|
||||
state = module.params.get("state")
|
||||
region = module.params.get("region")
|
||||
stage = module.params.get("stage")
|
||||
deploy = module.params.get("deploy", True)
|
||||
force = module.params.get("force", False)
|
||||
verbose = module.params.get("verbose", False)
|
||||
serverless_bin_path = module.params.get("serverless_bin_path")
|
||||
|
||||
if serverless_bin_path is not None:
|
||||
command = f"{serverless_bin_path} "
|
||||
else:
|
||||
command = f"{module.get_bin_path('serverless')} "
|
||||
|
||||
if state == 'present':
|
||||
command += 'deploy '
|
||||
elif state == 'absent':
|
||||
command += 'remove '
|
||||
if state == "present":
|
||||
command += "deploy "
|
||||
elif state == "absent":
|
||||
command += "remove "
|
||||
else:
|
||||
module.fail_json(msg=f"State must either be 'present' or 'absent'. Received: {state}")
|
||||
|
||||
if state == 'present':
|
||||
if state == "present":
|
||||
if not deploy:
|
||||
command += '--noDeploy '
|
||||
command += "--noDeploy "
|
||||
elif force:
|
||||
command += '--force '
|
||||
command += "--force "
|
||||
|
||||
if region:
|
||||
command += f'--region {region} '
|
||||
command += f"--region {region} "
|
||||
if stage:
|
||||
command += f'--stage {stage} '
|
||||
command += f"--stage {stage} "
|
||||
if verbose:
|
||||
command += '--verbose '
|
||||
command += "--verbose "
|
||||
|
||||
rc, out, err = module.run_command(command, cwd=service_path)
|
||||
if rc != 0:
|
||||
if state == 'absent' and f"-{stage}' does not exist" in out:
|
||||
module.exit_json(changed=False, state='absent', command=command,
|
||||
out=out, service_name=get_service_name(module, stage))
|
||||
if state == "absent" and f"-{stage}' does not exist" in out:
|
||||
module.exit_json(
|
||||
changed=False, state="absent", command=command, out=out, service_name=get_service_name(module, stage)
|
||||
)
|
||||
|
||||
module.fail_json(msg=f"Failure when executing Serverless command. Exited {rc}.\nstdout: {out}\nstderr: {err}")
|
||||
|
||||
# gather some facts about the deployment
|
||||
module.exit_json(changed=True, state='present', out=out, command=command,
|
||||
service_name=get_service_name(module, stage))
|
||||
module.exit_json(
|
||||
changed=True, state="present", out=out, command=command, service_name=get_service_name(module, stage)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue