|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +from __future__ import (absolute_import, division, print_function) |
| 4 | +__metaclass__ = type |
| 5 | + |
| 6 | +from ansible.module_utils.basic import AnsibleModule |
| 7 | +from ..module_utils.cli import AEMC, AEMC_arg_spec |
| 8 | + |
| 9 | +DOCUMENTATION = r''' |
| 10 | +--- |
| 11 | +module: content |
| 12 | +
|
| 13 | +short_description: Manages JCR content on AEM instance(s) |
| 14 | +
|
| 15 | +version_added: "1.4.0" |
| 16 | +
|
| 17 | +description: |
| 18 | + - Clean, download, pull, push, and copy JCR content between AEM instances. |
| 19 | + - Supports Vault filter files and filter roots for selective content operations. |
| 20 | +
|
| 21 | +options: |
| 22 | + command: |
| 23 | + description: |
| 24 | + - The content operation to perform. |
| 25 | + - C(clean) - Normalize content files. |
| 26 | + - C(download) - Download content from instance to local file. |
| 27 | + - C(pull) - Pull content from instance and unpack to JCR root directory. |
| 28 | + - C(push) - Push content from JCR root directory to instance. |
| 29 | + - C(copy) - Copy content between instances. |
| 30 | + required: true |
| 31 | + type: str |
| 32 | + choices: ['clean', 'download', 'pull', 'push', 'copy'] |
| 33 | + instance_id: |
| 34 | + description: Use only AEM instance with specified ID. |
| 35 | + type: str |
| 36 | + dir: |
| 37 | + description: JCR root directory path. |
| 38 | + type: str |
| 39 | + file: |
| 40 | + description: Local file path. |
| 41 | + type: str |
| 42 | + path: |
| 43 | + description: JCR root path or local file path. |
| 44 | + type: str |
| 45 | + filter_roots: |
| 46 | + description: Vault filter root paths. |
| 47 | + type: list |
| 48 | + elements: str |
| 49 | + filter_file: |
| 50 | + description: Vault filter file path. |
| 51 | + type: str |
| 52 | + target_file: |
| 53 | + description: File path for downloaded package. |
| 54 | + type: str |
| 55 | + target_pid: |
| 56 | + description: Package ID (group:name:version) for downloaded package. |
| 57 | + type: str |
| 58 | + clean: |
| 59 | + description: Normalize content during operation. |
| 60 | + type: bool |
| 61 | + replace: |
| 62 | + description: Replace content after downloading (for pull command). |
| 63 | + type: bool |
| 64 | + filter_mode: |
| 65 | + description: Override default filter mode (for push command). |
| 66 | + type: str |
| 67 | + instance_target_url: |
| 68 | + description: Destination instance URL(s) for copy command. |
| 69 | + type: list |
| 70 | + elements: str |
| 71 | + instance_target_id: |
| 72 | + description: Destination instance ID(s) for copy command. |
| 73 | + type: list |
| 74 | + elements: str |
| 75 | +
|
| 76 | +author: |
| 77 | + - Krystian Panek (krystian.panek@wundermanthompson.com) |
| 78 | +''' |
| 79 | + |
| 80 | +EXAMPLES = r''' |
| 81 | +- name: Clean content directory |
| 82 | + wttech.aem.content: |
| 83 | + command: clean |
| 84 | + path: /path/to/jcr_root/content/mysite |
| 85 | +
|
| 86 | +- name: Download content from instance |
| 87 | + wttech.aem.content: |
| 88 | + command: download |
| 89 | + instance_id: local_author |
| 90 | + filter_roots: |
| 91 | + - /content/mysite |
| 92 | + - /content/dam/mysite |
| 93 | + target_file: /tmp/content.zip |
| 94 | +
|
| 95 | +- name: Pull content from instance |
| 96 | + wttech.aem.content: |
| 97 | + command: pull |
| 98 | + instance_id: local_author |
| 99 | + dir: /path/to/jcr_root/content/mysite |
| 100 | + filter_roots: |
| 101 | + - /content/mysite |
| 102 | + clean: true |
| 103 | +
|
| 104 | +- name: Push content to instance |
| 105 | + wttech.aem.content: |
| 106 | + command: push |
| 107 | + instance_id: local_author |
| 108 | + dir: /path/to/jcr_root/content/mysite |
| 109 | +
|
| 110 | +- name: Copy content between instances |
| 111 | + wttech.aem.content: |
| 112 | + command: copy |
| 113 | + instance_id: local_author |
| 114 | + instance_target_id: |
| 115 | + - local_publish |
| 116 | + filter_roots: |
| 117 | + - /content/mysite |
| 118 | +''' |
| 119 | + |
| 120 | +RETURN = r''' |
| 121 | +''' |
| 122 | + |
| 123 | + |
| 124 | +def run_module(): |
| 125 | + module = AnsibleModule( |
| 126 | + argument_spec=AEMC_arg_spec(dict( |
| 127 | + command=dict(type='str', required=True, choices=['clean', 'download', 'pull', 'push', 'copy']), |
| 128 | + instance_id=dict(type='str'), |
| 129 | + dir=dict(type='str'), |
| 130 | + file=dict(type='str'), |
| 131 | + path=dict(type='str'), |
| 132 | + filter_roots=dict(type='list', elements='str'), |
| 133 | + filter_file=dict(type='str'), |
| 134 | + target_file=dict(type='str'), |
| 135 | + target_pid=dict(type='str'), |
| 136 | + clean=dict(type='bool'), |
| 137 | + replace=dict(type='bool'), |
| 138 | + filter_mode=dict(type='str'), |
| 139 | + instance_target_url=dict(type='list', elements='str'), |
| 140 | + instance_target_id=dict(type='list', elements='str'), |
| 141 | + )), |
| 142 | + required_if=[ |
| 143 | + ('command', 'clean', ['dir', 'file', 'path'], True), |
| 144 | + ('command', 'download', ['target_file']), |
| 145 | + ('command', 'download', ['filter_roots', 'filter_file'], True), |
| 146 | + ('command', 'pull', ['dir', 'file', 'path'], True), |
| 147 | + ('command', 'push', ['dir', 'file', 'path'], True), |
| 148 | + ('command', 'copy', ['filter_roots', 'filter_file'], True), |
| 149 | + ('command', 'copy', ['instance_target_url', 'instance_target_id'], True), |
| 150 | + ], |
| 151 | + mutually_exclusive=[ |
| 152 | + ['dir', 'file', 'path'], |
| 153 | + ['filter_roots', 'filter_file'], |
| 154 | + ['instance_target_url', 'instance_target_id'], |
| 155 | + ] |
| 156 | + ) |
| 157 | + aemc = AEMC(module) |
| 158 | + command = module.params['command'] |
| 159 | + |
| 160 | + args = ['content', command] |
| 161 | + |
| 162 | + instance_id = module.params['instance_id'] |
| 163 | + if instance_id: |
| 164 | + args.extend(['--instance-id', instance_id]) |
| 165 | + |
| 166 | + dir_param = module.params['dir'] |
| 167 | + if dir_param: |
| 168 | + args.extend(['--dir', dir_param]) |
| 169 | + |
| 170 | + file_param = module.params['file'] |
| 171 | + if file_param: |
| 172 | + args.extend(['--file', file_param]) |
| 173 | + |
| 174 | + path = module.params['path'] |
| 175 | + if path: |
| 176 | + args.extend(['--path', path]) |
| 177 | + |
| 178 | + filter_roots = module.params['filter_roots'] |
| 179 | + if filter_roots: |
| 180 | + for root in filter_roots: |
| 181 | + args.extend(['--filter-roots', root]) |
| 182 | + |
| 183 | + filter_file = module.params['filter_file'] |
| 184 | + if filter_file: |
| 185 | + args.extend(['--filter-file', filter_file]) |
| 186 | + |
| 187 | + target_file = module.params['target_file'] |
| 188 | + if target_file: |
| 189 | + args.extend(['--target-file', target_file]) |
| 190 | + |
| 191 | + target_pid = module.params['target_pid'] |
| 192 | + if target_pid: |
| 193 | + args.extend(['--target-pid', target_pid]) |
| 194 | + |
| 195 | + clean = module.params['clean'] |
| 196 | + if clean is not None: |
| 197 | + args.extend(['--clean', 'true' if clean else 'false']) |
| 198 | + |
| 199 | + replace = module.params['replace'] |
| 200 | + if replace is not None: |
| 201 | + args.extend(['--replace', 'true' if replace else 'false']) |
| 202 | + |
| 203 | + filter_mode = module.params['filter_mode'] |
| 204 | + if filter_mode: |
| 205 | + args.extend(['--filter-mode', filter_mode]) |
| 206 | + |
| 207 | + instance_target_url = module.params['instance_target_url'] |
| 208 | + if instance_target_url: |
| 209 | + for url in instance_target_url: |
| 210 | + args.extend(['--instance-target-url', url]) |
| 211 | + |
| 212 | + instance_target_id = module.params['instance_target_id'] |
| 213 | + if instance_target_id: |
| 214 | + for target_id in instance_target_id: |
| 215 | + args.extend(['--instance-target-id', target_id]) |
| 216 | + |
| 217 | + aemc.handle_json(args=args) |
| 218 | + |
| 219 | + |
| 220 | +def main(): |
| 221 | + run_module() |
| 222 | + |
| 223 | + |
| 224 | +if __name__ == '__main__': |
| 225 | + main() |
0 commit comments