
    Vh                     Z    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d Zd Zedk(  r e        y	y	)
    )absolute_importdivisionprint_functiona  
module: sysupgrade
short_description: Manage OpenBSD system upgrades
version_added: 1.1.0
description:
  - Manage OpenBSD system upgrades using C(sysupgrade).
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  snapshot:
    description:
      - Apply the latest snapshot.
      - Otherwise release will be applied.
    default: false
    type: bool
  force:
    description:
      - Force upgrade (for snapshots only).
    default: false
    type: bool
  keep_files:
    description:
      - Keep the files under C(/home/_sysupgrade).
      - By default, the files will be deleted after the upgrade.
    default: false
    type: bool
  fetch_only:
    description:
      - Fetch and verify files and create C(/bsd.upgrade) but do not reboot.
      - Set to V(false) if you want C(sysupgrade) to reboot. This will cause Ansible to error, as it expects the module to
        exit gracefully. See the examples.
    default: true
    type: bool
  installurl:
    description:
      - OpenBSD mirror top-level URL for fetching an upgrade.
      - By default, the mirror URL is pulled from C(/etc/installurl).
    type: str
author:
  - Andrew Klaus (@precurse)
aR  
- name: Upgrade to latest release
  community.general.sysupgrade:
  register: sysupgrade

- name: Upgrade to latest snapshot
  community.general.sysupgrade:
    snapshot: true
    installurl: https://cloudflare.cdn.openbsd.org/pub/OpenBSD
  register: sysupgrade

- name: Reboot to apply upgrade if needed
  ansible.builtin.reboot:
  when: sysupgrade.changed

# Note: Ansible will error when running this way due to how
#   the reboot is forcefully handled by sysupgrade:

- name: Have sysupgrade automatically reboot
  community.general.sysupgrade:
    fetch_only: false
  ignore_errors: true
a.  
rc:
  description: The command return code (0 means success).
  returned: always
  type: int
stdout:
  description: Sysupgrade standard output.
  returned: always
  type: str
stderr:
  description: Sysupgrade standard error.
  returned: always
  type: str
  sample: "sysupgrade: need root privileges"
)AnsibleModulec                    | j                  dd      }|g}d}g }| j                  d   r$dg}| j                  d   r|j                  d       nd	g}| j                  d
   r|j                  d       | j                  d   r|j                  d       | j                  d   r|j                  | j                  d          | j                  ||z         \  }}}|dk7  r| j	                  d||||fz         nI|j                         j                  d      dk\  rd}n$|j                         j                  d      dk\  rd}t        |||||      S )Nz/usr/sbin/sysupgradeT)requiredFsnapshotz-sforcez-fz-r
keep_filesz-k
fetch_onlyz-n
installurlr   z'Command %s failed rc=%d, out=%s, err=%s)msgzalready on latest snapshotzupgrade on next reboot)changedrcstderrstdoutwarnings)get_bin_pathparamsappendrun_command	fail_jsonlowerfinddict)	modulesysupgrade_bincmdr   r   run_flagr   outerrs	            p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/sysupgrade.pysysupgrade_runr#   e   sP   (()?$(ON
CGH }}Z 6==!OOD! 6}}\"}}\" }}\"l34%%cHn5LBS	QwF#rSVX[I\\]			6	71	<			2	3q	8     c                      t        t        t        dd      t        dd      t        dd      t        dd      t        d            d      } t        |       } | j                  d	i | y )
NboolF)typedefaultTstr)r'   )r	   r   r
   r   r   )argument_specsupports_check_mode )r   r   r#   	exit_json)r   return_dicts     r"   mainr/      sh    vu56FE27'
 "	F !(KF#{#r$   __main__N)
__future__r   r   r   r'   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   r#   r/   __name__r,   r$   r"   <module>r8      sM    C B-^0
  5)X$ zF r$   