o nnhk$@sjddlmZdZdZdZddlmZmZddlm Z ddZ d d Z d d Z d dZ edkr3e dSdS)) annotationsaw --- 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 ' 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 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 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. debconf is extensively used for pre-seeding configuration prior to installation rather than modifying configurations. So, while dpkg-reconfigure does use debconf data, it is not always authoritative and you may need to check how your package is handled. - Also note dpkg-reconfigure is a 3-phase process. It invokes the control scripts from the C(/var/lib/dpkg/info) directory with the C(.prerm reconfigure ), C(.config reconfigure ) and C(.postinst control ) arguments. - The main issue is that the C(.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 dpkg-reconfigure will effectively ignore changes made by debconf. - However as dpkg-reconfigure only executes the C(.config) step if the file exists, it is possible to rename it to C(/var/lib/dpkg/info/.config.ignore) before executing C(dpkg-reconfigure -f noninteractive ) 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 'raw'. type: raw aliases: [ answer ] unseen: description: - Do not set '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 Cs|dd}|g}||\}}}|dkr$|jd|d|d|d|dD]6} | |s1q)| d } t| d kr?d Sz| d |krS| d |krS| d WSWq)ty_Yd SwdS)Nzdebconf-get-selectionsTrzFailed to get the value 'z' from 'z': msg  ) get_bin_path run_command fail_jsonsplit startswithlen IndexError) modulepkgquestionvtypegetselcmdrcouterrlinefieldsr!B/usr/local/lib/python3.10/dist-packages/ansible/modules/debconf.pyget_password_values&     r#c Csv|dd|g}|d|\}}}|dkr|j|di}|D]}|dd\}} | ||d<q#|S) Nz debconf-showT rr:r *)rrjoinr splitlinesrstrip) rrrrrr selectionsrkeyvaluer!r!r"get_selectionss  r-c Cs@|dd}|g}|r|dd||||g}|j||dS)Nzdebconf-set-selectionsTz-ur$)data)rappendr'r) rrrrr,unseensetselrr.r!r!r" set_selections  r2c Cstttdddgdtdddgdtdgdd td d gdtd d ddgdfdd}|jd}|jd}|jd}|jd}|jd}t||}d }d}|dur|dusZ|dur`|jdd|dkrjt|}||vrqd}n[||} |dkrt||} nD|dkrt||||} n8|dkrt|t rzt |}Wnt y} z|jdt | dWYd} ~ nd} ~ wwt dd| d D} || krd}|rJ|js|dkrt|t rzd!|}Wnt y} z|jdt | dWYd} ~ nd} ~ wwt||||||\} }} | r|j| d||i} ||vr(|||i}nd||<i}|jr@|}|| ||d"}|j||| ||d#|j|||d$dS)%NstrTr)typerequiredaliases selectionsetting)r4r6) booleanerror multiselectnotepasswordseenselectstringtexttitle)r4choicesrawanswerboolF)r4default)namerrr,r0)rrr,) argument_specrequired_togethersupports_check_moderHrrr,r0r zAwhen supplying a question you must supply a valid vtype and valuerr9r=r;z,Invalid value provided for 'multiselect': %scSsg|]}|qSr!)r)).0ir!r!r" szmain..,z, )beforeafter)changedrcurrentpreviousdiff)rRrrS)rdictparamsr-rrlowerr# isinstancelistsorted TypeErrorrr check_moder'r2_diffcopyupdate exit_json)rrrrr,r0prevrRrexistingexcrecurr diff_dictrQr!r!r"mains                rh__main__N) __future__r DOCUMENTATIONEXAMPLESRETURN+ansible.module_utils.common.text.convertersrransible.module_utils.basicrr#r-r2rh__name__r!r!r!r"s R#  Q