Ejemplo n.º 1
0
def main():
    required_if = [
        ("state", "present", ["address", "token", "version"])
    ]

    module = AnsibleModule(
        supports_check_mode=True,
        required_if=required_if,
        argument_spec=dict(
            arguments.get_spec(
                "auth", "name", "state",
            ),
            address=dict(),
            token=dict(),
            version=dict(
                choices=["v1", "v2"],
            ),
            timeout=dict(
                type="int",
            ),
            max_retries=dict(
                type="int",
            ),
            rate_limit=dict(
                type="float",
            ),
            burst_limit=dict(
                type="int",
            ),
            tls=dict(
                type="dict",
                options=dict(
                    ca_cert=dict(),
                    cname=dict(),
                    client_cert=dict(),
                    client_key=dict(),
                )
            )
        )
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_url_path(
        API_GROUP, API_VERSION, None, 'providers', module.params['name']
    )

    payload = dict(
        type="VaultProvider",
        api_version=API_VERSION,
        metadata=dict(name=module.params["name"]),
        spec=build_vault_provider_spec(module.params)
    )

    try:
        changed, vault_provider = utils.sync_v1(
            module.params['state'], client, path, payload, module.check_mode, do_differ
        )
        module.exit_json(changed=changed, object=vault_provider)
    except errors.Error as e:
        module.fail_json(msg=str(e))
def main():
    module = AnsibleModule(supports_check_mode=True,
                           argument_spec=dict(
                               arguments.get_spec(
                                   "auth",
                                   "state",
                               ), ))
    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_url_path(API_GROUP, API_VERSION, None, 'providers',
                                'env')
    payload = dict(
        type="Env",
        api_version=API_VERSION,
        metadata=dict(name='env'),
        spec={},
    )

    try:
        changed, env_provider = utils.sync_v1(
            module.params['state'],
            client,
            path,
            payload,
            module.check_mode,
        )
        module.exit_json(changed=changed, object=env_provider)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Ejemplo n.º 3
0
    def test_parameter_passthrough(self, mocker):
        sync_mock = mocker.patch.object(utils, "sync")
        sync_mock.return_value = (True, {
            "metadata": {"name": "test", "namespace": "space"},
            "spec": {"key": "value"},
        })

        changed, object = utils.sync_v1("absent", "c", "/path", {}, False)

        assert changed is True
        assert {
            "metadata": {"name": "test", "namespace": "space"},
            "key": "value",
        }