Home > Blockchain >  Ansible conditional won't recognise debug output
Ansible conditional won't recognise debug output

Time:03-25

I am trying to pass the debug message to conditional on Kubernetes object but it looks like it doesn't recognise it properly:

- name: get some service status log
  kubernetes.core.k8s_log:
    namespace: "{{ product.namespace }}"
    label_selectors:
    - app.kubernetes.io/name=check-service-existence
  register: service_existence

- name: some service existence check log
  debug:
    msg: "{{ service_existence.log_lines | first }}"

- name: create service for "{{ product.namespace }}"
  kubernetes.core.k8s:
    state: present
    template: create-service.j2
    wait: yes
    wait_timeout: 300
    wait_condition:
      type: "Complete"
      status: "True"
  when: service_existence  == "service_does_not_exist"

what I am getting when I am running it is:

TASK [playbook : some service existence check log] ***
ok: [127.0.0.1] => 
  msg: service_does_not_exist

TASK [playbook : create service for "namespace"] ***
skipping: [127.0.0.1]

I suspect that it treats msg: as a part of string. How can I deal with this properly?

CodePudding user response:

Since your debug message is about the value of service_existence.log_lines | first your conditional should also be.

when: service_existence.log_lines | first  == "service_does_not_exist"
  • Related