
    Vh$                    j    d dl mZ dZdZdZd dlmZmZ d dlm	Z	 d Z
d Zd	 Zd
 Zedk(  r e        yy)    )annotationsa  
---
module: debconf
short_description: Configure a .deb package
description:
     - Configure a .deb package using debconf-set-selections.
     - Or just query existing selections.
version_added: "1.6"
extends_documentation_fragment:
- action_common_attributes
attributes:
    check_mode:
        support: full
    diff_mode:
        support: full
    platform:
        support: full
        platforms: debian
notes:
    - This module requires the command line debconf tools.
    - Several questions have to be answered (depending on the package).
      Use 'debconf-show <package>' on any Debian or derivative with the package
      installed to see questions/settings available.
    - Some distros will always record tasks involving the setting of passwords as changed. This is due to C(debconf-get-selections) masking passwords.
    - It is highly recommended to add C(no_log=True) to the task while handling sensitive information using this module.
    - The M(ansible.builtin.debconf) module does not reconfigure packages, it just updates the debconf database.
      An additional step is needed (typically with C(notify) if debconf makes a change)
      to reconfigure the package and apply the changes.
      C(debconf) is extensively used for pre-seeding configuration prior to installation
      rather than modifying configurations.
      So, while C(dpkg-reconfigure) does use debconf data, it is not always authoritative
      and you may need to check how your package is handled.
    - Also note C(dpkg-reconfigure) is a 3-phase process. It invokes the
      control scripts from the C(/var/lib/dpkg/info) directory with the
      C(<package>.prerm  reconfigure <version>),
      C(<package>.config reconfigure <version>) and C(<package>.postinst control <version>) arguments.
    - The main issue is that the C(<package>.config reconfigure) step for many packages
      will first reset the debconf database (overriding changes made by this module) by
      checking the on-disk configuration. If this is the case for your package then
      C(dpkg-reconfigure) will effectively ignore changes made by debconf.
    - However as C(dpkg-reconfigure) only executes the C(<package>.config) step if the file
      exists, it is possible to rename it to C(/var/lib/dpkg/info/<package>.config.ignore)
      before executing C(dpkg-reconfigure -f noninteractive <package>) and then restore it.
      This seems to be compliant with Debian policy for the .config file.
requirements:
- debconf
- debconf-utils
options:
  name:
    description:
      - Name of package to configure.
    type: str
    required: true
    aliases: [ pkg ]
  question:
    description:
      - A debconf configuration setting.
    type: str
    aliases: [ selection, setting ]
  vtype:
    description:
      - The type of the value supplied.
      - It is highly recommended to add C(no_log=True) to task while specifying O(vtype=password).
      - V(seen) was added in Ansible 2.2.
      - After Ansible 2.17, user can specify C(value) as a list, if C(vtype) is set as V(multiselect).
    type: str
    choices: [ boolean, error, multiselect, note, password, seen, select, string, text, title ]
  value:
    description:
      - Value to set the configuration to.
      - After Ansible 2.17, C(value) is of type C(raw).
    type: raw
    aliases: [ answer ]
  unseen:
    description:
      - Do not set C(seen) flag when pre-seeding.
    type: bool
    default: false
author:
- Brian Coca (@bcoca)
az  
- name: Set default locale to fr_FR.UTF-8
  ansible.builtin.debconf:
    name: locales
    question: locales/default_environment_locale
    value: fr_FR.UTF-8
    vtype: select

- name: Set to generate locales
  ansible.builtin.debconf:
    name: locales
    question: locales/locales_to_be_generated
    value: en_US.UTF-8 UTF-8, fr_FR.UTF-8 UTF-8
    vtype: multiselect

- name: Accept oracle license
  ansible.builtin.debconf:
    name: oracle-java7-installer
    question: shared/accepted-oracle-license-v1-1
    value: 'true'
    vtype: select

- name: Specifying package you can register/return the list of questions and current values
  ansible.builtin.debconf:
    name: tzdata

- name: Pre-configure tripwire site passphrase
  ansible.builtin.debconf:
    name: tripwire
    question: tripwire/site-passphrase
    value: "{{ site_passphrase }}"
    vtype: password
  no_log: True
#)to_text	to_native)AnsibleModulec                z   | j                  dd      }|g}| j                  |      \  }}}|dk7  r| j                  d| d| d|        |j                  d      D ]M  }	|	j	                  |      s|	j                  d	      }
t        |
      d
k  r y	 |
d   |k(  r|
d   |k(  r|
d
   c S O y # t        $ r Y  yw xY w)Nzdebconf-get-selectionsTr   zFailed to get the value 'z' from 'z': msg
	          )get_bin_pathrun_command	fail_jsonsplit
startswithlen
IndexError)modulepkgquestionvtypegetselcmdrcouterrlinefieldss              G/home/dcms/DCMS/lib/python3.12/site-packages/ansible/modules/debconf.pyget_password_valuer$      s      !94@F(C%%c*LBS	Qw8
(3%sSVRWXY		$ s# D!v;!	ayH$e);ay   		s   B--	B:9B:c                \   | j                  dd      |g}| j                  dj                  |            \  }}}|dk7  r| j                  |       i }|j	                         D ]G  }|j                  dd      \  }}	|	j                         ||j                  d      j                         <   I |S )	Nzdebconf-showT r   r	   :r   *)r   r   joinr   
splitlinesr   strip)
r   r   r   r   r   r    
selectionsr!   keyvalues
             r#   get_selectionsr/      s    ~t4c
:C%%chhsm4LBS	QwS!J  ;zz#q)e-2[[]
399S>'')*;     c                    | j                  dd      }|g}|r|j                  d       dj                  ||||g      }| j                  ||      S )Nzdebconf-set-selectionsTz-ur&   )data)r   appendr)   r   )	r   r   r   r   r.   unseensetselr   r2   s	            r#   set_selectionr6      sX      !94@F(C

488S(E512Dc--r0   c                    t        t        t        dddg      t        dddg      t        dg d	      t        d
dg      t        dd            g dfd      } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }t        | |      }d}d}|||| j	                  d       |dk(  rt        |      j                         }||vrd}n||   }	|dk(  rt        ||         j                         }	nk|dk(  rt        | |||      }	nW|dk(  rRt        |t              rB	 t        |      }t        |	j                  d      D cg c]  }|j                          c}      }	||	k7  rd}|r| j                  sO|dk(  r"t        |t              r	 dj!                  |      }t#        | |||||      \  }}}|r| j	                  |       ||i}||v r|||   i}nd||<   i }| j$                  r&|j'                         }|j)                  |       ||d }| j+                  |||||!       | j+                  |||"       y # t        $ r)}
| j	                  dt        |
      z         Y d }
~
;d }
~
ww xY wc c}w # t        $ r)}
| j	                  dt        |
      z         Y d }
~
d }
~
ww xY w)#NstrTr   )typerequiredaliases	selectionsetting)r9   r;   )
booleanerrormultiselectnotepasswordseenselectstringtexttitle)r9   choicesrawanswerboolF)r9   default)namer   r   r.   r4   )r   r   r.   )argument_specrequired_togethersupports_check_moderM   r   r   r.   r4   r   zAwhen supplying a question you must supply a valid vtype and valuer	   r>   rB   r@   z,Invalid value provided for 'multiselect': %s,z, )beforeafter)changedr
   currentpreviousdiff)rT   r
   rU   )r   dictparamsr/   r   r   lowerr$   
isinstancelistsorted	TypeErrorr   r   r+   
check_moder)   r6   _diffcopyupdate	exit_json)r   r   r   r   r.   r4   prevrT   r
   existingexcir   ecurr	diff_dictrS   s                    r#   mainrk      s   54%Au{I.FGE  ,P  QEH:6VU3
 :; 
F --
C}}Z(HMM'"EMM'"E]]8$F&#&DG
C=EM!de IEN((*E 4GH~H	!"4>288:*$-fc8UK-'Jud,Cj"5ME "hnnS6I"J1779"JK   %*UD*Aj IIe,E 'vsHeUFSJBQ  Q '% td8n-DDN	<<IIKELL#'%8Ic4$U^_
W#t<A ! j$$)WZcdgZh)h$iij"J ! j$$)WZcdgZh)h$iijs6   I  *J3J  	J)JJ	K#KK__main__N)
__future__r   DOCUMENTATIONEXAMPLESRETURN+ansible.module_utils.common.text.convertersr   r   ansible.module_utils.basicr   r$   r/   r6   rk   __name__ r0   r#   <module>ru      sR    #Pd!F 
 J 42 .N=b zF r0   