Exemple #1
0
def main():
    argument_spec = dict(
        failover_ip=dict(type='str', required=True),
        state=dict(type='str',
                   default='routed',
                   choices=['routed', 'unrouted']),
        value=dict(type='str'),
        timeout=dict(type='int', default=180),
    )
    argument_spec.update(HETZNER_DEFAULT_ARGUMENT_SPEC)
    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=(('state', 'routed', ['value']), ),
    )

    failover_ip = module.params['failover_ip']
    value = get_failover(module, failover_ip)
    changed = False
    before = get_failover_state(value)

    if module.params['state'] == 'routed':
        new_value = module.params['value']
    else:
        new_value = None

    if value != new_value:
        if module.check_mode:
            value = new_value
            changed = True
        else:
            value, changed = set_failover(module,
                                          failover_ip,
                                          new_value,
                                          timeout=module.params['timeout'])

    after = get_failover_state(value)
    module.exit_json(changed=changed,
                     diff=dict(
                         before=before,
                         after=after,
                     ),
                     **after)
Exemple #2
0
def main():
    argument_spec = dict(failover_ip=dict(type='str', required=True), )
    argument_spec.update(HETZNER_DEFAULT_ARGUMENT_SPEC)
    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )

    failover = get_failover_record(module, module.params['failover_ip'])
    result = get_failover_state(failover['active_server_ip'])
    result['failover_ip'] = failover['ip']
    result['failover_netmask'] = failover['netmask']
    result['server_ip'] = failover['server_ip']
    result['server_number'] = failover['server_number']
    result['changed'] = False
    module.exit_json(**result)