|
| 1 | +from ansible.module_utils.basic import AnsibleModule |
| 2 | + |
| 3 | +DOCUMENTATION = ''' |
| 4 | +name: icinga2_compatlogger |
| 5 | +short_description: Creates information for CompatLogger object. |
| 6 | +description: |
| 7 | + - Returns information used to create a CompatLogger object. |
| 8 | +version_added: 0.4.0 |
| 9 | +author: |
| 10 | + - Matthias Döhler <[email protected]> |
| 11 | +options: |
| 12 | + name: |
| 13 | + description: |
| 14 | + - The name of the CompatLogger object. |
| 15 | + required: true |
| 16 | + type: str |
| 17 | + state: |
| 18 | + description: |
| 19 | + - The state of the CompatLogger object. |
| 20 | + required: false |
| 21 | + default: present |
| 22 | + choices: [ "present", "absent" ] |
| 23 | + type: str |
| 24 | + order: |
| 25 | + description: |
| 26 | + - Value to determine internal precedence. |
| 27 | + required: false |
| 28 | + default: 10 |
| 29 | + type: int |
| 30 | + file: |
| 31 | + description: |
| 32 | + - Path to the file in which the object will be defined. |
| 33 | + required: true |
| 34 | + default: "features-available/compatlog.conf" |
| 35 | + type: str |
| 36 | + log_dir: |
| 37 | + description: |
| 38 | + - Path to the compat log directory. |
| 39 | + required: false |
| 40 | + type: str |
| 41 | + rotation_method: |
| 42 | + description: |
| 43 | + - Specifies when to rotate log files. |
| 44 | + required: false |
| 45 | + choices: [ "hourly", "daily", "weekly", "monthly" ] |
| 46 | + type: str |
| 47 | +''' |
| 48 | + |
| 49 | +EXAMPLES = ''' |
| 50 | +icinga.icinga.icinga2_compatlogger: |
| 51 | + name: "mycompatlogger" |
| 52 | + log_dir: "LogDir + /compat" |
| 53 | + rotation_method: "monthly" |
| 54 | +''' |
| 55 | + |
| 56 | +RETURN = ''' |
| 57 | +args: |
| 58 | + description: Arguments used to create the CompatLogger object. |
| 59 | + returned: success |
| 60 | + type: dict |
| 61 | + contains: |
| 62 | + log_dir: |
| 63 | + description: The specified log directory. |
| 64 | + returned: success |
| 65 | + type: str |
| 66 | + sample: "LogDir + /compat" |
| 67 | + rotation_method: |
| 68 | + description: The specified rotation method. |
| 69 | + returned: success |
| 70 | + type: str |
| 71 | + sample: "MONTHLY" |
| 72 | +file: |
| 73 | + description: Path to the file that will contain the object. |
| 74 | + returned: success |
| 75 | + type: str |
| 76 | + sample: features-available/compatlog.conf |
| 77 | +name: |
| 78 | + description: The name of the CompatLogger object. |
| 79 | + returned: success |
| 80 | + type: str |
| 81 | + sample: mycompatlogger |
| 82 | +order: |
| 83 | + description: The order value of this object. Used internally when combining multiple templates / objects. |
| 84 | + returned: success |
| 85 | + type: int |
| 86 | + sample: 10 |
| 87 | +state: |
| 88 | + description: The chosen state for the object. |
| 89 | + returned: success |
| 90 | + type: str |
| 91 | + sample: present |
| 92 | +''' |
| 93 | + |
| 94 | +def main(): |
| 95 | + module = AnsibleModule( |
| 96 | + supports_check_mode=True, |
| 97 | + argument_spec=dict( |
| 98 | + state=dict(default='present', choices=['present', 'absent']), |
| 99 | + name=dict(required=True), |
| 100 | + order=dict(default=10, type='int'), |
| 101 | + file=dict(default='features-available/compatlog.conf', type='str'), |
| 102 | + log_dir=dict(type='str'), |
| 103 | + rotation_method=dict(type='str', choices=['hourly', 'daily', 'weekly', 'monthly']), |
| 104 | + ) |
| 105 | + ) |
| 106 | + |
| 107 | + args = module.params |
| 108 | + name = args.pop('name') |
| 109 | + order = args.pop('order') |
| 110 | + state = args.pop('state') |
| 111 | + file = args.pop('file') |
| 112 | + |
| 113 | + # Capslock if rotation_method is set |
| 114 | + if args.get('rotation_method', None): |
| 115 | + args.update({'rotation_method': args.get('rotation_method').upper()}) |
| 116 | + |
| 117 | + module.exit_json( |
| 118 | + changed=False, |
| 119 | + args=args, |
| 120 | + name=name, |
| 121 | + order=str(order), |
| 122 | + state=state, |
| 123 | + file=file, |
| 124 | + ) |
| 125 | + |
| 126 | + |
| 127 | +if __name__ == '__main__': |
| 128 | + main() |
0 commit comments