def main():
    """ Main entry point for Ansible module execution
    """
    argument_spec = dict(src=dict(type='path',
                                  required=True,
                                  aliases=['package']),
                         version=dict(),
                         reboot=dict(type='bool', default=True),
                         no_copy=dict(default=False, type='bool'),
                         validate=dict(default=True, type='bool'),
                         force=dict(type='bool', default=False),
                         transport=dict(default='netconf',
                                        choices=['netconf']),
                         force_host=dict(type='bool', default=False),
                         issu=dict(type='bool', default=False),
                         ssh_private_key_file=dict(type='path'),
                         ssh_config=dict(type='path'))

    argument_spec.update(junos_argument_spec)

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

    if module.params['provider'] is None:
        module.params['provider'] = {}

    if not HAS_PYEZ:
        module.fail_json(
            msg='junos-eznc is required but does not appear to be installed. '
            'It can be installed using `pip  install junos-eznc`')

    result = dict(changed=False)

    do_upgrade = module.params['force'] or False

    device = get_device(module)

    if not module.params['force']:
        device.facts_refresh()
        has_ver = device.facts.get('version')
        wants_ver = module.params['version']
        do_upgrade = has_ver != wants_ver

    if do_upgrade:
        if not module.check_mode:
            install_package(module, device)
        result['changed'] = True

    module.exit_json(**result)
示例#2
0
def main():
    """Main entry point for Ansible module execution"""
    argument_spec = dict(
        src=dict(type="path", required=True, aliases=["package"]),
        version=dict(),
        reboot=dict(type="bool", default=True),
        no_copy=dict(default=False, type="bool"),
        validate=dict(default=True, type="bool"),
        force=dict(type="bool", default=False),
        force_host=dict(type="bool", default=False),
        issu=dict(type="bool", default=False),
        ssh_private_key_file=dict(type="path"),
        ssh_config=dict(type="path"),
    )

    argument_spec.update(junos_argument_spec)

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

    if module.params["provider"] is None:
        module.params["provider"] = {}

    if not HAS_PYEZ:
        module.fail_json(
            msg="junos-eznc is required but does not appear to be installed. "
            "It can be installed using `pip  install junos-eznc`"
        )

    result = dict(changed=False)

    do_upgrade = module.params["force"] or False

    device = get_device(module)

    if not module.params["force"]:
        device.facts_refresh()
        has_ver = device.facts.get("version")
        wants_ver = module.params["version"]
        do_upgrade = has_ver != wants_ver

    if do_upgrade:
        if not module.check_mode:
            install_package(module, device)
        result["changed"] = True

    module.exit_json(**result)
示例#3
0
    def populate(self):

        device = get_device(self.module)
        facts = dict(device.facts)

        if "2RE" in facts:
            facts["has_2RE"] = facts["2RE"]
            del facts["2RE"]

        facts["version_info"] = dict(facts["version_info"])
        if "junos_info" in facts:
            for key, value in facts["junos_info"].items():
                if "object" in value:
                    value["object"] = dict(value["object"])

        return facts
示例#4
0
    def populate(self):

        device = get_device(self.module)
        facts = dict(device.facts)

        if '2RE' in facts:
            facts['has_2RE'] = facts['2RE']
            del facts['2RE']

        facts['version_info'] = dict(facts['version_info'])
        if 'junos_info' in facts:
            for key, value in facts['junos_info'].items():
                if 'object' in value:
                    value['object'] = dict(value['object'])

        return facts
def main():
    """ Main entry point for Ansible module execution
    """
    argument_spec = dict(
        src=dict(type='list', required=True),
        dest=dict(type='path', required=False, default="."),
        recursive=dict(type='bool', default=False),
        remote_src=dict(type='bool', default=False),
        ssh_private_key_file=dict(type='path'),
        ssh_config=dict(type='path'),
        transport=dict(default='netconf', choices=['netconf'])
    )

    argument_spec.update(junos_argument_spec)

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

    if module.params['provider'] is None:
        module.params['provider'] = {}

    if not HAS_PYEZ:
        module.fail_json(
            msg='junos-eznc is required but does not appear to be installed. '
                'It can be installed using `pip install junos-eznc`'
        )

    result = dict(changed=True)

    if not module.check_mode:
        # open pyez connection and transfer files via SCP
        try:
            device = get_device(module)
            transfer_files(module, device)
        except Exception as ex:
            module.fail_json(
                msg=to_native(ex)
            )
        finally:
            try:
                # close pyez connection and ignore exceptions
                device.close()
            except Exception:
                pass

    module.exit_json(**result)