Example #1
0
File: seed.py Project: jpasko1/aomi
def seed_aws_roles(client, mount, roles, opt):
    """Handles the seeding of roles associated with an AWS account"""
    for role in roles:
        aomi.validation.aws_role_obj(role)

        role_path = "%s/roles/%s" % (mount, role['name'])
        if role.get('state', 'present') == 'present':
            if 'policy' in role:
                role_file = hard_path(role['policy'], opt.policies)
                role_template_obj = role.get('vars', {})
                cli_obj = merge_dicts(load_var_files(opt),
                                      cli_hash(opt.extra_vars))
                obj = merge_dicts(role_template_obj, cli_obj)
                data = render(role_file, obj)
                log(
                    'writing inline role %s from %s' %
                    (role['name'], role_file), opt)
                write(client, role_path, {'policy': data}, opt)
            elif 'arn' in role:
                log('writing role %s for %s' % (role['name'], role['arn']),
                    opt)
                write(client, role_path, {'arn': role['arn']}, opt)
        else:
            log('removing role %s' % role['name'], opt)
            delete(client, role_path, opt)
Example #2
0
 def __init__(self, obj, opt):
     super(Policy, self).__init__(obj, opt)
     self.path = obj['name']
     if self.present:
         self.filename = hard_path(obj['file'], opt.policies)
         cli_obj = merge_dicts(load_var_files(opt),
                               cli_hash(opt.extra_vars))
         self._obj = merge_dicts(cli_obj, obj.get('vars', {}))
Example #3
0
def blend_vars(secrets, opt):
    """Blends secret and static variables together"""
    extra_obj = merge_dicts(load_var_files(opt), cli_hash(opt.extra_vars))
    merged = merge_dicts(extra_obj, secrets)
    template_obj = dict((k, v) for k, v in iteritems(merged) if v)
    # give templates something to iterate over
    template_obj['aomi_items'] = template_obj.copy()
    return template_obj
Example #4
0
File: aws.py Project: wattdave/aomi
    def obj(self):
        s_obj = {}
        if 'policy' in self._obj:
            role_template_obj = self._obj.get('vars', {})
            cli_obj = merge_dicts(load_var_files(self.opt),
                                  cli_hash(self.opt.extra_vars))
            template_obj = merge_dicts(role_template_obj, cli_obj)
            s_obj = {'policy': render(self._obj['policy'], template_obj)}
        elif 'arn' in self._obj:
            s_obj = {'arn': self._obj['arn']}

        return s_obj
Example #5
0
File: seed.py Project: jpasko1/aomi
def policy_data(file_name, policy_vars, opt):
    """Returns the rendered policy"""
    policy_path = hard_path(file_name, opt.policies)
    cli_obj = merge_dicts(load_var_files(opt), cli_hash(opt.extra_vars))
    obj = merge_dicts(policy_vars, cli_obj)
    return render(policy_path, obj)
Example #6
0
def get_secretfile(opt):
    """Renders, YAMLs, and returns the Secretfile construct"""
    secretfile_path = abspath(opt.secretfile)
    obj = merge_dicts(load_var_files(opt),
                      cli_hash(opt.extra_vars))
    return yaml.safe_load(render(secretfile_path, obj))