コード例 #1
0
ファイル: junos_config.py プロジェクト: unndevops/ansible
def load_config(module):
    candidate =  module.params['lines'] or module.params['src']
    if isinstance(candidate, basestring):
        candidate = candidate.split('\n')

    confirm = module.params['confirm'] > 0
    confirm_timeout = module.params['confirm']

    kwargs = {
        'confirm': module.params['confirm'] is not None,
        'confirm_timeout': module.params['confirm'],
        'comment': module.params['comment'],
        'commit': not module.check_mode,
    }

    if module.params['src']:
        config_format = module.params['src_format'] or guess_format(str(candidate))
        kwargs.update({'format': config_format, 'action': module.params['update']})

    # this is done to filter out `delete ...` statements which map to
    # nothing in the config as that will cause an exception to be raised
    if module.params['lines']:
        candidate = filter_delete_statements(module, candidate)
        kwargs.update({'action': 'set', 'format': 'text'})

    return load(module, candidate, **kwargs)
コード例 #2
0
def main():
    """ main entry point for module execution
    """
    argument_spec = dict(users=dict(type='list'),
                         name=dict(),
                         full_name=dict(),
                         role=dict(choices=ROLES, default='unauthorized'),
                         sshkey=dict(),
                         purge=dict(type='bool'),
                         state=dict(choices=['present', 'absent'],
                                    default='present'))

    mutually_exclusive = [('users', 'name')]

    module = AnsibleModule(argument_spec=argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    result = {'changed': False}

    want = map_params_to_obj(module)
    ele = map_obj_to_ele(want)

    kwargs = {'commit': not module.check_mode}
    if module.params['purge']:
        kwargs['action'] = 'replace'

    diff = load(module, ele, **kwargs)

    if diff:
        result.update({'changed': True, 'diff': {'prepared': diff}})

    module.exit_json(**result)
コード例 #3
0
def main():

    argument_spec = dict(
        src=dict(required=True, type='path'),
        confirm=dict(default=0, type='int'),
        comment=dict(default=DEFAULT_COMMENT),
        action=dict(default='merge', choices=['merge', 'overwrite',
                                              'replace']),
        config_format=dict(choices=['text', 'set', 'xml']),
        backup=dict(default=False, type='bool'),
    )

    argument_spec.update(junos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    check_transport(module)

    warnings = list()
    check_args(module, warnings)

    result = {'changed': False, 'warnings': warnings}

    comment = module.params['comment']
    confirm = module.params['confirm']
    commit = not module.check_mode
    action = module.params['action']
    src = module.params['src']
    fmt = module.params['config_format']

    if action == 'overwrite' and fmt == 'set':
        module.fail_json(msg="overwrite cannot be used when format is "
                         "set per junos-pyez documentation")

    if module.params['backup']:
        result['__backup__'] = text_type(get_configuration(module))

    diff = load(module, src, action=action, commit=commit, format=fmt)
    if diff:
        result['changed'] = True
        if module._diff:
            result['diff'] = {'prepared': diff}

    module.exit_json(**result)