From 0b62b035722fc295951ff9668e0a8befc026125c Mon Sep 17 00:00:00 2001 From: fahed dorgaa Date: Wed, 30 Nov 2022 16:25:20 +0100 Subject: [PATCH] refacto ansible examples Signed-off-by: fahed dorgaa fixes Signed-off-by: fahed dorgaa --- apis/v1alpha1/ansibleRun_types.go | 5 -- .../ansibleRun-inline-inventory.yml} | 4 +- .../ansibleRun-inventory-from-secret.yml | 31 ++++++++++++ .../ansibleRun-playbook-inline.yml} | 0 .../ansibleRun-remote-roles.yml} | 0 .../ansibleRun-ObserveAndDelete-policy.yml | 2 +- .../ansibleRun-checkWhenObserve-policy.yml | 49 +++++++++++++++++++ .../ansible.crossplane.io_ansibleruns.yaml | 5 -- 8 files changed, 82 insertions(+), 14 deletions(-) rename examples/ansible/{ansibleRun-remote-host.yml => inventory/ansibleRun-inline-inventory.yml} (84%) create mode 100644 examples/ansible/inventory/ansibleRun-inventory-from-secret.yml rename examples/ansible/{ansibleRun-inline.yml => playbook/ansibleRun-playbook-inline.yml} (100%) rename examples/ansible/{ansibleRun-checkWhenObserve-policy.yml => role/ansibleRun-remote-roles.yml} (100%) rename examples/ansible/{ => runPolicy}/ansibleRun-ObserveAndDelete-policy.yml (97%) create mode 100644 examples/ansible/runPolicy/ansibleRun-checkWhenObserve-policy.yml diff --git a/apis/v1alpha1/ansibleRun_types.go b/apis/v1alpha1/ansibleRun_types.go index 499fb32..1a50c69 100644 --- a/apis/v1alpha1/ansibleRun_types.go +++ b/apis/v1alpha1/ansibleRun_types.go @@ -63,11 +63,6 @@ type AnsibleRunParameters struct { // Inventory required to configure ansible inventory. type Inventory struct { - - // Filename to which these inventory - // should be written. - Filename string `json:"filename"` - // Source of the inventory. // +kubebuilder:validation:Enum=None;Secret;InjectedIdentity;Environment;Filesystem Source xpv1.CredentialsSource `json:"source"` diff --git a/examples/ansible/ansibleRun-remote-host.yml b/examples/ansible/inventory/ansibleRun-inline-inventory.yml similarity index 84% rename from examples/ansible/ansibleRun-remote-host.yml rename to examples/ansible/inventory/ansibleRun-inline-inventory.yml index bc7c507..233b521 100644 --- a/examples/ansible/ansibleRun-remote-host.yml +++ b/examples/ansible/inventory/ansibleRun-inline-inventory.yml @@ -1,9 +1,7 @@ apiVersion: ansible.crossplane.io/v1alpha1 kind: AnsibleRun metadata: - annotations: - ansible.crossplane.io/runPolicy: ObserveAndDelete - name: remote-debug + name: inline-inventory-remote-debug spec: forProvider: inventoryInline: | diff --git a/examples/ansible/inventory/ansibleRun-inventory-from-secret.yml b/examples/ansible/inventory/ansibleRun-inventory-from-secret.yml new file mode 100644 index 0000000..e3aadd5 --- /dev/null +++ b/examples/ansible/inventory/ansibleRun-inventory-from-secret.yml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: Secret +metadata: + namespace: crossplane-system + name: inventory +type: Opaque +data: + hosts: QkFTRTY0RU5DT0RFRF9QUk9WSURFUl9DUkVEUw== +--- +apiVersion: ansible.crossplane.io/v1alpha1 +kind: AnsibleRun +metadata: + name: secret-inventory-remote-debug +spec: + forProvider: + inventories: + - source: Secret + secretRef: + namespace: crossplane-system + name: inventory + key: hosts + # AnsibleRun default to using a remote source. + # For simple cases you can use an inline source to specify the content of + # playbook.yaml as opaque, inline yaml. + playbookInline: | + --- + - hosts: all + tasks: + - name: ansibleplaybook-simple + debug: + msg: Your are running 'ansibleplaybook-simple' example \ No newline at end of file diff --git a/examples/ansible/ansibleRun-inline.yml b/examples/ansible/playbook/ansibleRun-playbook-inline.yml similarity index 100% rename from examples/ansible/ansibleRun-inline.yml rename to examples/ansible/playbook/ansibleRun-playbook-inline.yml diff --git a/examples/ansible/ansibleRun-checkWhenObserve-policy.yml b/examples/ansible/role/ansibleRun-remote-roles.yml similarity index 100% rename from examples/ansible/ansibleRun-checkWhenObserve-policy.yml rename to examples/ansible/role/ansibleRun-remote-roles.yml diff --git a/examples/ansible/ansibleRun-ObserveAndDelete-policy.yml b/examples/ansible/runPolicy/ansibleRun-ObserveAndDelete-policy.yml similarity index 97% rename from examples/ansible/ansibleRun-ObserveAndDelete-policy.yml rename to examples/ansible/runPolicy/ansibleRun-ObserveAndDelete-policy.yml index f8e2ac1..811ea88 100644 --- a/examples/ansible/ansibleRun-ObserveAndDelete-policy.yml +++ b/examples/ansible/runPolicy/ansibleRun-ObserveAndDelete-policy.yml @@ -42,7 +42,7 @@ metadata: name: gcp-credentials type: Opaque data: - credentials: BASE64ENCODED_PROVIDER_CREDS + credentials: QkFTRTY0RU5DT0RFRF9QUk9WSURFUl9DUkVEUw== --- apiVersion: ansible.crossplane.io/v1alpha1 kind: ProviderConfig diff --git a/examples/ansible/runPolicy/ansibleRun-checkWhenObserve-policy.yml b/examples/ansible/runPolicy/ansibleRun-checkWhenObserve-policy.yml new file mode 100644 index 0000000..2014277 --- /dev/null +++ b/examples/ansible/runPolicy/ansibleRun-checkWhenObserve-policy.yml @@ -0,0 +1,49 @@ +apiVersion: ansible.crossplane.io/v1alpha1 +kind: AnsibleRun +metadata: + annotations: + ansible.crossplane.io/runPolicy: CheckWhenObserve + name: gcpdisk +spec: + forProvider: + # AnsibleRun default to using a remote source + # For simple cases you can use an inline source to specify the content of + # playbook.yaml as opaque, inline yaml. + roles: + - name: ansible_provider.gcpdisk_role + src: https://github.com/multicloudlab/crossplane-ansible-provider-sample.git + vars: + project: + disk: + size: 20 + key: 718BDCC469891 + zone: europe-west1-b + id: test_project + providerConfigRef: + name: gcpconfig +--- +apiVersion: v1 +kind: Secret +metadata: + namespace: crossplane-system + name: gcp-credentials +type: Opaque +data: + credentials: QkFTRTY0RU5DT0RFRF9QUk9WSURFUl9DUkVEUw== +--- +apiVersion: ansible.crossplane.io/v1alpha1 +kind: ProviderConfig +metadata: + name: gcpconfig +spec: + # Note that unlike most provider configs this one supports an array of + # credentials. This is because each Ansible playbook uses a single + # Crossplane provider config, but could use multiple providers each + # with their own credentials. + credentials: + - filename: gcp-credentials.json + source: Secret + secretRef: + namespace: crossplane-system + name: gcp-credentials + key: credentials \ No newline at end of file diff --git a/package/crds/ansible.crossplane.io_ansibleruns.yaml b/package/crds/ansible.crossplane.io_ansibleruns.yaml index 34eb7a5..427707d 100644 --- a/package/crds/ansible.crossplane.io_ansibleruns.yaml +++ b/package/crds/ansible.crossplane.io_ansibleruns.yaml @@ -68,10 +68,6 @@ spec: required: - name type: object - filename: - description: Filename to which these inventory should be - written. - type: string fs: description: Fs is a reference to a filesystem location that contains credentials that must be used to connect @@ -112,7 +108,6 @@ spec: - Filesystem type: string required: - - filename - source type: object type: array