Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions resources/ansible.cfg
Original file line number Diff line number Diff line change
@@ -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:/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
7 changes: 7 additions & 0 deletions src/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func runUpgrade(replaceMakefile bool) error {
return fmt.Errorf("error copying Makefile-common: %w", err)
}

// 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")
Expand Down
7 changes: 7 additions & 0 deletions test/initial_ansible_cfg_overwrite
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions test/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ==="

#
Expand Down Expand Up @@ -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 ==="

#
Expand Down Expand Up @@ -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 ==="

#
Expand Down Expand Up @@ -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 ==="

#
Expand All @@ -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"
Expand Down Expand Up @@ -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 ==="

#
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down