| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
from __future__ import absolute_import, division, print_function |
| 20 |
__metaclass__ = type |
| 21 |
|
| 22 |
|
| 23 |
DOCUMENTATION = ''' |
| 24 |
--- |
| 25 |
module: lifecycle_environment |
| 26 |
version_added: 1.0.0 |
| 27 |
short_description: Manage Lifecycle Environments |
| 28 |
description: |
| 29 |
- Create and manage lifecycle environments |
| 30 |
author: |
| 31 |
- "Andrew Kofink (@akofink)" |
| 32 |
- "Baptiste Agasse (@bagasse)" |
| 33 |
options: |
| 34 |
name: |
| 35 |
description: |
| 36 |
- Name of the lifecycle environment |
| 37 |
required: true |
| 38 |
type: str |
| 39 |
label: |
| 40 |
description: |
| 41 |
- Label of the lifecycle environment. This field cannot be updated. |
| 42 |
type: str |
| 43 |
description: |
| 44 |
description: |
| 45 |
- Description of the lifecycle environment |
| 46 |
type: str |
| 47 |
prior: |
| 48 |
description: |
| 49 |
- Name of the parent lifecycle environment |
| 50 |
type: str |
| 51 |
extends_documentation_fragment: |
| 52 |
- theforeman.foreman.foreman |
| 53 |
- theforeman.foreman.foreman.entity_state |
| 54 |
- theforeman.foreman.foreman.organization |
| 55 |
''' |
| 56 |
|
| 57 |
EXAMPLES = ''' |
| 58 |
- name: "Add a production lifecycle environment" |
| 59 |
theforeman.foreman.lifecycle_environment: |
| 60 |
username: "admin" |
| 61 |
password: "changeme" |
| 62 |
server_url: "https://foreman.example.com" |
| 63 |
name: "Production" |
| 64 |
label: "production" |
| 65 |
organization: "Default Organization" |
| 66 |
prior: "Library" |
| 67 |
description: "The production environment" |
| 68 |
state: "present" |
| 69 |
''' |
| 70 |
|
| 71 |
RETURN = ''' |
| 72 |
entity: |
| 73 |
description: Final state of the affected entities grouped by their type. |
| 74 |
returned: success |
| 75 |
type: dict |
| 76 |
contains: |
| 77 |
lifecycle_environments: |
| 78 |
description: List of lifecycle environments. |
| 79 |
type: list |
| 80 |
elements: dict |
| 81 |
''' |
| 82 |
|
| 83 |
from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import KatelloEntityAnsibleModule |
| 84 |
|
| 85 |
|
| 86 |
class KatelloLifecycleEnvironmentModule(KatelloEntityAnsibleModule): |
| 87 |
pass |
| 88 |
|
| 89 |
|
| 90 |
def main(): |
| 91 |
module = KatelloLifecycleEnvironmentModule( |
| 92 |
foreman_spec=dict( |
| 93 |
name=dict(required=True), |
| 94 |
label=dict(), |
| 95 |
description=dict(), |
| 96 |
prior=dict(type='entity', resource_type='lifecycle_environments', scope=['organization']), |
| 97 |
), |
| 98 |
) |
| 99 |
|
| 100 |
with module.api_connection(): |
| 101 |
entity = module.lookup_entity('entity') |
| 102 |
|
| 103 |
|
| 104 |
if 'prior' not in module.foreman_params and not entity: |
| 105 |
module.foreman_params['prior'] = 'Library' |
| 106 |
|
| 107 |
if entity and not module.desired_absent: |
| 108 |
if 'label' in module.foreman_params and entity['label'] != module.foreman_params['label']: |
| 109 |
module.fail_json(msg="Label cannot be updated on a lifecycle environment.") |
| 110 |
|
| 111 |
if 'prior' in module.foreman_params and entity['prior']['id'] != module.lookup_entity('prior')['id']: |
| 112 |
module.fail_json(msg="Prior cannot be updated on a lifecycle environment.") |
| 113 |
|
| 114 |
module.run() |
| 115 |
|
| 116 |
|
| 117 |
if __name__ == '__main__': |
| 118 |
main() |