Skip to content

Commit 3c79d5b

Browse files
authored
feat: Add ansible.cfg to patternizer (#21)
* feat: Add ansible.cfg to patternizer We need the ansible config in the patternizer, so we can always have a reliable working ansible configuration. * fix: Typo, remove common paths from ansible.cfg
1 parent e3b156c commit 3c79d5b

5 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎resources/ansible.cfg‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[defaults]
2+
localhost_warning=False
3+
retry_files_enabled=False
4+
# Retry files disabled to avoid cluttering CI/CD environments
5+
interpreter_python=auto_silent
6+
timeout=30
7+
library=~/.ansible/plugins/modules:./ansible/plugins/modules:/usr/share/ansible/plugins/modules
8+
roles_path=~/.ansible/roles:./ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
9+
filter_plugins=~/.ansible/plugins/filter:./ansible/plugins/filter:/usr/share/ansible/plugins/filter
10+
# use the collections from the util. container,
11+
# change below if you want to test local collections
12+
collections_path=/usr/share/ansible/collections

‎src/cmd/init.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ func runInit(withSecrets bool) error {
4747
return fmt.Errorf("error copying pattern.sh: %w", err)
4848
}
4949

50+
// Always copy ansible.cfg to the pattern repo
51+
ansibleCfgSrc := filepath.Join(resourcesDir, "ansible.cfg")
52+
ansibleCfgDst := filepath.Join(repoRoot, "ansible.cfg")
53+
if err := fileutils.CopyFile(ansibleCfgSrc, ansibleCfgDst); err != nil {
54+
return fmt.Errorf("error copying ansible.cfg: %w", err)
55+
}
56+
5057
// Always copy Makefile-common to the pattern repo
5158
makefilePatternSrc := filepath.Join(resourcesDir, "Makefile-common")
5259
makefilePatternDst := filepath.Join(repoRoot, "Makefile-common")

‎src/cmd/upgrade.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func runUpgrade(replaceMakefile bool) error {
4747
return fmt.Errorf("error copying Makefile-common: %w", err)
4848
}
4949

50+
// Copy ansible.cfg
51+
if err := fileutils.CopyFile(filepath.Join(resourcesDir, "ansible.cfg"), filepath.Join(repoRoot, "ansible.cfg")); err != nil {
52+
return fmt.Errorf("error copying ansible.cfg: %w", err)
53+
}
54+
5055
// Makefile handling
5156
makefileSrc := filepath.Join(resourcesDir, "Makefile")
5257
makefileDst := filepath.Join(repoRoot, "Makefile")

‎test/initial_ansible_cfg_overwrite‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[defaults]
2+
display_skipped_hosts=False
3+
localhost_warning=True
4+
retry_files_enabled=False
5+
library=~/.ansible/plugins/modules:./ansible/plugins/modules:./common/ansible/plugins/modules:/usr/share/ansible/plugins/modules
6+
roles_path=~/.ansible/roles:./ansible/roles:./common/ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
7+
filter_plugins=~/.ansible/plugins/filter:./ansible/plugins/filter:./common/ansible/plugins/filter:/usr/share/ansible/plugins/filter

‎test/integration_test.sh‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ INITIAL_VALUES_CUSTOM_CLUSTER_OVERWRITE="$REPO_ROOT/test/initial_values_custom_c
8989
INITIAL_VALUES_GLOBAL_CUSTOM="$REPO_ROOT/test/initial_values_global_custom.yaml"
9090
INITIAL_VALUES_GLOBAL_OVERWRITE="$REPO_ROOT/test/initial_values_global_overwrite.yaml"
9191
INITIAL_VALUES_SECRET_TEMPLATE_OVERWRITE="$REPO_ROOT/test/initial_values_secret_template_overwrite.yaml"
92+
INITIAL_ANSIBLE_CFG_OVERWRITE="$REPO_ROOT/test/initial_ansible_cfg_overwrite"
9293

9394
# Set paths for expected resource files
9495
EXPECTED_MAKEFILE="$PATTERNIZER_RESOURCES_DIR/Makefile"
9596
EXPECTED_MAKEFILE_COMMON="$PATTERNIZER_RESOURCES_DIR/Makefile-common"
9697
EXPECTED_PATTERN_SH="$PATTERNIZER_RESOURCES_DIR/pattern.sh"
9798
EXPECTED_VALUES_SECRET_TEMPLATE="$PATTERNIZER_RESOURCES_DIR/values-secret.yaml.template"
99+
EXPECTED_ANSIBLE_CFG="$PATTERNIZER_RESOURCES_DIR/ansible.cfg"
98100

99101
# Check if patternizer binary exists and is executable
100102
if [ ! -x "$PATTERNIZER_BINARY" ]; then
@@ -249,6 +251,9 @@ compare_files "$EXPECTED_MAKEFILE" "Makefile" "Makefile has expected content (in
249251
# Test 1.5: Check Makefile-common has exact expected content
250252
compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common has expected content (init without secrets)"
251253

254+
# Test 1.6: Check ansible.cfg has exact expected content
255+
compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg has expected content (init without secrets)"
256+
252257
test_pass "=== Test 1: Basic initialization PASSED ==="
253258

254259
#
@@ -284,6 +289,9 @@ compare_files "$EXPECTED_MAKEFILE" "Makefile" "Makefile has expected content (in
284289
# Test 2.6: Check Makefile-common has exact expected content
285290
compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common has expected content (init with secrets)"
286291

292+
# Test 2.7: Check ansible.cfg has exact expected content
293+
compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg has expected content (init with secrets)"
294+
287295
test_pass "=== Test 2: Initialization with secrets PASSED ==="
288296

289297
#
@@ -322,6 +330,9 @@ compare_files "$EXPECTED_MAKEFILE" "Makefile" "Makefile has expected content (cu
322330
# Test 3.6: Check Makefile-common has exact expected content
323331
compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common has expected content (custom names with secrets)"
324332

333+
# Test 3.7: Check ansible.cfg has exact expected content
334+
compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg has expected content (custom names with secrets)"
335+
325336
test_pass "=== Test 3: Custom pattern and cluster group names (with secrets) PASSED ==="
326337

327338
#
@@ -360,6 +371,10 @@ compare_files "$EXPECTED_MAKEFILE" "Makefile" "Makefile has expected content (se
360371
# Test 4.6: Check Makefile-common has exact expected content
361372
compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common has expected content (sequential execution)"
362373

374+
# Test 4.7: Check ansible.cfg has exact expected content
375+
compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg has expected content (sequential execution)"
376+
377+
363378
test_pass "=== Test 4: Sequential execution PASSED ==="
364379

365380
#
@@ -376,6 +391,7 @@ cp "$INITIAL_MAKEFILE_OVERWRITE" "Makefile"
376391
cp "$INITIAL_MAKEFILE_PATTERN_OVERWRITE" "Makefile-common"
377392
cp "$INITIAL_PATTERN_SH_OVERWRITE" "pattern.sh"
378393
cp "$INITIAL_VALUES_SECRET_TEMPLATE_OVERWRITE" "values-secret.yaml.template"
394+
cp "$INITIAL_ANSIBLE_CFG_OVERWRITE" "ansible.cfg"
379395

380396
# Make pattern.sh executable to match real scenarios
381397
chmod +x "pattern.sh"
@@ -410,6 +426,10 @@ fi
410426
# Test 5.6: values-secret.yaml.template should NOT be overwritten
411427
compare_files "$INITIAL_VALUES_SECRET_TEMPLATE_OVERWRITE" "values-secret.yaml.template" "values-secret.yaml.template was not overwritten (content preserved)"
412428

429+
# Test 5.7: ansible.cfg SHOULD be overwritten with exact expected content
430+
compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg was overwritten with correct content"
431+
432+
413433
test_pass "=== Test 5: File overwrite behavior PASSED ==="
414434

415435
#
@@ -441,6 +461,8 @@ compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common cre
441461

442462
compare_files "$EXPECTED_PATTERN_SH" "pattern.sh" "pattern.sh created with correct content"
443463

464+
compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg created with correct content"
465+
444466
# Test 6.2: Files that should be preserved
445467
compare_files "$INITIAL_MAKEFILE_OVERWRITE" "Makefile" "Existing Makefile preserved in mixed scenario"
446468

@@ -484,6 +506,7 @@ fi
484506
# Verify pattern.sh and Makefile-common contents
485507
compare_files "$EXPECTED_PATTERN_SH" "pattern.sh" "pattern.sh copied during upgrade"
486508
compare_files "$EXPECTED_MAKEFILE_COMMON" "Makefile-common" "Makefile-common copied during upgrade"
509+
compare_files "$EXPECTED_ANSIBLE_CFG" "ansible.cfg" "ansible.cfg copied during upgrade"
487510

488511
# Verify Makefile first line and content
489512
EXPECTED_UPGRADE_MF=$(mktemp)

0 commit comments

Comments
 (0)