github.com/yashbhutwala/operator-sdk@v0.8.1/test/ansible-inventory/molecule/test-local/playbook.yml (about) 1 --- 2 3 - name: Build Operator in Kubernetes docker container 4 hosts: k8s 5 vars: 6 image_name: inventory.apps.fabianism.us/inventory:testing 7 tasks: 8 # using command so we don't need to install any dependencies 9 - name: Get existing image hash 10 command: docker images -q {{image_name}} 11 register: prev_hash 12 changed_when: false 13 14 - name: Build Operator Image 15 command: docker build -f /build/build/Dockerfile -t {{ image_name }} /build 16 register: build_cmd 17 changed_when: not prev_hash.stdout or (prev_hash.stdout and prev_hash.stdout not in ''.join(build_cmd.stdout_lines[-2:])) 18 19 - name: Converge 20 hosts: localhost 21 connection: local 22 vars: 23 ansible_python_interpreter: '{{ ansible_playbook_python }}' 24 deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy" 25 pull_policy: Never 26 REPLACE_IMAGE: inventory.apps.fabianism.us/inventory:testing 27 custom_resource: "{{ lookup('file', '/'.join([deploy_dir, 'crds/inventory_v1alpha1_inventory_cr.yaml'])) | from_yaml }}" 28 tasks: 29 - name: Delete the Operator Deployment 30 k8s: 31 state: absent 32 namespace: '{{ namespace }}' 33 definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) }}" 34 register: delete_deployment 35 when: hostvars[groups.k8s.0].build_cmd.changed 36 37 - name: Wait 30s for Operator Deployment to terminate 38 k8s_facts: 39 api_version: '{{ definition.apiVersion }}' 40 kind: '{{ definition.kind }}' 41 namespace: '{{ namespace }}' 42 name: '{{ definition.metadata.name }}' 43 vars: 44 definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) | from_yaml }}" 45 register: deployment 46 until: not deployment.resources 47 delay: 3 48 retries: 10 49 when: delete_deployment.changed 50 51 - name: Create the Operator Deployment 52 k8s: 53 namespace: '{{ namespace }}' 54 definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) }}" 55 56 - name: Create the inventory.apps.fabianism.us/v1alpha1.Inventory 57 k8s: 58 state: present 59 namespace: '{{ namespace }}' 60 definition: "{{ custom_resource }}" 61 62 - name: Wait 30s for reconciliation to run 63 k8s_facts: 64 api_version: '{{ custom_resource.apiVersion }}' 65 kind: '{{ custom_resource.kind }}' 66 namespace: '{{ namespace }}' 67 name: '{{ custom_resource.metadata.name }}' 68 register: cr 69 until: 70 - "'Successful' in (cr | json_query('resources[].status.conditions[].reason'))" 71 delay: 3 72 retries: 10 73 74 - import_playbook: asserts.yml