---
- block:
  - name: Record RPM based etcd version
    command: rpm -qa --qf '%{version}' etcd\*
    args:
      warn: no
    register: etcd_rpm_version
    failed_when: false
    # AUDIT:changed_when: `false` because we are only inspecting
    # state, not manipulating anything
    changed_when: false
  - debug:
      msg: "Etcd rpm version {{ etcd_rpm_version.stdout }} detected"
  when:
  - not openshift_is_containerized | bool

- block:
  - name: Record containerized etcd version (docker)
    command: docker exec etcd_container rpm -qa --qf '%{version}' etcd\*
    register: etcd_container_version_docker
    failed_when: false
    # AUDIT:changed_when: `false` because we are only inspecting
    # state, not manipulating anything
    changed_when: false
    when:
    - not l_is_etcd_system_container | bool

    # Given a register variables is set even if the whwen condition
    # is false, we need to set etcd_container_version separately
  - set_fact:
      etcd_container_version: "{{ etcd_container_version_docker.stdout }}"
    when:
    - not l_is_etcd_system_container | bool

  - name: Record containerized etcd version (runc)
    command: runc exec etcd rpm -qa --qf '%{version}' etcd\*
    register: etcd_container_version_runc
    failed_when: false
    # AUDIT:changed_when: `false` because we are only inspecting
    # state, not manipulating anything
    changed_when: false
    when:
    - l_is_etcd_system_container | bool

    # Given a register variables is set even if the whwen condition
    # is false, we need to set etcd_container_version separately
  - set_fact:
      etcd_container_version: "{{ etcd_container_version_runc.stdout }}"
    when:
    - l_is_etcd_system_container | bool

  - debug:
      msg: "Etcd containerized version {{ etcd_container_version }} detected"
  when:
  - openshift_is_containerized | bool
