provider-ansible
provider-ansible copied to clipboard
Unable to trigger delete/cleanup code
What happened?
I'm trying to trigger cleanup code on composite-resource deletion. According to the doc, I can use the variable 'ansible_provider_meta.{managed_resource}.state' to detect when the ansibleRun object get deleted. I created a simple ansibleRun object which only output debug information. I can see the expected debug output on ansibleRun creation but I don't see anything at all when the ansibleRun object is deleted. I read the doc few time and I believe I have the syntax right but I can't get the playbook to be triggered on ansibleRun deletion (on crossplane delete lifecycle event)
How can we reproduce it?
- Apply this simple configuration:
apiVersion: ansible.crossplane.io/v1alpha1
kind: AnsibleRun
metadata:
annotations:
ansible.crossplane.io/runPolicy: ObserveAndDelete
name: deletetest
spec:
forProvider:
playbookInline: |
---
- hosts: localhost
tasks:
- name: debug adding
debug:
msg: Adding
when: ansible_provider_meta.deletetest.state == 'present'
- name: debug removing
debug:
msg: Removing
when: ansible_provider_meta.deletetest.state != 'present'
providerConfigRef:
name: default
---
apiVersion: ansible.crossplane.io/v1alpha1
kind: ProviderConfig
metadata:
name: default
spec: {}
- Look at the log of the ansible-provider pod for output of this playbook run.
- delete ansibleRun object deletetest
- Observe the log and nothing is triggered. Impossible to perform cleanup action
I might have misunderstood the documentation, but it seems using the ObserveAndDelete policy and using 'ansible_provider_meta.{managed_resource}.state != present' should allow to trigger one playbook run on resource deletion.
What environment did it happen in?
provider-ansible version: xpkg.upbound.io/crossplane-contrib/provider-ansible:v0.6.0 Crossplane version: Server Version: v1.18.0-up.1 Kubernetes version: Server Version: v1.32.0 kubernetes distribution: kind version 0.26.0 OS: centos 9 Kernel: Linux test-kind1 5.14.0-553.el9.x86_64