1
votes

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.

1
Same problem here. Did you found any resolution yet?Michel
Unfortunately, nosengbatz
Could you share your resource definition YAMLs, and confirm what's the value for the apiversion variable. I suspect some v1 / 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

1 Answers

0
votes

Try adding apply: yes to your k8s parameters, if I'm correct it should then ignore the already created resources and update them if anything changed.

The default behaviour is like using oc create from the CLI which could be troubling Ansible for whatever reason