set_etcd_ca_host.yml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ---
  2. - name: Check for CA indicator files
  3. stat:
  4. path: "{{ item.0 }}"
  5. delegate_to: "{{ item.1 }}"
  6. with_nested:
  7. - - /etc/etcd/ca
  8. - /etc/etcd/generated_certs
  9. - "{{ groups[etcd_ca_host_group] }}"
  10. register: __etcd_ca_host_stat
  11. run_once: true
  12. # Collect ansible_host (inventory hostname) of hosts with /etc/etcd/ca
  13. # and /etc/etcd/generated_certs directories.
  14. - set_fact:
  15. __etcd_ca_dir_hosts: "{{ __etcd_ca_host_stat.results
  16. | lib_utils_oo_collect('_ansible_delegated_vars.inventory_hostname',
  17. filters={'stat.path':'/etc/etcd/ca','stat.exists':True}) }}"
  18. __etcd_generated_certs_dir_hosts: "{{ __etcd_ca_host_stat.results
  19. | lib_utils_oo_collect('_ansible_delegated_vars.inventory_hostname',
  20. filters={'stat.path':'/etc/etcd/generated_certs','stat.exists':True}) }}"
  21. run_once: true
  22. # __etcd_ca_hosts is the intersection of hosts which have /etc/etcd/ca
  23. # and /etc/etcd/generated_certs directories.
  24. - set_fact:
  25. __etcd_ca_hosts: "{{ __etcd_ca_dir_hosts | intersect(__etcd_generated_certs_dir_hosts) }}"
  26. run_once: true
  27. # __etcd_ca_hosts should only contain one host. If more than one host
  28. # is able to be an etcd CA host then we will use the first.
  29. - set_fact:
  30. etcd_ca_host: "{{ __etcd_ca_hosts[0] }}"
  31. when:
  32. - __etcd_ca_hosts | length > 0
  33. - etcd_ca_host is not defined
  34. # No etcd_ca_host was found in __etcd_ca_hosts. This is probably a
  35. # fresh installation so we will default to the first member of the
  36. # etcd host group.
  37. - set_fact:
  38. etcd_ca_host: "{{ groups[etcd_ca_host_group].0 }}"
  39. when:
  40. - etcd_ca_host is not defined