I want to create some resources in an OpenSHift cluster using Ansible. Creation of resources works well, but when I run the same script for the second time, it claims that the resources already exist. In my opinion, this should not happen as ansible should be idempotent. I searched and found that this problem should be fixed (https://github.com/CiscoCloud/kubernetes-ansible/issues/69). What am I doing wrong?
Error message:
TASK [apply_templates : Set state of project-request in project developtest to present] *************************************************************************************************************************** fatal: [localhost]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "error": 409, "msg": "Failed to create object: {\"kind\":\"Status\",\"apiVersion\":\"v1\", \"metadata\":{},\"status\":\"Failure\",\"message\":\"project.project.openshift.io \\"developtest\\" already exists\",\"reason\":\"AlreadyExists\",\"details\":{\"name\":\"developtest\",\"group\":\"project.opens hift.io\",\"kind\":\"project\"},\"code\":409}\n", "reason": "Conflict", "status": 409}
Part of my playbook:
---
# Create projectrequest
- name: Set state of project-request in project {{current_project.name}} to {{state}}
k8s:
api_version: "{{apiversion}}"
state: "{{ state }}"
resource_definition: "{{ lookup('file', '{{ templating.destination_dir }}/{{current_project.name}}/projectrequest.yaml')}}"
# Create namespace and namespace-quota
- name: Set state of object in project {{current_project.name}} to {{state}}
k8s:
api_version: "{{apiversion}}"
state: "{{ state }}"
resource_definition: "{{ lookup('file', '{{ templating.destination_dir }}/{{current_project.name}}/namespace.yaml')}}"
Maybe you can give me a hint where to look at. Thanks in advance.
apiversion
variable. I suspect somev1
/project.openshift.io/v1
mixup. Also, you don't need to set the api_version, if you already have one in the YAML you're loading. Meanwhile, rather than creating Project (or project requests), maybe Namespaces would be more portable, ... ;) – SYN