diff --git a/hack/ansible-test.yaml b/hack/ansible-test.yaml index 255c7eca551..ade4d0e12c8 100644 --- a/hack/ansible-test.yaml +++ b/hack/ansible-test.yaml @@ -2,5 +2,5 @@ tasks: - name: Create test file file: - path: /tmp/ansible + path: "/tmp/param-{{ lookup('ansible.builtin.env', 'PARAM_ANSIBLE') }}" state: touch diff --git a/hack/test-templates.sh b/hack/test-templates.sh index da5e72744b5..2b2616bf40e 100755 --- a/hack/test-templates.sh +++ b/hack/test-templates.sh @@ -35,7 +35,6 @@ declare -A CHECKS=( ["disk"]="" ["user-v2"]="" ["mount-path-with-spaces"]="" - ["provision-ansible"]="" ["param-env-variables"]="" ["set-user"]="" ) @@ -62,7 +61,6 @@ case "$NAME" in CHECKS["snapshot-online"]="1" CHECKS["snapshot-offline"]="1" CHECKS["mount-path-with-spaces"]="1" - CHECKS["provision-ansible"]="1" CHECKS["param-env-variables"]="1" CHECKS["set-user"]="1" ;; @@ -160,13 +158,9 @@ if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then [ "$(limactl shell "$NAME" cat "/tmp/lima test dir with spaces/test file")" = "test file content" ] fi -if [[ -n ${CHECKS["provision-ansible"]} ]]; then - INFO 'Testing that /tmp/ansible was created successfully on provision' - limactl shell "$NAME" test -e /tmp/ansible -fi - if [[ -n ${CHECKS["param-env-variables"]} ]]; then INFO 'Testing that PARAM env variables are exported to all types of provisioning scripts and probes' + limactl shell "$NAME" test -e /tmp/param-ansible limactl shell "$NAME" test -e /tmp/param-boot limactl shell "$NAME" test -e /tmp/param-dependency limactl shell "$NAME" test -e /tmp/param-probe diff --git a/hack/test-templates/test-misc.yaml b/hack/test-templates/test-misc.yaml index 2137c5f3e69..5b2e85387c5 100644 --- a/hack/test-templates/test-misc.yaml +++ b/hack/test-templates/test-misc.yaml @@ -30,6 +30,7 @@ mounts: writable: true param: + ANSIBLE: ansible BOOT: boot DEPENDENCY: dependency PROBE: probe diff --git a/pkg/instance/ansible.go b/pkg/instance/ansible.go index 53460fa747f..56f62b81f8f 100644 --- a/pkg/instance/ansible.go +++ b/pkg/instance/ansible.go @@ -2,6 +2,7 @@ package instance import ( "context" + "fmt" "os" "os/exec" "path/filepath" @@ -33,6 +34,7 @@ func runAnsiblePlaybook(ctx context.Context, inst *store.Instance, playbook stri logrus.Debugf("ansible-playbook -i %q %q", inventory, playbook) args := []string{"-i", inventory, playbook} cmd := exec.CommandContext(ctx, "ansible-playbook", args...) + cmd.Env = getAnsibleEnvironment(inst) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() @@ -60,3 +62,11 @@ func createAnsibleInventory(inst *store.Instance) (string, error) { inventory := filepath.Join(inst.Dir, filenames.AnsibleInventoryYAML) return inventory, os.WriteFile(inventory, bytes, 0o644) } + +func getAnsibleEnvironment(inst *store.Instance) []string { + env := os.Environ() + for key, val := range inst.Config.Param { + env = append(env, fmt.Sprintf("PARAM_%s=%s", key, val)) + } + return env +} diff --git a/pkg/limayaml/validate.go b/pkg/limayaml/validate.go index 56d03c0d22c..164e8478945 100644 --- a/pkg/limayaml/validate.go +++ b/pkg/limayaml/validate.go @@ -457,6 +457,16 @@ func ValidateParamIsUsed(y *LimaYAML) error { keyIsUsed = true break } + if p.Playbook != "" { + playbook, err := os.ReadFile(p.Playbook) + if err != nil { + return err + } + if re.Match(playbook) { + keyIsUsed = true + break + } + } } for _, p := range y.Probes { if re.MatchString(p.Script) {