| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
from __future__ import absolute_import, division, print_function |
| 19 |
__metaclass__ = type |
| 20 |
|
| 21 |
|
| 22 |
DOCUMENTATION = ''' |
| 23 |
--- |
| 24 |
module: puppetclasses_import |
| 25 |
version_added: 2.0.0 |
| 26 |
short_description: Import Puppet Classes from a Proxy |
| 27 |
description: |
| 28 |
- Import Puppet Classes from a Proxy |
| 29 |
author: |
| 30 |
- "Evgeni Golov (@evgeni)" |
| 31 |
options: |
| 32 |
smart_proxy: |
| 33 |
description: |
| 34 |
- Smart Proxy to import Puppet Classes from |
| 35 |
required: true |
| 36 |
type: str |
| 37 |
environment: |
| 38 |
description: |
| 39 |
- Puppet Environment to import Puppet Classes from |
| 40 |
required: false |
| 41 |
type: str |
| 42 |
except: |
| 43 |
description: |
| 44 |
- Which types of Puppet Classes to exclude from the import. |
| 45 |
choices: |
| 46 |
- new |
| 47 |
- updated |
| 48 |
- obsolete |
| 49 |
required: false |
| 50 |
type: list |
| 51 |
elements: str |
| 52 |
attributes: |
| 53 |
check_mode: |
| 54 |
support: none |
| 55 |
diff_mode: |
| 56 |
support: none |
| 57 |
extends_documentation_fragment: |
| 58 |
- theforeman.foreman.foreman |
| 59 |
''' |
| 60 |
|
| 61 |
EXAMPLES = ''' |
| 62 |
- name: Import Puppet Classes |
| 63 |
theforeman.foreman.puppetclasses_import: |
| 64 |
username: "admin" |
| 65 |
password: "changeme" |
| 66 |
server_url: "https://foreman.example.com" |
| 67 |
smart_proxy: "foreman.example.com" |
| 68 |
''' |
| 69 |
|
| 70 |
RETURN = ''' |
| 71 |
result: |
| 72 |
description: Details about the Puppet Class import |
| 73 |
returned: success |
| 74 |
type: dict |
| 75 |
contains: |
| 76 |
environments_with_new_puppetclasses: |
| 77 |
description: |
| 78 |
- Number of Puppet Environments with new Puppet Classes |
| 79 |
type: int |
| 80 |
returned: when I(environment) not specificed |
| 81 |
environments_updated_puppetclasses: |
| 82 |
description: |
| 83 |
- Number of Puppet Environments with updated Puppet Classes |
| 84 |
type: int |
| 85 |
returned: when I(environment) not specificed |
| 86 |
environments_obsolete: |
| 87 |
description: |
| 88 |
- Number of Puppet Environments with removed Puppet Classes |
| 89 |
type: int |
| 90 |
returned: when I(environment) not specificed |
| 91 |
environments_ignored: |
| 92 |
description: |
| 93 |
- Number of ignored Puppet Environments |
| 94 |
type: int |
| 95 |
returned: when I(environment) not specificed |
| 96 |
results: |
| 97 |
description: |
| 98 |
- List of Puppet Environments and the changes made to them |
| 99 |
type: list |
| 100 |
returned: success |
| 101 |
''' |
| 102 |
|
| 103 |
from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import ForemanAnsibleModule, _flatten_entity |
| 104 |
|
| 105 |
|
| 106 |
def main(): |
| 107 |
module = ForemanAnsibleModule( |
| 108 |
foreman_spec={ |
| 109 |
'smart_proxy': dict(type='entity', required=True, flat_name='id'), |
| 110 |
'environment': dict(type='entity'), |
| 111 |
'except': dict(type='list', elements='str', choices=['new', 'updated', 'obsolete']), |
| 112 |
}, |
| 113 |
supports_check_mode=False, |
| 114 |
) |
| 115 |
|
| 116 |
with module.api_connection(): |
| 117 |
module.auto_lookup_entities() |
| 118 |
|
| 119 |
if 'except' in module.foreman_params: |
| 120 |
module.foreman_params['except'] = ','.join(module.foreman_params.get('except')) |
| 121 |
|
| 122 |
result = module.resource_action('smart_proxies', 'import_puppetclasses', record_change=False, |
| 123 |
params=_flatten_entity(module.foreman_params, module.foreman_spec)) |
| 124 |
if (result.get('environments_updated_puppetclasses', 0) + result.get('environments_with_new_puppetclasses', 0) |
| 125 |
+ result.get('environments_obsolete', 0) + result.get('environments_ignored', 0)): |
| 126 |
module.set_changed() |
| 127 |
|
| 128 |
module.exit_json(result=result) |
| 129 |
|
| 130 |
|
| 131 |
if __name__ == '__main__': |
| 132 |
main() |