From a359838122aa97e02e3acd76685af47f0d7e64db Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Mon, 23 Feb 2026 13:55:01 +0100 Subject: [PATCH 1/2] feat: Add ansible.cfg to patternizer We need the ansible config in the patternizer, so we can always have a reliable working ansible configuration. --- resources/ansible.cfg | 12 ++++++++++++ src/cmd/init.go | 7 +++++++ src/cmd/upgrade.go | 5 +++++ test/initial_ansible_cfg_overwrite | 7 +++++++ test/integration_test.sh | 23 +++++++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 resources/ansible.cfg create mode 100644 test/initial_ansible_cfg_overwrite diff --git a/resources/ansible.cfg b/resources/ansible.cfg new file mode 100644 index 0000000..91d0379 --- /dev/null +++ b/resources/ansible.cfg @@ -0,0 +1,12 @@ +[defaults] +localhost_warning=False +retry_files_enabled=False +# Retry files disabled to avoid cluttering CI/CD environments +interpreter_python=auto_silent +timeout=30 +library=~/.ansible/plugins/modules:./ansible/plugins/modules:./common/ansible/plugins/modules:/usr/share/ansible/plugins/modules +roles_path=~/.ansible/roles:./ansible/roles:./common/ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles +filter_plugins=~/.ansible/plugins/filter:./ansible/plugins/filter:./common/ansible/plugins/filter:/usr/share/ansible/plugins/filter +# use the collections from the util. container, +# change below if you want to test local collections +collections_path=/usr/share/ansible/collections diff --git a/src/cmd/init.go b/src/cmd/init.go index 70b9cda..040e272 100644 --- a/src/cmd/init.go +++ b/src/cmd/init.go @@ -47,6 +47,13 @@ func runInit(withSecrets bool) error { return fmt.Errorf("error copying pattern.sh: %w", err) } + // Always copy ansible.cfg to the pattern repo + ansibleCfgSrc := filepath.Join(resourcesDir, "ansible.cfg") + ansibleCfgDst := filepath.Join(repoRoot, "ansible.cfg") + if err := fileutils.CopyFile(ansibleCfgSrc, ansibleCfgDst); err != nil { + return fmt.Errorf("error copying ansible.cfg: %w", err) + } + // Always copy Makefile-common to the pattern repo makefilePatternSrc := filepath.Join(resourcesDir, "Makefile-common") makefilePatternDst := filepath.Join(repoRoot, "Makefile-common") diff --git a/src/cmd/upgrade.go b/src/cmd/upgrade.go index be7277e..6d85c39 100644 --- a/src/cmd/upgrade.go +++ b/src/cmd/upgrade.go @@ -47,6 +47,11 @@ func runUpgrade(replaceMakefile bool) error { return fmt.Errorf("error copying Makefile-common: %w", err) } + // Copy copy ansible.cfg + if err := fileutils.CopyFile(filepath.Join(resourcesDir, "ansible.cfg"), filepath.Join(repoRoot, "ansible.cfg")); err != nil { + return fmt.Errorf("error copying ansible.cfg: %w", err) + } + // Makefile handling makefileSrc := filepath.Join(resourcesDir, "Makefile") makefileDst := filepath.Join(repoRoot, "Makefile") diff --git a/test/initial_ansible_cfg_overwrite b/test/initial_ansible_cfg_overwrite new file mode 100644 index 0000000..ab2af55 --- /dev/null +++ b/test/initial_ansible_cfg_overwrite @@ -0,0 +1,7 @@ +[defaults] +display_skipped_hosts=False +localhost_warning=True +retry_files_enabled=False +library=~/.ansible/plugins/modules:./ansible/plugins/modules:./common/ansible/plugins/modules:/usr/share/ansible/plugins/modules +roles_path=~/.ansible/roles:./ansible/roles:./common/ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles +filter_plugins=~/.ansible/plugins/filter:./ansible/plugins/filter:./common/ansible/plugins/filter:/usr/share/ansible/plugins/filter diff --git a/test/integration_test.sh b/test/integration_test.sh index d4d17f5..d74e1e1 100755 --- a/test/integration_test.sh +++ b/test/integration_test.sh @@ -89,12 +89,14 @@ INITIAL_VALUES_CUSTOM_CLUSTER_OVERWRITE="$REPO_ROOT/test/initial_values_custom_c INITIAL_VALUES_GLOBAL_CUSTOM="$REPO_ROOT/test/initial_values_global_custom.yaml" INITIAL_VALUES_GLOBAL_OVERWRITE="$REPO_ROOT/test/initial_values_global_overwrite.yaml" INITIAL_VALUES_SECRET_TEMPLATE_OVERWRITE="$REPO_ROOT/test/initial_values_secret_template_overwrite.yaml" +INITIAL_ANSIBLE_CFG_OVERWRITE="$REPO_ROOT/test/initial_ansible_cfg_overwrite" # Set paths for expected resource files EXPECTED_MAKEFILE="$PATTERNIZER_RESOURCES_DIR/Makefile" EXPECTED_MAKEFILE_COMMON="$PATTERNIZER_RESOURCES_DIR/Makefile-common" EXPECTED_PATTERN_SH="$PATTERNIZER_RESOURCES_DIR/pattern.sh" EXPECTED_VALUES_SECRET_TEMPLATE="$PATTERNIZER_RESOURCES_DIR/values-secret.yaml.template" +EXPECTED_ANSIBLE_CFG="$PATTERNIZER_RESOURCES_DIR/ansible.cfg" # Check if patternizer binary exists and is executable if [ ! -x "$PATTERNIZER_BINARY" ]; then @@ -249,6 +251,9 @@ compare_files "$EXPECTED_MAKEFILE" "Makefile" "Makefile has expected content (in # Test 1.5: Check Makefile-common has exact expected content compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common has expected content (init without secrets)" +# Test 1.6: Check ansible.cfg has exact expected content +compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg has expected content (init without secrets)" + test_pass "=== Test 1: Basic initialization PASSED ===" # @@ -284,6 +289,9 @@ compare_files "$EXPECTED_MAKEFILE" "Makefile" "Makefile has expected content (in # Test 2.6: Check Makefile-common has exact expected content compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common has expected content (init with secrets)" +# Test 2.7: Check ansible.cfg has exact expected content +compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg has expected content (init with secrets)" + test_pass "=== Test 2: Initialization with secrets PASSED ===" # @@ -322,6 +330,9 @@ compare_files "$EXPECTED_MAKEFILE" "Makefile" "Makefile has expected content (cu # Test 3.6: Check Makefile-common has exact expected content compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common has expected content (custom names with secrets)" +# Test 3.7: Check ansible.cfg has exact expected content +compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg has expected content (custom names with secrets)" + test_pass "=== Test 3: Custom pattern and cluster group names (with secrets) PASSED ===" # @@ -360,6 +371,10 @@ compare_files "$EXPECTED_MAKEFILE" "Makefile" "Makefile has expected content (se # Test 4.6: Check Makefile-common has exact expected content compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common has expected content (sequential execution)" +# Test 4.7: Check ansible.cfg has exact expected content +compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg has expected content (sequential execution)" + + test_pass "=== Test 4: Sequential execution PASSED ===" # @@ -376,6 +391,7 @@ cp "$INITIAL_MAKEFILE_OVERWRITE" "Makefile" cp "$INITIAL_MAKEFILE_PATTERN_OVERWRITE" "Makefile-common" cp "$INITIAL_PATTERN_SH_OVERWRITE" "pattern.sh" cp "$INITIAL_VALUES_SECRET_TEMPLATE_OVERWRITE" "values-secret.yaml.template" +cp "$INITIAL_ANSIBLE_CFG_OVERWRITE" "ansible.cfg" # Make pattern.sh executable to match real scenarios chmod +x "pattern.sh" @@ -410,6 +426,10 @@ fi # Test 5.6: values-secret.yaml.template should NOT be overwritten compare_files "$INITIAL_VALUES_SECRET_TEMPLATE_OVERWRITE" "values-secret.yaml.template" "values-secret.yaml.template was not overwritten (content preserved)" +# Test 5.7: ansible.cfg SHOULD be overwritten with exact expected content +compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg was overwritten with correct content" + + test_pass "=== Test 5: File overwrite behavior PASSED ===" # @@ -441,6 +461,8 @@ compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common cre compare_files "$EXPECTED_PATTERN_SH" "pattern.sh" "pattern.sh created with correct content" +compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg created with correct content" + # Test 6.2: Files that should be preserved compare_files "$INITIAL_MAKEFILE_OVERWRITE" "Makefile" "Existing Makefile preserved in mixed scenario" @@ -484,6 +506,7 @@ fi # Verify pattern.sh and Makefile-common contents compare_files "$EXPECTED_PATTERN_SH" "pattern.sh" "pattern.sh copied during upgrade" compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common copied during upgrade" +compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg copied during upgrade" # Verify Makefile first line and content EXPECTED_UPGRADE_MF=$(mktemp) From 0f68048d7964775f48dbe08dd3054f68201157f6 Mon Sep 17 00:00:00 2001 From: Akos Eros Date: Wed, 25 Feb 2026 09:25:45 +0100 Subject: [PATCH 2/2] fix: Typo, remove common paths from ansible.cfg --- resources/ansible.cfg | 6 +++--- src/cmd/upgrade.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/ansible.cfg b/resources/ansible.cfg index 91d0379..ac1ce92 100644 --- a/resources/ansible.cfg +++ b/resources/ansible.cfg @@ -4,9 +4,9 @@ retry_files_enabled=False # Retry files disabled to avoid cluttering CI/CD environments interpreter_python=auto_silent timeout=30 -library=~/.ansible/plugins/modules:./ansible/plugins/modules:./common/ansible/plugins/modules:/usr/share/ansible/plugins/modules -roles_path=~/.ansible/roles:./ansible/roles:./common/ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles -filter_plugins=~/.ansible/plugins/filter:./ansible/plugins/filter:./common/ansible/plugins/filter:/usr/share/ansible/plugins/filter +library=~/.ansible/plugins/modules:./ansible/plugins/modules:/usr/share/ansible/plugins/modules +roles_path=~/.ansible/roles:./ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles +filter_plugins=~/.ansible/plugins/filter:./ansible/plugins/filter:/usr/share/ansible/plugins/filter # use the collections from the util. container, # change below if you want to test local collections collections_path=/usr/share/ansible/collections diff --git a/src/cmd/upgrade.go b/src/cmd/upgrade.go index 6d85c39..325707c 100644 --- a/src/cmd/upgrade.go +++ b/src/cmd/upgrade.go @@ -47,7 +47,7 @@ func runUpgrade(replaceMakefile bool) error { return fmt.Errorf("error copying Makefile-common: %w", err) } - // Copy copy ansible.cfg + // Copy ansible.cfg if err := fileutils.CopyFile(filepath.Join(resourcesDir, "ansible.cfg"), filepath.Join(repoRoot, "ansible.cfg")); err != nil { return fmt.Errorf("error copying ansible.cfg: %w", err) }