diff --git a/locale/fr/LC_MESSAGES/user_data_ansible.po b/locale/fr/LC_MESSAGES/user_data_ansible.po index d57d2fe..746fc99 100644 --- a/locale/fr/LC_MESSAGES/user_data_ansible.po +++ b/locale/fr/LC_MESSAGES/user_data_ansible.po @@ -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" diff --git a/locale/user_data_ansible.pot b/locale/user_data_ansible.pot index 1ed7498..af651fe 100644 --- a/locale/user_data_ansible.pot +++ b/locale/user_data_ansible.pot @@ -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 \n" "Language-Team: LANGUAGE \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 "" diff --git a/src/rougail/user_data_ansible/__init__.py b/src/rougail/user_data_ansible/__init__.py index a3ad815..ae545e3 100644 --- a/src/rougail/user_data_ansible/__init__.py +++ b/src/rougail/user_data_ansible/__init__.py @@ -16,16 +16,19 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . """ -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())) diff --git a/src/rougail/user_data_ansible/config.py b/src/rougail/user_data_ansible/config.py index e55b11e..c1d5923 100644 --- a/src/rougail/user_data_ansible/config.py +++ b/src/rougail/user_data_ansible/config.py @@ -19,17 +19,35 @@ along with this program. If not, see . 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",) diff --git a/src/rougail/locale/fr/LC_MESSAGES/user_data_ansible.mo b/src/rougail/user_data_ansible/locale/fr/LC_MESSAGES/user_data_ansible.mo similarity index 90% rename from src/rougail/locale/fr/LC_MESSAGES/user_data_ansible.mo rename to src/rougail/user_data_ansible/locale/fr/LC_MESSAGES/user_data_ansible.mo index 7128b26..8a10f34 100644 Binary files a/src/rougail/locale/fr/LC_MESSAGES/user_data_ansible.mo and b/src/rougail/user_data_ansible/locale/fr/LC_MESSAGES/user_data_ansible.mo differ