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

feat(panos_software): name config load option #398

Merged
merged 2 commits into from
Jun 14, 2023
Merged
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
45 changes: 42 additions & 3 deletions plugins/modules/panos_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
- Timeout value in seconds to wait for the device operation to complete
type: int
default: 1200
named_config:
description:
- A name of a existing named config to be loaded after restart.
If a non-existing file name is given the module will fail.
type: str
required: False
perform_software_check:
description:
- Do a software check before doing the upgrade.
Expand Down Expand Up @@ -97,6 +103,14 @@
sync_to_peer: true
install: false
restart: false

- name: Downgrade to 9.1.10 with named config load
panos_software:
provider: '{{ device }}'
version: 9.1.10
named_config: '9.1.10_backup_named_config.xml'
install: true
restart: true
"""

RETURN = """
Expand Down Expand Up @@ -129,7 +143,7 @@ def needs_download(device, version):


def is_valid_sequence(current, target):
# Patch version upgrade (major and minor versions match)
# Patch version change (major and minor versions match)
if (current.major == target.major) and (current.minor == target.minor):
return True

Expand Down Expand Up @@ -159,6 +173,7 @@ def main():
argument_spec=dict(
version=dict(type="str", required=True),
sync_to_peer=dict(type="bool", default=False),
named_config=dict(type="str", required=False),
download=dict(type="bool", default=True),
install=dict(type="bool", default=True),
restart=dict(type="bool", default=False),
Expand All @@ -179,6 +194,7 @@ def main():
# Module params.
target = PanOSVersion(module.params["version"])
sync_to_peer = module.params["sync_to_peer"]
named_config = module.params.get("named_config", None)
download = module.params["download"]
install = module.params["install"]
restart = module.params["restart"]
Expand All @@ -195,14 +211,31 @@ def main():
device.software.check()

if target != current:

if not is_valid_sequence(current, target):
module.fail_json(
msg="Version Sequence is invalid: {0} -> {1}".format(
current, target
)
)

# try to check if the config specified in the module invocation actually exists
# in case it does not, the module will simply fail
if named_config:
try:
device.op(
"<show><config><saved>"
+ named_config
+ "</saved></config></show>",
xml=True,
cmd_xml=False,
)
except PanDeviceError as e1:
module.fail_json(
msg="Error fetching specified named configuration, file {0}".format(
e1
)
)

# Download new base version if needed.
if download and (
(current.major != target.major) or (current.minor != target.minor)
Expand All @@ -222,7 +255,13 @@ def main():

if install:
if not module.check_mode:
device.software.install(target, sync=True)
if named_config:
device.software.install(
version=target, load_config=named_config, sync=True
)
else:
device.software.install(version=target, sync=True)

changed = True

if restart:
Expand Down