community.libvirt.virt_secret module – Manage libvirt secrets and their values
Note
This module is part of the community.libvirt collection (version 2.2.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.libvirt.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.libvirt.virt_secret.
New in community.libvirt 2.1.0
Synopsis
Manage libvirt secrets. Can add, remove or update secrets in libvirt.
Can be used to set secrets value.
Requirements
The below requirements are needed on the host that executes this module.
libvirt
lxml
PyYAML
Parameters
Parameter |
Comments |
|---|---|
Executes commands to manage secret. If defined If defined If defined If defined If defined Choices:
|
|
A value of the secret which will be stored in the libvirt secret. As in majority cases secrets are private, password is defined only
during secret creation or when |
|
Defines a secret as a set of fields instead of raw XML. This property is mutually exclusive with If |
|
Defines secret description. |
|
If Default value is Choices:
|
|
If Default value is Choices:
|
|
Specifies what this secret is used for. Possible values are Choices:
|
|
Defines unique secret_ID. Unique for each |
|
Alternative for the If Can be used to update existing secrets properties. If If Mutually exclusive with Choices:
|
|
Libvirt connection uri. Default: |
|
Secret UUID. The value is unique across all secret types. If UUID value is also defined in the |
|
XML document used with the define command. Must be raw XML content using |
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: full In check mode, secrets are not actually created, updated or deleted. Module compares existing state of the secret in libvirt and check if change is required. Will always produce changed with |
Check mode is fully supported. |
|
Support: full For all made changes except In check_mode diff will contain the same output as if it was executed normally. |
Module provides state change as a dict. |
|
Support: partial If In most of the cases secrets are private and their value is not obtainable from the libvirt. |
In most cases, this module is idempotent. |
Examples
---
- name: Create new secret using xml option and command
community.libvirt.virt_secret:
command: create
xml: |
<secret ephemeral='no' private='yes'>
<uuid>e4b5978c-ba37-5605-97c1-4a20413d0fc9</uuid>
<description>test ceph pool secret</description>
<usage type='ceph'>
<name>test_secret</name>
</usage>
</secret>
- name: Get secret XML by uuid
community.libvirt.virt_secret:
uuid: e4b5978c-ba37-5605-97c1-4a20413d0fc9
command: get_xml
register: result
- name: Get XML by secret usage and usage_id
community.libvirt.virt_secret:
secret:
usage: ceph
usage_id: test_secret
command: get_xml
register: result
- name: Print found XML
ansible.builtin.debug:
var: result.secret_xml
- name: Define secret using options secret and uuid
community.libvirt.virt_secret:
uuid: e4b5978c-ba37-5605-97c1-4a20413d0fc9
secret:
usage: tls
usage_id: test_secret
description: Test TLS secret
state: present
- name: List all currently defined secrets
community.libvirt.virt_secret:
command: list_secrets
register: result
- name: Print found secrets list
ansible.builtin.debug:
var: result.secrets_list
- name: Set value of the secret
community.libvirt.virt_secret:
uuid: e4b5978c-ba37-5605-97c1-4a20413d0fc9
command: set_value
password: somesecureandrandomsecret1234
- name: Remove secret
community.libvirt.virt_secret:
uuid: 57ea8fd0-9b82-4e54-9d16-df7d2765844d
state: absent
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
When (command=list_secrets) returns a list of secrets in XML format. Returned: success Sample: |
|
When command=get_xml returns XML definition of the secret. Returned: success Sample: |