
    Vh9p                       d dl mZ dZdZd dlZd dlZd dlZd dlZd dlm	c m
c mZ d dlmZmZmZ d dlmZ d dlmZ d dlmZmZ d d	lmZmZ d
dddddddddddddZ G d de      Z G d de      Z G d de      Z G d de      Z  G d de       Z! G d d e      Z" G d! d"e       Z# G d# d$e      Z$ G d% d&e      Z% G d' d(e       Z& G d) d*e      Z' G d+ d,e      Z( G d- d.e      Z) G d/ d0e      Z* G d1 d2e*      Z+ G d3 d4e*      Z, G d5 d6e*      Z- G d7 d8e*      Z. G d9 d:e*      Z/ G d; d<e*      Z0 G d= d>e*      Z1 G d? d@e*      Z2 G dA dBe*      Z3 G dC dDe*      Z4 G dE dFe*      Z5 G dG dHe*      Z6 G dI dJe*      Z7 G dK dLe*      Z8 G dM dNe*      Z9 G dO dPe*      Z: G dQ dRe*      Z; G dS dTe*      Z< G dU dVe*      Z= G dW dXe*      Z> G dY dZe*      Z? G d[ d\e*      Z@ G d] d^e*      ZA G d_ d`e*      ZB G da dbe*      ZC G dc dde*      ZD G de dfe*      ZE G dg dhe*      ZF G di dje*      ZG G dk dle*      ZH G dm dne*      ZI G do dpe*      ZJ G dq dre*      ZK G ds dte*      ZL G du dve*      ZMdw ZNeOdxk(  r eN        yy)y    )annotationsa  
---
module: hostname
author:
    - Adrian Likins (@alikins)
    - Hideki Saito (@saito-hideki)
version_added: "1.4"
short_description: Manage hostname
requirements: [ hostname ]
description:
    - Set system's hostname. Supports most OSs/Distributions including those using C(systemd).
    - Windows, HP-UX, and AIX are not currently supported.
notes:
    - This module does B(NOT) modify C(/etc/hosts). You need to modify it yourself using other modules such as M(ansible.builtin.template)
      or M(ansible.builtin.replace).
    - On macOS, this module uses C(scutil) to set C(HostName), C(ComputerName), and C(LocalHostName). Since C(LocalHostName)
      cannot contain spaces or most special characters, this module will replace characters when setting C(LocalHostName).
options:
    name:
        description:
            - Name of the host.
            - If the value is a fully qualified domain name that does not resolve from the given host,
              this will cause the module to hang for a few seconds while waiting for the name resolution attempt to timeout.
        type: str
        required: true
    use:
        description:
            - Which strategy to use to update the hostname.
            - If not set we try to autodetect, but this can be problematic, particularly with containers as they can present misleading information.
            - Note that V(systemd) should be specified for RHEL/EL/CentOS 7+. Older distributions should use V(redhat).
        choices: ['alpine', 'debian', 'freebsd', 'generic', 'macos', 'macosx', 'darwin', 'openbsd', 'openrc', 'redhat', 'sles', 'solaris', 'systemd']
        type: str
        version_added: '2.9'
extends_documentation_fragment:
- action_common_attributes
- action_common_attributes.facts
attributes:
    check_mode:
        support: full
    diff_mode:
        support: full
    facts:
        support: full
    platform:
        platforms: posix
z
- name: Set a hostname
  ansible.builtin.hostname:
    name: web01

- name: Set a hostname specifying strategy
  ansible.builtin.hostname:
    name: web01
    use: systemd
N)AnsibleModuleget_distributionget_distribution_version)get_platform_subclass)ServiceMgrFactCollector)get_file_linesget_file_content)	to_nativeto_textAlpineSystemdFreeBSDBaseDarwinOpenBSDOpenRCRedHatSLESSolaris)alpinedebianfreebsdgenericmacosmacosxdarwinopenbsdopenrcredhatslessolarissystemdc                  <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
BaseStrategyc                     || _         d| _        y )NF)modulechanged)selfr'   s     H/home/dcms/DCMS/lib/python3.12/site-packages/ansible/modules/hostname.py__init__zBaseStrategy.__init__g   s        c                Z    | j                          | j                          | j                  S N)update_current_hostnameupdate_permanent_hostnamer(   r)   s    r*   %update_current_and_permanent_hostnamez2BaseStrategy.update_current_and_permanent_hostnamek   s$    $$&&&(||r,   c                    | j                   j                  d   }| j                         }||k7  r/| j                   j                  s| j	                  |       d| _        y y NnameT)r'   paramsget_current_hostname
check_modeset_current_hostnamer(   )r)   r5   current_names      r*   r/   z$BaseStrategy.update_current_hostnamep   sS    {{!!&)0024;;))))$/DL  r,   c                    | j                   j                  d   }| j                         }||k7  r/| j                   j                  s| j	                  |       d| _        y y r4   )r'   r6   get_permanent_hostnamer8   set_permanent_hostnamer(   )r)   r5   permanent_names      r*   r0   z&BaseStrategy.update_permanent_hostnamex   sS    {{!!&)446T!;;))++D1DL "r,   c                "    | j                         S r.   )r<   r1   s    r*   r7   z!BaseStrategy.get_current_hostname   s    **,,r,   c                     y r.    r)   r5   s     r*   r9   z!BaseStrategy.set_current_hostname       r,   c                    t         r.   NotImplementedErrorr1   s    r*   r<   z#BaseStrategy.get_permanent_hostname       !!r,   c                    t         r.   rE   rB   s     r*   r=   z#BaseStrategy.set_permanent_hostname   rG   r,   N)__name__
__module____qualname__r+   r2   r/   r0   r7   r9   r<   r=   rA   r,   r*   r%   r%   f   s*    
  -""r,   r%   c                  <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
UnimplementedStrategyc                $    | j                          y r.   unimplemented_errorr1   s    r*   r2   z;UnimplementedStrategy.update_current_and_permanent_hostname         "r,   c                $    | j                          y r.   rO   r1   s    r*   r/   z-UnimplementedStrategy.update_current_hostname   rQ   r,   c                $    | j                          y r.   rO   r1   s    r*   r0   z/UnimplementedStrategy.update_permanent_hostname   rQ   r,   c                $    | j                          y r.   rO   r1   s    r*   r7   z*UnimplementedStrategy.get_current_hostname   rQ   r,   c                $    | j                          y r.   rO   rB   s     r*   r9   z*UnimplementedStrategy.set_current_hostname   rQ   r,   c                $    | j                          y r.   rO   r1   s    r*   r<   z,UnimplementedStrategy.get_permanent_hostname   rQ   r,   c                $    | j                          y r.   rO   rB   s     r*   r=   z,UnimplementedStrategy.set_permanent_hostname   rQ   r,   c                    t        j                         }t               }|	|d|d}n|}| j                  j	                  d|z         y )Nz ()z-hostname module cannot be used on platform %smsg)platformsystemr   r'   	fail_json)r)   r]   distributionmsg_platforms       r*   rP   z)UnimplementedStrategy.unimplemented_error   sK    "')#(.=L!L?,N 	 	Pr,   N)rI   rJ   rK   r2   r/   r0   r7   r9   r<   r=   rP   rA   r,   r*   rM   rM      s+    #######Pr,   rM   c                  :     e Zd ZdZ fdZd Zd Zd Zd Z xZ	S )CommandStrategyhostnamec                    t         t        |   |       | j                  j	                  | j
                  d      | _        y NT)superrb   r+   r'   get_bin_pathCOMMANDhostname_cmdr)   r'   	__class__s     r*   r+   zCommandStrategy.__init__   /    ot-f5 KK44T\\4Hr,   c                    | j                   g}| j                  j                  |      \  }}}|dk7  r"| j                  j                  d|||fz         t	        |      j                         S Nr   $Command failed rc=%d, out=%s, err=%srZ   ri   r'   run_commandr^   r   stripr)   cmdrcouterrs        r*   r7   z$CommandStrategy.get_current_hostname   h      !{{..s3C7KK!!&LPRTWY\~&]!^~##%%r,   c                    | j                   |g}| j                  j                  |      \  }}}|dk7  r#| j                  j                  d|||fz         y y rn   ri   r'   rq   r^   r)   r5   rt   ru   rv   rw   s         r*   r9   z$CommandStrategy.set_current_hostname   \      $'{{..s3C7KK!!&LPRTWY\~&]!^ r,   c                     y)NUNKNOWNrA   r1   s    r*   r<   z&CommandStrategy.get_permanent_hostname   s    r,   c                     y r.   rA   rB   s     r*   r=   z&CommandStrategy.set_permanent_hostname   rC   r,   )
rI   rJ   rK   rh   r+   r7   r9   r<   r=   __classcell__rk   s   @r*   rb   rb      s#    GI&_r,   rb   c                      e Zd ZdZd Zd Zy)FileStrategy/etc/hostnamec                *   t         j                  j                  | j                        sy	 t	        | j                  dd      S # t
        $ rE}| j                  j                  dt        |      z  t        j                                Y d }~y d }~ww xY w)N T)defaultrr   failed to read hostname: %sr[   	exception)ospathisfileFILEr
   	Exceptionr'   r^   r   	traceback
format_exc)r)   es     r*   r<   z#FileStrategy.get_permanent_hostname   su    ww~~dii(	2#DIIrFF 	2KK!!1IaL@#..0 " 2 2	2s   A 	B;BBc                &   	 t        | j                  d      5 }|j                  d|z         d d d        y # 1 sw Y   y xY w# t        $ rE}| j                  j                  dt        |      z  t        j                                Y d }~y d }~ww xY w)Nw+z%s
failed to update hostname: %sr   )	openr   writer   r'   r^   r   r   r   )r)   r5   fr   s       r*   r=   z#FileStrategy.set_permanent_hostname   s    	2dii& '!&' ' ' 	2KK!!3ilB#..0 " 2 2	2s.   A 6A ?A A 	B;BBN)rI   rJ   rK   r   r<   r=   rA   r,   r*   r   r      s    D	22r,   r   c                      e Zd ZdZdZy)SLESStrategyzW
    This is a SLES Hostname strategy class - it edits the
    /etc/HOSTNAME file.
    z/etc/HOSTNAMEN)rI   rJ   rK   __doc__r   rA   r,   r*   r   r      s     Dr,   r   c                       e Zd ZdZdZd Zd Zy)RedHatStrategyzb
    This is a Redhat Hostname strategy class - it edits the
    /etc/sysconfig/network file.
    z/etc/sysconfig/networkc                   	 t        | j                        D ]R  }t        |      j                         }|j	                  d      s.|j                  d      \  }}|j                         c S  | j                  j                  d| j                  z         y # t        $ rE}| j                  j                  dt        |      z  t        j                                Y d }~y d }~ww xY w)NHOSTNAME=z%Unable to locate HOSTNAME entry in %sr   r   )r	   NETWORK_FILEr   rr   
startswithsplitr'   r^   r   r   r   )r)   linekvr   s        r*   r<   z%RedHatStrategy.get_permanent_hostname   s    	2&t'8'89 % ,,.??:.::c?DAq779$	%
 KK!!7$:K:KK  	2KK!!1IaL@#..0 " 2 2	2s$   AB %B +)B 	C#;CC#c                Z   	 g }d}t        | j                  d      xs d}|j                  d      D ]T  }t        |      }|j	                         j                  d      r|j                  d|z         d}D|j                  |       V |s|j                  d|z         t        | j                  d      5 }|j                  |       d d d        y # 1 sw Y   y xY w# t        $ rE}| j                  j                  dt        |      z  t        j                         	       Y d }~y d }~ww xY w)
NF)rr   r   Tr   zHOSTNAME=%s
r   r   r   )r
   r   
splitlinesr   rr   r   appendr   
writelinesr   r'   r^   r   r   )r)   r5   linesfoundcontentr   r   r   s           r*   r=   z%RedHatStrategy.set_permanent_hostname   s   	2EE&t'8'8FL"G**40 ' ::<**:6LL4!78 ELL&' _t34d''. $!U#$ $ $ 	2KK!!3ilB#..0 " 2 2	2s6   B3C 5CC CC C 	D*%;D%%D*N)rI   rJ   rK   r   r   r<   r=   rA   r,   r*   r   r      s     ,L22r,   r   c                  *     e Zd ZdZdZdZ fdZ xZS )AlpineStrategyz
    This is a Alpine Linux Hostname manipulation strategy class - it edits
    the /etc/hostname file then run hostname -F /etc/hostname.
    r   rc   c                $   t         t        |   |       | j                  j	                  | j
                  d      }|d| j                  g}| j                  j                  |      \  }}}|dk7  r#| j                  j                  d|||fz         y y )NTz-Fr   ro   rZ   )	rf   r   r9   r'   rg   rh   r   rq   r^   )r)   r5   ri   rt   ru   rv   rw   rk   s          r*   r9   z#AlpineStrategy.set_current_hostname  s    nd8>{{//dCT499-{{..s3C7KK!!&LPRTWY\~&]!^ r,   )rI   rJ   rK   r   r   rh   r9   r   r   s   @r*   r   r     s     
 DG_ _r,   r   c                  D     e Zd ZdZdZ fdZd Zd Zd Zd Z	d Z
 xZS )	SystemdStrategyzg
    This is a Systemd hostname manipulation strategy class - it uses
    the hostnamectl command.
    hostnamectlc                    t         t        |   |       | j                  j	                  | j
                  d      | _        y re   )rf   r   r+   r'   rg   rh   hostnamectl_cmdrj   s     r*   r+   zSystemdStrategy.__init__0  s/    ot-f5#{{77dKr,   c                    | j                   ddg}| j                  j                  |      \  }}}|dk7  r"| j                  j                  d|||fz         t	        |      j                         S )N--transientstatusr   ro   rZ   r   r'   rq   r^   r   rr   rs   s        r*   r7   z$SystemdStrategy.get_current_hostname4  sl    ##]H={{..s3C7KK!!&LPRTWY\~&]!^~##%%r,   c                   t        |      dkD  r| j                  j                  d       | j                  dd|g}| j                  j	                  |      \  }}}|dk7  r#| j                  j                  d|||fz         y y )N@   Oname cannot be longer than 64 characters on systemd servers, try a shorter namerZ   r   set-hostnamer   ro   lenr'   r^   r   rq   r{   s         r*   r9   z$SystemdStrategy.set_current_hostname;  s    t9r>KK!!&w!x##]NDI{{..s3C7KK!!&LPRTWY\~&]!^ r,   c                    | j                   ddg}| j                  j                  |      \  }}}|dk7  r"| j                  j                  d|||fz         t	        |      j                         S )N--staticr   r   ro   rZ   r   rs   s        r*   r<   z&SystemdStrategy.get_permanent_hostnameC  sl    ##Z:{{..s3C7KK!!&LPRTWY\~&]!^~##%%r,   c                   t        |      dkD  r| j                  j                  d       | j                  ddd|g}| j                  j	                  |      \  }}}|dk7  r#| j                  j                  d|||fz         y y )	Nr   r   rZ   z--prettyr   r   r   ro   r   r{   s         r*   r=   z&SystemdStrategy.set_permanent_hostnameJ  s    t9r>KK!!&w!x##Z^TR{{..s3C7KK!!&LPRTWY\~&]!^ r,   c                Z    | j                          | j                          | j                  S r.   )r0   r/   r(   r1   s    r*   r2   z5SystemdStrategy.update_current_and_permanent_hostnameR  s&     	&&($$&||r,   )rI   rJ   rK   r   rh   r+   r7   r9   r<   r=   r2   r   r   s   @r*   r   r   (  s0    
 GL&_&_r,   r   c                       e Zd ZdZdZd Zd Zy)OpenRCStrategyzv
    This is a Gentoo (OpenRC) Hostname manipulation strategy class - it edits
    the /etc/conf.d/hostname file.
    z/etc/conf.d/hostnamec                   t         j                  j                  | j                        sy	 t	        | j                        D ]9  }|j                         }|j                  d      s%|dd  j                  d      c S  y # t        $ rE}| j                  j                  dt        |      z  t        j                                Y d }~y d }~ww xY wNr   	hostname=
   "r   r   r   r   r   r   r	   rr   r   r   r'   r^   r   r   r   r)   r   r   s      r*   r<   z%OpenRCStrategy.get_permanent_hostnameb      ww~~dii(	2&tyy1 0zz|??;/9??3//0  	2KK!!1IaL@#..0 " 2 2	2#   9A> &A> <A> >	C;CCc                
   	 t        | j                        D cg c]  }|j                          }}t        |      D ]   \  }}|j	                  d      sd|z  ||<    n t        | j                  d      5 }|j                  dj                  |      dz          d d d        y c c}w # 1 sw Y   y xY w# t        $ rE}| j                  j                  dt        |      z  t        j                                Y d }~y d }~ww xY wNr   zhostname="%s"w
r   r   )r	   r   rr   	enumerater   r   r   joinr   r'   r^   r   r   r   r)   r5   xr   ir   r   r   s           r*   r=   z%OpenRCStrategy.set_permanent_hostnamep  s    	2(6tyy(AB1QWWYBEB$U+ 4??;/.5E!H
 dii% 1		%(4/01 1 C1 1 	2KK!!3ilB#..0 " 2 2	2sK   B4 B#$B4 !B4 6$B(B4 #B4 (B1-B4 1B4 4	D=;C==DN)rI   rJ   rK   r   r   r<   r=   rA   r,   r*   r   r   Z  s    
 "D22r,   r   c                  6     e Zd ZdZdZdZ fdZd Zd Z xZ	S )OpenBSDStrategyz
    This is a OpenBSD family Hostname manipulation strategy class - it edits
    the /etc/myname file for the permanent hostname and executes hostname
    command for the current hostname.
    z/etc/mynamerc   c                    t         t        |   |       | j                  j	                  | j
                  d      | _        y re   )rf   r   r+   r'   rg   rh   ri   rj   s     r*   r+   zOpenBSDStrategy.__init__  rl   r,   c                    | j                   g}| j                  j                  |      \  }}}|dk7  r"| j                  j                  d|||fz         t	        |      j                         S rn   rp   rs   s        r*   r7   z$OpenBSDStrategy.get_current_hostname  rx   r,   c                    | j                   |g}| j                  j                  |      \  }}}|dk7  r#| j                  j                  d|||fz         y y rn   rz   r{   s         r*   r9   z$OpenBSDStrategy.set_current_hostname  r|   r,   )
rI   rJ   rK   r   r   rh   r+   r7   r9   r   r   s   @r*   r   r     s%     DGI&_r,   r   c                  8     e Zd ZdZdZ fdZd Zd Zd Z xZ	S )SolarisStrategyzn
    This is a Solaris11 or later Hostname manipulation strategy class - it
    execute hostname command.
    rc   c                    t         t        |   |       | j                  j	                  | j
                  d      | _        y re   )rf   r   r+   r'   rg   rh   ri   rj   s     r*   r+   zSolarisStrategy.__init__  rl   r,   c                    d}| j                   ||g}| j                  j                  |      \  }}}|dk7  r#| j                  j                  d|||fz         y y )Nz-tr   ro   rZ   rz   )r)   r5   
cmd_optionrt   ru   rv   rw   s          r*   r9   z$SolarisStrategy.set_current_hostname  sc    
  *d3{{..s3C7KK!!&LPRTWY\~&]!^ r,   c                    d}d}d|d|}| j                   j                  |d      \  }}}|dk7  r"| j                   j                  d|||fz  	       t        |      j	                         S )
Nzsvc:/system/identity:nodezconfig/nodenamez/usr/sbin/svccfg -s z listprop -o value T)use_unsafe_shellr   ro   rZ   )r'   rq   r^   r   rr   )r)   fmripatternrt   ru   rv   rw   s          r*   r<   z&SolarisStrategy.get_permanent_hostname  ss    *#?CWM{{..sT.JC7KK!!&LPRTWY\~&]!^~##%%r,   c                    | j                   |g}| j                  j                  |      \  }}}|dk7  r#| j                  j                  d|||fz         y y rn   rz   r{   s         r*   r=   z&SolarisStrategy.set_permanent_hostname  r|   r,   )
rI   rJ   rK   r   rh   r+   r9   r<   r=   r   r   s   @r*   r   r     s&    
 GI_&_r,   r   c                  B     e Zd ZdZdZdZ fdZd Zd Zd Z	d Z
 xZS )	FreeBSDStrategyzq
    This is a FreeBSD hostname manipulation strategy class - it edits
    the /etc/rc.conf.d/hostname file.
    z/etc/rc.conf.d/hostnamerc   c                    t         t        |   |       | j                  j	                  | j
                  d      | _        y re   )rf   r   r+   r'   rg   rh   ri   rj   s     r*   r+   zFreeBSDStrategy.__init__  rl   r,   c                    | j                   g}| j                  j                  |      \  }}}|dk7  r"| j                  j                  d|||fz         t	        |      j                         S rn   rp   rs   s        r*   r7   z$FreeBSDStrategy.get_current_hostname  rx   r,   c                    | j                   |g}| j                  j                  |      \  }}}|dk7  r#| j                  j                  d|||fz         y y rn   rz   r{   s         r*   r9   z$FreeBSDStrategy.set_current_hostname  r|   r,   c                   t         j                  j                  | j                        sy	 t	        | j                        D ]9  }|j                         }|j                  d      s%|dd  j                  d      c S  y # t        $ rE}| j                  j                  dt        |      z  t        j                                Y d }~y d }~ww xY wr   r   r   s      r*   r<   z&FreeBSDStrategy.get_permanent_hostname  r   r   c                j   	 t         j                  j                  | j                        r_t	        | j                        D cg c]  }|j                          }}t        |      D ]   \  }}|j                  d      sd|z  ||<    n nd|z  g}t        | j                  d      5 }|j                  dj                  |      dz          d d d        y c c}w # 1 sw Y   y xY w# t        $ rE}| j                  j                  dt        |      z  t        j                                 Y d }~y d }~ww xY wr   )r   r   r   r   r	   rr   r   r   r   r   r   r   r'   r^   r   r   r   r   s           r*   r=   z&FreeBSDStrategy.set_permanent_hostname  s   	2ww~~dii(,:499,EFqFF(/ GAt{3#2T#9a
 )4/0dii% 1		%(4/01 1 G1 1 	2KK!!3ilB#..0 " 2 2	2sN   A C$ C$C$ >(C$ &$C
C$ C$ C!C$ !C$ $	D2-;D--D2)rI   rJ   rK   r   r   rh   r+   r7   r9   r<   r=   r   r   s   @r*   r   r     s/    
 %DGI&_22r,   r   c                  L     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Z xZS )
DarwinStrategya<  
    This is a macOS hostname manipulation strategy class. It uses
    /usr/sbin/scutil to set ComputerName, HostName, and LocalHostName.

    HostName corresponds to what most platforms consider to be hostname.
    It controls the name used on the command line and SSH.

    However, macOS also has LocalHostName and ComputerName settings.
    LocalHostName controls the Bonjour/ZeroConf name, used by services
    like AirDrop. This class implements a method, _scrub_hostname(), that mimics
    the transformations macOS makes on hostnames when entered in the Sharing
    preference pane. It replaces spaces with dashes and removes all special
    characters.

    ComputerName is the name used for user-facing GUI services, like the
    System Preferences/Sharing pane and when users connect to the Mac over the network.
    c                    t         t        |   |       | j                  j	                  dd      | _        d| _        | j                  | j                  j                  d         | _	        y )NscutilT)HostNameComputerNameLocalHostNamer5   )
rf   r   r+   r'   rg   r   
name_types_scrub_hostnamer6   scrubbed_namerj   s     r*   r+   zDarwinStrategy.__init__  sS    nd,V4kk..x>G!11$++2D2DV2LMr,   c                    t        |      }d}d}t        j                  |dt        |      z  |      }|j	                  |      }d|v r|j                  dd      }d|v r|j                  d      }|S )z
        LocalHostName only accepts valid DNS characters while HostName and ComputerName
        accept a much wider range of characters. This function aims to mimic how macOS
        translates a friendly name to the LocalHostName.
        z'"~`!@#$%^&*(){}[]/=?+\|-_ z.'-z--r   )r   str	maketransr   	translatereplacerstrip)r)   r5   replace_charsdelete_charstables        r*   r   zDarwinStrategy._scrub_hostname  sx     t}8mS3}3E-E|T~~e$ o<<,D o {{3r,   c                    | j                   ddg}| j                  j                  |      \  }}}|dk7  r&d|vr"| j                  j                  d|||fz         t	        |      j                         S )N--getr   r   zHostName: not setz4Failed to get current hostname rc=%d, out=%s, err=%srZ   r   r'   rq   r^   r   rr   rs   s        r*   r7   z#DarwinStrategy.get_current_hostname+  ss    {{GZ0{{..s3C7*#5KK!!&\`bdgil_m&m!n~##%%r,   c                    | j                   ddg}| j                  j                  |      \  }}}|dk7  r"| j                  j                  d|||fz         t	        |      j                         S )Nr  r   r   z6Failed to get permanent hostname rc=%d, out=%s, err=%srZ   r  rs   s        r*   r<   z%DarwinStrategy.get_permanent_hostname3  sk    {{G^4{{..s3C7KK!!&^bdfiknao&o!p~##%%r,   c           
        | j                   D ]  }| j                  d|g}|dk(  r%|j                  t        | j                               n|j                  t        |             | j
                  j                  |      \  }}}|dk7  s{| j
                  j                  dj                  t        |      t        |      t        |      |              y )Nz--setr   r   z#Failed to set {3} to '{2}': {0} {1}rZ   )	r   r   r   r   r   r'   rq   r^   format)r)   r5   hostname_typert   ru   rv   rw   s          r*   r=   z%DarwinStrategy.set_permanent_hostname;  s    !__ 	XM;;7C/

9T%7%789

9T?+;;2237LBSQw%%*O*V*VW`adWegpqtgu  xA  BF  xG  IV  +W%  X	Xr,   c                     y r.   rA   rB   s     r*   r9   z#DarwinStrategy.set_current_hostnameF  rC   r,   c                     y r.   rA   r1   s    r*   r/   z&DarwinStrategy.update_current_hostnameI  rC   r,   c                     j                   j                  d   t         fd j                  D              }t         fd j                  D              }||k7  r/ j                   j                  s j                         d _        y y )Nr5   c              3     K   | ]=  }j                   j                  j                  d |g      d   j                          ? yw)r     N)r'   rq   r   rr   ).0	name_typer)   s     r*   	<genexpr>z;DarwinStrategy.update_permanent_hostname.<locals>.<genexpr>P  sA       Bdm$++114;;2STUVW]]_  Bs   AAc              3  D   K   | ]  }|d k(  rj                   n  yw)r   N)r   )r  nr5   r)   s     r*   r  z;DarwinStrategy.update_permanent_hostname.<locals>.<genexpr>S  s$     mXYQ/5It11tSms    T)r'   r6   tupler   r8   r=   r(   )r)   	all_namesexpected_namesr5   s   `  @r*   r0   z(DarwinStrategy.update_permanent_hostnameL  s    {{!!&)   Bqu  rA  rA  B  B	 m]a]l]lmm &;;))++D1DL 'r,   )rI   rJ   rK   r   r+   r   r7   r<   r=   r9   r/   r0   r   r   s   @r*   r   r     s2    $N*&&	X r,   r   c                  R     e Zd ZdZdZdZeZ fdZd Z	d Z
d Zd Zd	 Zd
 Z xZS )Hostnamez
    This is a generic Hostname manipulation class that is subclassed
    based on platform.

    A subclass may wish to set different strategy instance to self.strategy.

    All subclasses MUST define platform and distribution (which may be None).
    GenericNc                @    t        t              }t        | |  |      S r.   )r   r  rf   __new__)clsargskwargsnew_clsrk   s       r*   r  zHostname.__new__j  s    '1S'*733r,   c                ~   || _         |j                  d   | _        |j                  d   | _        | j                  /t	               dt
        | j                     z     } ||      | _        y t        j                         dk(  r&t        j                  |      rt        |      | _        y | j                  |      | _        y )Nr5   usez
%sStrategyLinux)r'   r6   r5   r   globalsSTRATSstrategyr\   r]   r   is_systemd_managedr   strategy_class)r)   r'   strats      r*   r+   zHostname.__init__n  s    MM&)	=='88IlVDHH-==>E!&MDM__').E.X.XY_.`+F3DM //7DMr,   c                6    | j                   j                         S r.   )r$  r2   r1   s    r*   r2   z.Hostname.update_current_and_permanent_hostname|  s    }}BBDDr,   c                6    | j                   j                         S r.   )r$  r7   r1   s    r*   r7   zHostname.get_current_hostname  s    }}1133r,   c                :    | j                   j                  |       y r.   )r$  r9   rB   s     r*   r9   zHostname.set_current_hostname  s    **40r,   c                6    | j                   j                         S r.   )r$  r<   r1   s    r*   r<   zHostname.get_permanent_hostname  s    }}3355r,   c                :    | j                   j                  |       y r.   )r$  r=   rB   s     r*   r=   zHostname.set_permanent_hostname  s    ,,T2r,   )rI   rJ   rK   r   r\   r_   rM   r&  r  r+   r2   r7   r9   r<   r=   r   r   s   @r*   r  r  \  s=     HL*N48E4163r,   r  c                      e Zd ZdZdZ	  e       Zerd ee      cxk  rdk  rn  e
       eZ	y e
       # e
$ r eZ	Y yw xY w)SLESHostnamer!  Slesr      N)rI   rJ   rK   r\   r_   r   distribution_versionfloatr   r&  
ValueErrorrM   rA   r,   r*   r.  r.    s\    HL/79B%0D*E$K$K , *N, /./s   %7 7 A Ar.  c                      e Zd ZdZdZeZy)RHELHostnamer!  RedhatNrI   rJ   rK   r\   r_   r   r&  rA   r,   r*   r5  r5        HL#Nr,   r5  c                      e Zd ZdZdZeZy)CentOSHostnamer!  CentosNr7  rA   r,   r*   r:  r:    r8  r,   r:  c                      e Zd ZdZdZeZy)AnolisOSHostnamer!  AnolisNr7  rA   r,   r*   r=  r=    r8  r,   r=  c                      e Zd ZdZdZeZy)CloudlinuxserverHostnamer!  CloudlinuxserverNr7  rA   r,   r*   r@  r@    s    H%L#Nr,   r@  c                      e Zd ZdZdZeZy)CloudlinuxHostnamer!  
CloudlinuxNr7  rA   r,   r*   rC  rC        HL#Nr,   rC  c                      e Zd ZdZdZeZy)AlinuxHostnamer!  AlinuxNr7  rA   r,   r*   rG  rG    r8  r,   rG  c                      e Zd ZdZdZeZy)ScientificHostnamer!  
ScientificNr7  rA   r,   r*   rJ  rJ    rE  r,   rJ  c                      e Zd ZdZdZeZy)OracleLinuxHostnamer!  OracleNr7  rA   r,   r*   rM  rM    r8  r,   rM  c                      e Zd ZdZdZeZy)VirtuozzoLinuxHostnamer!  	VirtuozzoNr7  rA   r,   r*   rP  rP        HL#Nr,   rP  c                      e Zd ZdZdZeZy)AmazonLinuxHostnamer!  AmazonNr7  rA   r,   r*   rT  rT    r8  r,   rT  c                      e Zd ZdZdZeZy)DebianHostnamer!  DebianNrI   rJ   rK   r\   r_   r   r&  rA   r,   r*   rW  rW        HL!Nr,   rW  c                      e Zd ZdZdZeZy)KylinHostnamer!  KylinNrY  rA   r,   r*   r\  r\    s    HL!Nr,   r\  c                      e Zd ZdZdZeZy)CumulusHostnamer!  zCumulus-linuxNrY  rA   r,   r*   r_  r_    s    H"L!Nr,   r_  c                      e Zd ZdZdZeZy)KaliHostnamer!  KaliNrY  rA   r,   r*   ra  ra        HL!Nr,   ra  c                      e Zd ZdZdZeZy)ParrotHostnamer!  ParrotNrY  rA   r,   r*   re  re    rZ  r,   re  c                      e Zd ZdZdZeZy)UbuntuHostnamer!  UbuntuNrY  rA   r,   r*   rh  rh    rZ  r,   rh  c                      e Zd ZdZdZeZy)LinuxmintHostnamer!  	LinuxmintNrY  rA   r,   r*   rk  rk    s    HL!Nr,   rk  c                      e Zd ZdZdZeZy)LinaroHostnamer!  LinaroNrY  rA   r,   r*   rn  rn     rZ  r,   rn  c                      e Zd ZdZdZeZy)DevuanHostnamer!  DevuanNrY  rA   r,   r*   rq  rq    rZ  r,   rq  c                      e Zd ZdZdZeZy)RaspbianHostnamer!  RaspbianNrY  rA   r,   r*   rt  rt    s    HL!Nr,   rt  c                      e Zd ZdZdZeZy)UosHostnamer!  UosNrY  rA   r,   r*   rw  rw        HL!Nr,   rw  c                      e Zd ZdZdZeZy)DeepinHostnamer!  DeepinNrY  rA   r,   r*   r{  r{    rZ  r,   r{  c                      e Zd ZdZdZeZy)GentooHostnamer!  GentooN)rI   rJ   rK   r\   r_   r   r&  rA   r,   r*   r~  r~    r8  r,   r~  c                      e Zd ZdZdZeZy)ALTLinuxHostnamer!  AltlinuxNr7  rA   r,   r*   r  r  $  s    HL#Nr,   r  c                      e Zd ZdZdZeZy)AlpineLinuxHostnamer!  r   N)rI   rJ   rK   r\   r_   r   r&  rA   r,   r*   r  r  *  r8  r,   r  c                      e Zd ZdZdZeZy)OpenBSDHostnamer   N)rI   rJ   rK   r\   r_   r   r&  rA   r,   r*   r  r  0      HL$Nr,   r  c                      e Zd ZdZdZeZy)SolarisHostnameSunOSN)rI   rJ   rK   r\   r_   r   r&  rA   r,   r*   r  r  6  s    HL$Nr,   r  c                      e Zd ZdZdZeZy)FreeBSDHostnamer   NrI   rJ   rK   r\   r_   r   r&  rA   r,   r*   r  r  <  r  r,   r  c                      e Zd ZdZdZeZy)NetBSDHostnameNetBSDNr  rA   r,   r*   r  r  B  s    HL$Nr,   r  c                      e Zd ZdZdZeZy)NeonHostnamer!  NeonNrY  rA   r,   r*   r  r  H  rc  r,   r  c                      e Zd ZdZdZeZy)DarwinHostnamer   N)rI   rJ   rK   r\   r_   r   r&  rA   r,   r*   r  r  N  s    HL#Nr,   r  c                      e Zd ZdZdZeZy)VoidLinuxHostnamer!  VoidNrY  rA   r,   r*   r  r  T  rc  r,   r  c                      e Zd ZdZdZeZy)PopHostnamer!  PopNrY  rA   r,   r*   r  r  Z  ry  r,   r  c                      e Zd ZdZdZeZy)EurolinuxHostnamer!  	EurolinuxNr7  rA   r,   r*   r  r  `  rR  r,   r  c                 r   t        t        t        dd      t        dt        t        j	                                           d      } t        |       }| j                  d   }|j                         }|j                         }|j                         }||k7  r|}n|}t        ||t        |j                  d      d	   |t        j                         dj                  t        j                         j                  d      d
d                    }|rd|z   dz   d|z   dz   d|d<    | j                  di | y )Nr   T)typerequired)r  choices)r5   r   )argument_specsupports_check_moder5   .r   r  )ansible_hostnameansible_nodenameansible_fqdnansible_domain)r(   r5   ansible_factszhostname = r   )afterbeforediffrA   )r   dictlistr#  keysr  r6   r7   r<   r2   r   socketgetfqdnr   	exit_json)r'   rc   r5   current_hostnamepermanent_hostnamer(   name_beforekws           r*   mainr  f  s/   540%fkkm)<=
 !F H== D446!88:<<>G&( 
gD $**S/!2D26.4nn.>039I9O9OPS9TUVUW9X0Y[
\B ,t3d: - ;d BD6
 Frr,   __main__)P
__future__r   DOCUMENTATIONEXAMPLESr   r\   r  r   "ansible.module_utils.compat.typingmodule_utilscompattypingtansible.module_utils.basicr   r   r   $ansible.module_utils.common.sys_infor   -ansible.module_utils.facts.system.service_mgrr    ansible.module_utils.facts.utilsr	   r
   +ansible.module_utils.common.text.convertersr   r   r#  objectr%   rM   rb   r   r   r   r   r   r   r   r   r   r   r  r.  r5  r:  r=  r@  rC  rG  rJ  rM  rP  rT  rW  r\  r_  ra  re  rh  rk  rn  rq  rt  rw  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  rI   rA   r,   r*   <module>r     s   #-^	 
    . . 
 G Q M J 
"$"6 $"NPL PBl 62< 20< )2\ )2X_\ _&/l /d$2\ $2N_l _8 _l  _F92l 92x] \ ] @-3v -3`/8 /$8 $$X $$x $$x $$ $$X $$ $$( $$X $$( $"X ""H ""h ""8 ""X ""X "" ""X ""X ""x ""( ""X "$X $$x $$( $%h %%h %%h %%X %"8 "$X $" ""( "$ $"J zF r,   