graphiant.naas.graphiant_device_lifecycle module – Manage device lifecycle state and software upgrades/rollback
Note
This module is part of the graphiant.naas collection (version 26.10.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install graphiant.naas.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: graphiant.naas.graphiant_device_lifecycle.
New in graphiant.naas 26.10.0
Synopsis
Changes device lifecycle state with
PUT /v1/devices/bringupand schedules or rolls back software upgrades withPUT /v1/devices/upgrade/schedule. Matches the portal’s Maintain > Device Lifecycle page. Use graphiant.naas.graphiant_device_lifecycle_info to query current status instead.operation=change_statesetslifecycle_statetoactivated,staging,maintenance,deactivated, ordecommissioned. Idempotent against liveGET /v1/edges-summarystatus— only devices that differ are pushed.decommissionedis only accepted when the device’s current state isdeactivated(matches the portal UI); the module fails the task otherwise rather than sending a request the device isn’t in a valid state for.operation=schedule_upgradeschedules a software update to a release channel (release:Stable/Recommended/Latest/Custom— matches the portal’s own “Change Release” dropdown exactly;Customonly resolves to anything for an enterprise that has a custom image enabled, and is otherwise rejected by the API) viaupgrade_action(InstallActivate/Install/Activate, optionaltsto run later);operation=rollbackschedulesaction=Activateback to each device’supgradeSummary.lastRunningVersion— the only target either operation supports; neither can be pinned to an arbitrary exact build string, matching what the portal UI itself allows. Both are actions rather than fully declarative state, so a device that does need the change always reportschanged=trueon success — except one idempotency-style skip each:schedule_upgradeskips a device already resolved to be running the requestedreleasechannel’s current build (skipped_devices);rollbackskips a device with nolastRunningVersion— its *only* skip, sincelastRunningVersionalways differs from what’s currently running, so there’s no “already on this version” case; a repeatrollbackright after a previous one simply targets whichever build the device just came from, reportingchanged=trueagain.schedule_upgradeadditionally does not schedule a device whose portal Connectivity Status is Down (ttConnCountbelow1/Impaired) rather than attempting a push with nothing to deliver it over — unlike the other two skips, this one (not_connected_devices) fails the task, even when other devices in the same batch were scheduled successfully (msgis replaced with a summary; see notes). Bothschedule_upgradeandrollbackalso skip (schedule_in_progress_devices) a device whose existing schedule hasn’t reached a terminal state yet, to avoid racing a still-in-flight prior schedule for the same device — a soft skip likeskipped_devices, not a failure (see notes).Supply
config_filefor adevice_lifecyclelist, and/ordevicewithlifecycle_state/releaseto run a single device or override one device from the file.Precedence is NOT the same for every option:
operation,upgrade_action, andtsapply to the whole run and are module-parameter only (noconfig_fileequivalent).lifecycle_stateandreleasefollow the usual rule — a module parameter set viadeviceoverrides that one device’s entry in the file.verify_for_insyncandwait_for_completionwork the OPPOSITE way: the module parameter only sets the whole-run default, and a device’s own value inconfig_filealways wins over it for itself — see notes.
Requirements
The below requirements are needed on the host that executes this module.
python >= 3.7
graphiant-sdk >= 26.10.0
tabulate (optional; logs a pre-change device table with
detailed_logs=truewhen installed)
Parameters
Parameter |
Comments |
|---|---|
Bearer token for API authentication (for example, from If not passed as a module argument, the collection reads When a bearer token is present (module argument or environment), it takes precedence over If no valid token is available, the module authenticates with |
|
Path to YAML that can drive the whole task by itself (only Relative paths resolve using the collection config path (see Top-level key
|
|
Enable detailed logging in the task result message. Choices:
|
|
Portal device name. With Required when |
|
Graphiant portal host URL for API connectivity. Example: “https://api.graphiant.com” |
|
Target lifecycle state ( Choices:
|
|
The device lifecycle operation to perform. Module-parameter only (not settable in Choices:
|
|
Graphiant portal password for authentication. Required for password-based login when no valid bearer token is available from |
|
Target software release channel ( Ignored for Choices:
|
|
Optional schedule time for |
|
How to apply the upgrade (
Applies to every device in the batch (one Choices:
|
|
Graphiant portal username for authentication. Required for password-based login when no valid bearer token is available from |
|
Poll for the device to reach Sets the whole-run default; a device’s own Choices:
|
|
For Sets the whole-run default; a device’s own Choices:
|
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: partial
|
Full support for |
|
Support: partial
|
Supports Ansible’s |
Notes
Note
After
operation=change_statesucceeds foractivated/staging/maintenance(skipped fordeactivated/decommissioned), the module pollsGET /v1/edges-summaryuntilportalStatus=Readyand the device has at least 2 tunnel-terminator connections, or a timeout is reached (reuses the sameverify_device_portal_statushelper as graphiant.naas.graphiant_device_config). Devices that don’t reach Ready in time land innot_insync_devicesand fail the task (msgis replaced with a summary naming them; the state change itself was still applied — seeconfigured_devices); devices that did reach Ready land ininsync_devices. Setverify_for_insync=falseto skip this for every device, or setverify_for_insyncper device inconfig_file. Devices sharing the same desiredlifecycle_stateare applied via a single batchedPUTcall (matching the portal UI’s own behavior), not one call per device; the readiness poll afterward still runs concurrently per device, not one at a time, and each retry logged while polling names the device by hostname (not just its numeric ID) so concurrent devices’ log lines can be told apart.After
operation=schedule_upgrade/operation=rollbacksucceeds, the module polls each scheduled device’supgradeSummary.schedule.stateuntil it reachesSuccessorFailed(every other value, including any new one the API might add, means still in progress — not a failure, since downloads/installs can take minutes), landing incompleted_devices/failed_devices/in_progress_devices. A device whose schedule reachesSuccessis then also polled forportalStatus=Readythe same wayoperation=change_stateis (sameverify_for_insynctoggle, sameinsync_devices/not_insync_devicesresult fields) —Successdoesn’t mean the portal has settled back toReadyyet. AFailedschedule, or a non-emptynot_insync_devices, fails the task even though the schedule/rollback was still applied. Setwait_for_completion=falseto skip the schedule-state poll (and, since there’s then noSuccessto follow, the Ready poll too) for every device, or override either toggle per device inconfig_file.With
detailed_logs=trueandtabulateinstalled, every operation logs the targeted devices’ current state as a table before anyPUT(see graphiant.naas.graphiant_device_lifecycle_info‘sdetailed_logsnote for column details).operation=change_state(outside check mode) logs the same table again afterward, re-fetched to show each device’s resulting state.operation=schedule_upgradeandoperation=rollbackadditionally log the release channel -> current build table (from the same software releases catalog used to resolveskipped_devicesand the diffaftervalue) right before the devices table, so the skip/schedule decision for every device is auditable from the log alone.A
deviceorconfig_filedevice_lifecycleentry naming a device not found inGET /v1/edges-summaryfails the task before anyPUTis sent; every such unresolved device is collected and named together in one failure, not just the first one encountered, so a config file with several bad names surfaces all of them in a single run.operation=schedule_upgrade/operation=rollbackskip (schedule_in_progress_devices) a device whose existingupgradeSummary.schedule.statehasn’t reachedSuccess/Failedyet, includingIdle— submitting a new schedule while a prior one is still in progress can race the upgrade backend’s own duplicate-request guard and has been observed to fail withFailureReason: "Internal error". Not a failure here; this is reported the same way asskipped_devices(counted in the “N device(s) skipped” summary) rather than failing the task, since the device’s prior schedule is itself still making progress toward the same goal.
See Also
See also
- graphiant.naas.graphiant_device_system
Configure device hostname, region, and site.
- graphiant.naas.graphiant_device_lifecycle_info
Query device lifecycle state and software upgrade status.
Examples
- name: Change lifecycle state for devices from a config file
graphiant.naas.graphiant_device_lifecycle:
operation: change_state
config_file: "sample_device_lifecycle.yaml"
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
detailed_logs: true
register: lifecycle_result
- name: Move a single device to staging
graphiant.naas.graphiant_device_lifecycle:
operation: change_state
device: "edge-1-sdktest"
lifecycle_state: staging
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
- name: Deactivate then decommission a device
graphiant.naas.graphiant_device_lifecycle:
operation: change_state
device: "edge-1-sdktest"
lifecycle_state: deactivated
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
- name: Now safe to decommission (device is Deactivated)
graphiant.naas.graphiant_device_lifecycle:
operation: change_state
device: "edge-1-sdktest"
lifecycle_state: decommissioned
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
- name: Download and install the Latest release now
graphiant.naas.graphiant_device_lifecycle:
operation: schedule_upgrade
device: "edge-1-sdktest"
release: "Latest"
upgrade_action: "InstallActivate"
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
- name: Download the Stable release only, for later activation
graphiant.naas.graphiant_device_lifecycle:
operation: schedule_upgrade
device: "edge-1-sdktest"
release: "Stable"
upgrade_action: "Install"
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
- name: Schedule an upgrade for several devices, from a config file
graphiant.naas.graphiant_device_lifecycle:
operation: schedule_upgrade
config_file: "sample_device_lifecycle.yaml" # devices + release, from the file
upgrade_action: "InstallActivate" # applies to the whole batch; module param only
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
- name: Roll back a device to its previous running version
graphiant.naas.graphiant_device_lifecycle:
operation: rollback
device: "edge-1-sdktest"
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
- name: Override verify_for_insync for just one device in the batch
graphiant.naas.graphiant_device_lifecycle:
operation: change_state
config_file: "sample_device_lifecycle.yaml" # one device's own entry sets verify_for_insync: false
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
Whether the operation made (or, in check mode, would make) changes. Returned: always |
|
For Returned: when applicable |
|
Device names updated ( Returned: when applicable |
|
Raw manager result payload. Returned: always |
|
Ansible Returned: when playbook uses |
|
For Returned: when applicable |
|
For Returned: when applicable |
|
Device names that were polled for readiness and reached Returned: when applicable |
|
Result message from the operation, including detailed logs when Returned: always |
|
Returned: when applicable |
|
Device names that did not reach Returned: when applicable |
|
The operation that was performed. Returned: always |
|
Returned: when applicable |
|
Device names skipped — for Returned: when applicable |