Commit a8ef967d authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

Improve idempotency

parent 0a1d7f29
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -40,11 +40,11 @@
- name: Generate MongoDB manifest
  ansible.builtin.template:
    src: mongo-db.yaml.j2
    dest: "/tmp/mongo-db.yaml"
    dest: "/tmp/mongo-db-remote.yaml"
    mode: '0644'

- name: Apply MongoDB manifest
  ansible.builtin.command: "kubectl apply -f /tmp/mongo-db.yaml"
  ansible.builtin.command: "kubectl apply -f /tmp/mongo-db-remote.yaml"
  register: apply_mongo
  changed_when: "'created' in apply_mongo.stdout or 'configured' in apply_mongo.stdout"
  environment:
@@ -53,11 +53,11 @@
- name: Generate Keycloak manifest
  ansible.builtin.template:
    src: keycloak.yaml.j2
    dest: "/tmp/keycloak.yaml"
    dest: "/tmp/keycloak-remote.yaml"
    mode: '0644'

- name: Apply Keycloak manifest
  ansible.builtin.command: "kubectl apply -f /tmp/keycloak.yaml"
  ansible.builtin.command: "kubectl apply -f /tmp/keycloak-remote.yaml"
  register: apply_keycloak
  changed_when: "'created' in apply_keycloak.stdout or 'configured' in apply_keycloak.stdout"
  environment:
@@ -66,11 +66,11 @@
- name: Generate Federation Manager manifest
  ansible.builtin.template:
    src: federation-manager.yaml.j2
    dest: "/tmp/federation-manager.yaml"
    dest: "/tmp/federation-manager-remote.yaml"
    mode: '0644'

- name: Apply Federation Manager manifest
  ansible.builtin.command: "kubectl apply -f /tmp/federation-manager.yaml"
  ansible.builtin.command: "kubectl apply -f /tmp/federation-manager-remote.yaml"
  register: apply_manifest
  changed_when: "'created' in apply_manifest.stdout or 'configured' in apply_manifest.stdout"
  environment:
+6 −6
Original line number Diff line number Diff line
@@ -40,11 +40,11 @@
- name: Generate MongoDB manifest
  ansible.builtin.template:
    src: mongo-db.yaml.j2
    dest: "/tmp/mongo-db.yaml"
    dest: "/tmp/mongo-db-local.yaml"
    mode: "0644"

- name: Apply MongoDB manifest
  ansible.builtin.command: "kubectl apply -f /tmp/mongo-db.yaml"
  ansible.builtin.command: "kubectl apply -f /tmp/mongo-db-local.yaml"
  register: apply_mongo
  changed_when: "'created' in apply_mongo.stdout or 'configured' in apply_mongo.stdout"
  environment:
@@ -53,11 +53,11 @@
- name: Generate Keycloak manifest
  ansible.builtin.template:
    src: keycloak.yaml.j2
    dest: "/tmp/keycloak.yaml"
    dest: "/tmp/keycloak-local.yaml"
    mode: "0644"

- name: Apply Keycloak manifest
  ansible.builtin.command: "kubectl apply -f /tmp/keycloak.yaml"
  ansible.builtin.command: "kubectl apply -f /tmp/keycloak-local.yaml"
  register: apply_keycloak
  changed_when: "'created' in apply_keycloak.stdout or 'configured' in apply_keycloak.stdout"
  environment:
@@ -66,11 +66,11 @@
- name: Generate Federation Manager manifest
  ansible.builtin.template:
    src: federation-manager.yaml.j2
    dest: "/tmp/federation-manager.yaml"
    dest: "/tmp/federation-manager-local.yaml"
    mode: "0644"

- name: Apply Federation Manager manifest
  ansible.builtin.command: "kubectl apply -f /tmp/federation-manager.yaml"
  ansible.builtin.command: "kubectl apply -f /tmp/federation-manager-local.yaml"
  register: apply_manifest
  changed_when: "'created' in apply_manifest.stdout or 'configured' in apply_manifest.stdout"
  environment:
+4 −1
Original line number Diff line number Diff line
@@ -5,7 +5,10 @@
  ansible.builtin.command: >
    helm repo add {{ harbor_helm_repo_name }} {{ harbor_helm_repo_url }}
  register: harbor_helm_repo_add
  changed_when: "'already exists' not in harbor_helm_repo_add.stderr"
  changed_when: 
    - "'already exists' not in harbor_helm_repo_add.stderr"
    - "'skipping' not in harbor_helm_repo_add.stderr"
    - "'skipping' not in harbor_helm_repo_add.stdout"
  failed_when: harbor_helm_repo_add.rc != 0 and 'already exists' not in harbor_helm_repo_add.stderr

- name: Update Helm repositories
+2 −2
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@
# Handle cluster creation
- name: Prompt for cluster recreation
  ansible.builtin.pause:
    prompt: "Cluster '{{ kind_cluster_name }}' already exists. Recreate it? (yes/no) [Default: yes]"
    prompt: "Cluster '{{ kind_cluster_name }}' already exists. Recreate it? (yes/no) [Default: no]"
    seconds: 7
  register: recreate_prompt
  when:
@@ -67,7 +67,7 @@
    - cluster_exists
    - not kind_cluster_recreate
    - recreate_prompt is not skipped
    - recreate_prompt.user_input | default('yes', true) | lower in ['yes', 'y']
    - recreate_prompt.user_input | default('no', true) | lower in ['yes', 'y']
  register: cluster_deleted_prompt
  changed_when: true

+8 −1
Original line number Diff line number Diff line
@@ -5,7 +5,10 @@
  ansible.builtin.command: >
    helm repo add {{ prometheus_helm_repo_name }} {{ prometheus_helm_repo_url }}
  register: helm_repo_add
  changed_when: "'already exists' not in helm_repo_add.stderr"
  changed_when: 
    - "'already exists' not in helm_repo_add.stderr"
    - "'skipping' not in helm_repo_add.stderr"
    - "'skipping' not in helm_repo_add.stdout"
  failed_when: helm_repo_add.rc != 0 and 'already exists' not in helm_repo_add.stderr

- name: Update Helm repositories
@@ -26,18 +29,21 @@
    state: directory
    suffix: grafana
  register: grafana_temp_dir
  changed_when: false

- name: Create Grafana admin user file
  ansible.builtin.copy:
    content: "{{ grafana_admin_user }}"
    dest: "{{ grafana_temp_dir.path }}/admin-user"
    mode: '0600'
  changed_when: false

- name: Create Grafana admin password file
  ansible.builtin.copy:
    content: "{{ grafana_admin_password }}"
    dest: "{{ grafana_temp_dir.path }}/admin-password"
    mode: '0600'
  changed_when: false

- name: Create Grafana credentials secret
  ansible.builtin.command: >
@@ -62,6 +68,7 @@
  ansible.builtin.file:
    path: "{{ grafana_temp_dir.path }}"
    state: absent
  changed_when: false

- name: Auto-discover Kind cluster node IPs if not provided
  when: prometheus_control_plane_ips | length == 0 or prometheus_worker_ips | length == 0