fix: support user data ansible with output ansible

This commit is contained in:
egarette@silique.fr 2024-11-27 16:22:34 +01:00
parent e7157de7b5
commit 71e0fcd8cf
5 changed files with 55 additions and 16 deletions

View file

@ -5,8 +5,8 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2024-11-25 10:49+0100\n"
"PO-Revision-Date: 2024-11-25 10:51+0100\n"
"POT-Creation-Date: 2024-11-27 16:19+0100\n"
"PO-Revision-Date: 2024-11-27 16:21+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
@ -16,6 +16,6 @@ msgstr ""
"Generated-By: pygettext.py 1.5\n"
"X-Generator: Poedit 3.5\n"
#: src/rougail/user_data_ansible/__init__.py:43
#: src/rougail/user_data_ansible/__init__.py:46
msgid "ansible is not set in step.user_data"
msgstr "ansible n'est pas définit dans step.user_data"

View file

@ -5,7 +5,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-11-25 10:53+0100\n"
"POT-Creation-Date: 2024-11-27 16:21+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -15,7 +15,7 @@ msgstr ""
"Generated-By: pygettext.py 1.5\n"
#: src/rougail/user_data_ansible/__init__.py:43
#: src/rougail/user_data_ansible/__init__.py:46
msgid "ansible is not set in step.user_data"
msgstr ""

View file

@ -16,16 +16,19 @@ You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from rougail import RougailConfig
from rougail.user_data_file import RougailUserDataFile
from pathlib import Path
from ansible.parsing.vault import VaultLib, PromptVaultSecret
from ansible.module_utils._text import to_bytes
from pathlib import Path
from rougail import RougailConfig
from rougail.user_data_file import RougailUserDataFile
from .i18n import _
class RougailUserDataAnsible(RougailUserDataFile):
"""Load Ansible data from encrypted file
"""
def __init__(
self,
config,
@ -49,9 +52,13 @@ class RougailUserDataAnsible(RougailUserDataFile):
self.warnings = []
def open(self, filename: str) -> dict:
prompt = PromptVaultSecret(to_bytes(self.secret), 'default', ["Vault password: "])
vault = VaultLib([('default', prompt)])
with Path(filename).open('rb') as fh:
"""Open file
"""
prompt = PromptVaultSecret(
to_bytes(self.secret), "default", ["Vault password: "]
)
vault = VaultLib([("default", prompt)])
with Path(filename).open("rb") as fh:
return self.yaml.load(vault.decrypt(fh.read()))

View file

@ -19,17 +19,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
def get_rougail_config(
*,
backward_compatibility=True,
backward_compatibility: bool = True, # pylint: disable=unused-argument
) -> dict:
options = """
"""get rougail config for ansible"""
# redefine ansible family if already exists (for output)
# or create a new only only for user data
options = [
"""
ansible:
description: Configuration rougail-user-data-ansible
exists: true
redefine: true
description: Configuration of user data or output Ansible
disabled:
type: jinja
jinja: |
{% if step.output != 'ansible' and 'ansible' not in step.user_data %}
disabled
{% endif %}
""",
"""
ansible:
exists: false
description: Configuration of user data Ansible
disabled:
type: jinja
jinja: |
{% if 'ansible' not in step.user_data %}
disabled
{% endif %}
filename:
description: Ansible filename inventory
type: unix_filename
@ -39,10 +57,24 @@ ansible:
test_existence: True
types:
- file
disabled:
type: jinja
jinja: |
{% if 'ansible' not in step.user_data %}
disabled
{% endif %}
secret:
description: Secret to decrypt file
type: secret
"""
disabled:
type: jinja
jinja: |
{% if 'ansible' not in step.user_data %}
disabled
{% endif %}
""",
]
return {
"name": "ansible",
"process": "user data",
@ -51,4 +83,4 @@ ansible:
}
__all__ = "get_rougail_config"
__all__ = ("get_rougail_config",)