Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Install Mode on Install OS Module #265

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pip install terminal
* **ntc_reboot** - reboots a network device. Uses SSH/netmiko for IOS, NX-API for Nexus, and eAPI for Arista.
* **ntc_get_facts** - gathers facts from a network device. Uses SSH/netmiko for IOS, NX-API for Nexus, and eAPI for Arista.
* **ntc_rollback** - performs two major functions. (1) Creates a checkpoint file or backup running config on box. (2) Rolls back to the previously created checkpoint/backup config. Use case is to create the checkpoint/backup as the first task in a playbook and then rollback to it _if_ needed using block/rescue, i.e. try/except in Ansible. Uses SSH/netmiko for IOS, NX-API for Nexus, and eAPI for Arista.
* **ntc_install_os** - installs a new operating system or just sets boot options. Depends on platform. Does not issue a "reload" command, but the device may perform an automatic reboot. Common workflow is to use ntc_file_copy, ntc_install_os, and then ntc_reboot (if needed) for upgrades. Uses SSH/netmiko for IOS, NX-API for Nexus, and eAPI for Arista.
* **ntc_install_os** - installs a new operating system or just sets boot options. Depends on platform. Does not issue a "reload" command, but the device may perform an automatic reboot. Common workflow is to use ntc_file_copy, ntc_install_os, and then ntc_reboot (if needed) for upgrades. Uses SSH/netmiko for IOS, NX-API for Nexus, and eAPI for Arista. For Cisco stack switches pyntc leverages `install_mode` flag to install with the install command. This has an optional parameter of `install_mode` available on install_os (requires PyNTC > 0.16.0)

## Common Issues

Expand Down
51 changes: 33 additions & 18 deletions library/ntc_install_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,16 @@ def already_set(boot_options, system_image_file, kickstart_image_file, **kwargs)

def main():
connection_argument_spec = dict(
platform=dict(choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI,
PLATFORM_F5, PLATFORM_ASA],
required=False),
platform=dict(
choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI, PLATFORM_F5, PLATFORM_ASA],
required=False,
),
host=dict(required=False),
port=dict(required=False),
username=dict(required=False, type='str'),
password=dict(required=False, type='str', no_log=True),
secret=dict(required=False, type='str', no_log=True),
transport=dict(required=False, choices=['http', 'https']),
username=dict(required=False, type="str"),
password=dict(required=False, type="str", no_log=True),
secret=dict(required=False, type="str", no_log=True),
transport=dict(required=False, choices=["http", "https"]),
ntc_host=dict(required=False),
ntc_conf_file=dict(required=False),
)
Expand All @@ -238,24 +239,26 @@ def main():
kickstart_image_file=dict(required=False),
volume=dict(required=False, type="str"),
reboot=dict(required=False, type="bool", default=False),
install_mode=dict(required=False, type="bool", default=None),
)
argument_spec = base_argument_spec
argument_spec.update(connection_argument_spec)
argument_spec["provider"] = dict(required=False, type="dict", options=connection_argument_spec)

module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive=[['host', 'ntc_host'],
['ntc_host', 'secret'],
['ntc_host', 'transport'],
['ntc_host', 'port'],
['ntc_conf_file', 'secret'],
['ntc_conf_file', 'transport'],
['ntc_conf_file', 'port'],
],
required_one_of=[['host', 'ntc_host', 'provider']],
mutually_exclusive=[
["host", "ntc_host"],
["ntc_host", "secret"],
["ntc_host", "transport"],
["ntc_host", "port"],
["ntc_conf_file", "secret"],
["ntc_conf_file", "transport"],
["ntc_conf_file", "port"],
],
required_one_of=[["host", "ntc_host", "provider"]],
required_if=[["platform", PLATFORM_F5, ["volume"]]],
supports_check_mode=True
supports_check_mode=True,
)

if not HAS_PYNTC:
Expand Down Expand Up @@ -324,6 +327,15 @@ def main():
kickstart_image_file = module.params["kickstart_image_file"]
volume = module.params["volume"]

# Get the NTC Version split
version_numbers = pyntc_version.split(".")
install_mode = module.params.get("install_mode")

if install_mode and not ((int(version_numbers[0]) > 0) or (int(version_numbers[1]) >= 16)):
module.fail_json(
msg="Current version of PyNTC does not support install_mode. Please update PyNTC >= 0.16.0"
)

if kickstart_image_file == "null":
kickstart_image_file = None

Expand All @@ -337,7 +349,10 @@ def main():
# TODO: Remove conditional if we require reboot for non-F5 devices
if reboot or device.device_type == "f5_tmos_icontrol":
changed = device.install_os(
image_name=system_image_file, kickstart=kickstart_image_file, volume=volume
image_name=system_image_file,
kickstart=kickstart_image_file,
volume=volume,
install_mode=install_mode,
)
else:
# TODO: Remove support if we require reboot for non-F5 devices
Expand Down