コード例 #1
0
    def run(self, tmp=None, task_vars=None):

        result = super(ActionModule, self).run(tmp, task_vars)
        del tmp  # tmp no longer has any effect

        if self._play_context.check_mode:
            # in --check mode, always skip this module execution
            result['skipped'] = True
            result['msg'] = 'The dcos task does not support check mode'
            return result

        args = self._task.args
        path = args.get('path')
        if path is None:
            raise AnsibleActionFail('path cannot be empty for dcos_secret')
        store = args.get('store', 'default')
        file = args.get('file')

        with open(file, "rb") as wanted_value:

            wanted_state = args.get('state', 'present')

            ensure_dcos()
            ensure_dcos_security()

            current_value = get_secret_value(path, store)

            current_state = 'present' if current_value is not None else 'absent'

            if current_state == wanted_state:
                
                display.vvv(
                    "DC/OS Secret {} already in desired state {}".format(path, wanted_state))
                result['changed'] = False

                if wanted_state == "present" and current_value != wanted_value:
                    secret_update_from_file(path, file, store)
                    result['changed'] = True
                    result['msg'] = "Secret {} was updated".format(path)

            else:
                display.vvv("DC/OS Secret {} not in desired state {}".format(path, wanted_state))

                if wanted_state != 'absent':
                    secret_create_from_file(path, file, store)
                    result['msg'] = "Secret {} was created".format(path)

                else:
                    secret_delete(path, store)
                    result['msg'] = "Secret {} was deleted".format(path)

                result['changed'] = True

            return result
コード例 #2
0
    def run(self, tmp=None, task_vars=None):

        result = super(ActionModule, self).run(tmp, task_vars)
        del tmp  # tmp no longer has any effect

        if self._play_context.check_mode:
            # in --check mode, always skip this module execution
            result['skipped'] = True
            result['msg'] = 'The dcos task does not support check mode'
            return result

        args = self._task.args
        uid = args.get('uid')
        description = args.get('description', 'Created by Ansible')
        password = args.get('password')
        groups = args.get('groups', [])
        wanted_state = args.get('state', 'present')

        if uid is None:
            raise AnsibleActionFail('uid cannot be empty for dcos_iam_user')

        if password is None:
            raise AnsibleActionFail(
                'password cannot be empty for dcos_iam_user')

        ensure_dcos()
        ensure_dcos_security()

        current_state = get_user_state(uid)

        if current_state == wanted_state:

            display.vvv("DC/OS IAM user {} already in desired state {}".format(
                uid, wanted_state))

            if wanted_state == "present":
                user_update(uid, groups)

            result['changed'] = False
        else:
            display.vvv("DC/OS: IAM user {} not in desired state {}".format(
                uid, wanted_state))

            if wanted_state != 'absent':
                user_create(uid, password, description)
                user_update(uid, groups)

            else:
                user_delete(uid)

            result['changed'] = True

        return result
コード例 #3
0
    def run(self, tmp=None, task_vars=None):

        result = super(ActionModule, self).run(tmp, task_vars)
        del tmp  # tmp no longer has any effect

        if self._play_context.check_mode:
            # in --check mode, always skip this module execution
            result['skipped'] = True
            result['msg'] = 'The dcos task does not support check mode'
            return result

        args = self._task.args
        sid = args.get('sid')
        description = args.get('description', 'Created by Ansible')
        secret_path = args.get('secret_path')
        store = args.get('store', 'default')
        groups = args.get('groups', [])
        wanted_state = args.get('state', 'present')

        if sid is None:
            raise AnsibleActionFail(
                'sid cannot be empty for dcos_iam_service_account')

        if secret_path is None:
            raise AnsibleActionFail(
                'secret_path cannot be empty for dcos_iam_service_account')

        ensure_dcos()
        ensure_dcos_security()

        current_state = get_service_account_state(sid)

        if current_state == wanted_state:

            display.vvv(
                "DC/OS IAM service_account {} already in desired state {}".
                format(sid, wanted_state))

            result['changed'] = False

            if wanted_state == "present":

                if get_secret_value(secret_path, store) is None:
                    service_account_delete(sid)
                    service_account_create(sid, secret_path, store,
                                           description)
                    result['changed'] = True

                service_account_update(sid, groups)

        else:
            display.vvv(
                "DC/OS: IAM service_account {} not in desired state {}".format(
                    sid, wanted_state))

            if wanted_state != 'absent':
                service_account_create(sid, secret_path, store, description)
                service_account_update(sid, groups)

            else:
                service_account_delete(sid)

            result['changed'] = True

        return result