%PDF- %PDF-
| Direktori : /lib/python3.9/site-packages/ansible/modules/__pycache__/ |
| Current File : //lib/python3.9/site-packages/ansible/modules/__pycache__/apt_key.cpython-39.opt-1.pyc |
a
�)g�E � @ s� d dl mZmZmZ eZdZdZdZd dl Z d dl
mZ d dlm
Z
d dlmZ d d lmZ d d
lmZ dadadZdd� Zd
d� Zdd� Zdd� Zd)dd�Zdd� Zdd� Zdd� Zd*dd�Zdd� Z d d!� Z!d+d"d#�Z"d$d%� Z#d&d'� Z$e%d(kr�e$� dS ),� )�absolute_import�division�print_functiona�
---
module: apt_key
author:
- Jayson Vantuyl (@jvantuyl)
version_added: "1.0"
short_description: Add or remove an apt key
description:
- Add or remove an I(apt) key, optionally downloading it.
extends_documentation_fragment: action_common_attributes
attributes:
check_mode:
support: full
diff_mode:
support: none
platform:
platforms: debian
notes:
- The apt-key command has been deprecated and suggests to 'manage keyring files in trusted.gpg.d instead'. See the Debian wiki for details.
This module is kept for backwards compatibility for systems that still use apt-key as the main way to manage apt repository keys.
- As a sanity check, downloaded key id must match the one specified.
- "Use full fingerprint (40 characters) key ids to avoid key collisions.
To generate a full-fingerprint imported key: C(apt-key adv --list-public-keys --with-fingerprint --with-colons)."
- If you specify both the key id and the URL with C(state=present), the task can verify or add the key as needed.
- Adding a new key requires an apt cache update (e.g. using the M(ansible.builtin.apt) module's update_cache option).
requirements:
- gpg
options:
id:
description:
- The identifier of the key.
- Including this allows check mode to correctly report the changed state.
- If specifying a subkey's id be aware that apt-key does not understand how to remove keys via a subkey id. Specify the primary key's id instead.
- This parameter is required when C(state) is set to C(absent).
type: str
data:
description:
- The keyfile contents to add to the keyring.
type: str
file:
description:
- The path to a keyfile on the remote server to add to the keyring.
type: path
keyring:
description:
- The full path to specific keyring file in C(/etc/apt/trusted.gpg.d/).
type: path
version_added: "1.3"
url:
description:
- The URL to retrieve key from.
type: str
keyserver:
description:
- The keyserver to retrieve key from.
type: str
version_added: "1.6"
state:
description:
- Ensures that the key is present (added) or absent (revoked).
type: str
choices: [ absent, present ]
default: present
validate_certs:
description:
- If C(false), SSL certificates for the target url will not be validated. This should only be used
on personally controlled sites using self-signed certificates.
type: bool
default: 'yes'
ah
- name: One way to avoid apt_key once it is removed from your distro
block:
- name: somerepo |no apt key
ansible.builtin.get_url:
url: https://download.example.com/linux/ubuntu/gpg
dest: /etc/apt/trusted.gpg.d/somerepo.asc
- name: somerepo | apt source
ansible.builtin.apt_repository:
repo: "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/myrepo.asc] https://download.example.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present
- name: Add an apt key by id from a keyserver
ansible.builtin.apt_key:
keyserver: keyserver.ubuntu.com
id: 36A1D7869245C8950F966E92D8576A8BA88D21E9
- name: Add an Apt signing key, uses whichever key is at the URL
ansible.builtin.apt_key:
url: https://ftp-master.debian.org/keys/archive-key-6.0.asc
state: present
- name: Add an Apt signing key, will not download if present
ansible.builtin.apt_key:
id: 9FED2BCBDCD29CDF762678CBAED4B06F473041FA
url: https://ftp-master.debian.org/keys/archive-key-6.0.asc
state: present
- name: Remove a Apt specific signing key, leading 0x is valid
ansible.builtin.apt_key:
id: 0x9FED2BCBDCD29CDF762678CBAED4B06F473041FA
state: absent
# Use armored file since utf-8 string is expected. Must be of "PGP PUBLIC KEY BLOCK" type.
- name: Add a key from a file on the Ansible server
ansible.builtin.apt_key:
data: "{{ lookup('ansible.builtin.file', 'apt.asc') }}"
state: present
- name: Add an Apt signing key to a specific keyring file
ansible.builtin.apt_key:
id: 9FED2BCBDCD29CDF762678CBAED4B06F473041FA
url: https://ftp-master.debian.org/keys/archive-key-6.0.asc
keyring: /etc/apt/trusted.gpg.d/debian.gpg
- name: Add Apt signing key on remote server to keyring
ansible.builtin.apt_key:
id: 9FED2BCBDCD29CDF762678CBAED4B06F473041FA
file: /tmp/apt.gpg
state: present
a�
after:
description: List of apt key ids or fingerprints after any modification
returned: on change
type: list
sample: ["D8576A8BA88D21E9", "3B4FE6ACC0B21F32", "D94AA3F0EFE21092", "871920D1991BC93C"]
before:
description: List of apt key ids or fingprints before any modifications
returned: always
type: list
sample: ["3B4FE6ACC0B21F32", "D94AA3F0EFE21092", "871920D1991BC93C"]
fp:
description: Fingerprint of the key to import
returned: always
type: str
sample: "D8576A8BA88D21E9"
id:
description: key id from source
returned: always
type: str
sample: "36A1D7869245C8950F966E92D8576A8BA88D21E9"
key_id:
description: calculated key id, it should be same as 'id', but can be different
returned: always
type: str
sample: "36A1D7869245C8950F966E92D8576A8BA88D21E9"
short_id:
description: calculated short key id
returned: always
type: str
sample: "A88D21E9"
N)�
format_exc)� to_native)�
AnsibleModule)�get_best_parsable_locale)� fetch_urlc C s( t td�s"t| �}t|||d�t_tjS )N�result)�LANG�LC_ALL�LC_MESSAGES)�hasattr�lang_envr �dictr
)�module�locale� r �;/usr/lib/python3.9/site-packages/ansible/modules/apt_key.pyr � s
r c C s | j ddd�a| j ddd�ad S )Nzapt-keyT)�requiredZgpg)Zget_bin_path�apt_key_bin�gpg_bin)r r r r �find_needed_binaries� s r c C s2 dD ]}t j�|�}|r qq|r.| d| 7 } | S )N)ZHTTPS_PROXYZhttps_proxyZ
HTTP_PROXYZ
http_proxyz" --keyserver-options http-proxy=%s)�os�environ�get)�cmdZenvvar�proxyr r r �add_http_proxy� s r c C s� t t| �d� | �� } | �d�r,| dd� } t| �}|dkrT|dkrT|dkrTtd��| dd� }| }|dkrx| dd� }||| fS ) a� validate the key_id and break it into segments
:arg key_id: The key_id as supplied by the user. A valid key_id will be
8, 16, or more hexadecimal chars with an optional leading ``0x``.
:returns: The portion of key_id suitable for apt-key del, the portion
suitable for comparisons with --list-public-keys, and the portion that
can be used with --recv-key. If key_id is long enough, these will be
the last 8 characters of key_id, the last 16 characters, and all of
key_id. If key_id is not long enough, some of the values will be the
same.
* apt-key del <= 1.10 has a bug with key_id != 8 chars
* apt-key adv --list-public-keys prints 16 chars
* apt-key adv --recv-key can take more chars
� Z0X� N� z=key_id must be 8, 16, or 16+ hexadecimal characters in length���i�)�intr �upper�
startswith�len�
ValueError)�key_idZ
key_id_len�short_key_id�fingerprintr r r �parse_key_id� s
r+ Fc
C s� g }t | ��d�}|D ]�}|�d�s.|�d�rd|vrz"|�� }|d }|�d�\}}W nJ ttfy� z|�d�}|d }W n ttfy� Y Y qY n0 Y n0 |�|� q|r�|r�t|�}|S ) N�
Zpub�subZexpired� �/�:� )r �splitr% �
IndexErrorr'