---
- name: Remove chrony container
  gather_facts: false
  hosts:
    - "{{ 'chrony-server' if 'chrony-server' in  groups else 'all' }}"
    - "{{ 'chrony' if 'chrony' in  groups else 'all' }}"
  serial: '{{ kolla_serial|default("0") }}'
  tags:
    - chrony
  tasks:
    # NOTE(mgoddard): Running against the all group means that some hosts may
    # not have docker installed, which would break the kolla_docker module.
    # Avoid using service_facts which adds a large fact.
    - name: Check if Docker is running  # noqa command-instead-of-module
      command:
        cmd: "systemctl is-active docker.service"
      register: systemctl_is_active
      changed_when: false
      failed_when: false

    - block:
        - name: Stop and remove chrony container
          become: true
          kolla_docker:
            action: "stop_and_remove_container"
            name: chrony

        - name: Remove config for chrony
          become: true
          file:
            path: "{{ node_config_directory }}/chrony"
            state: "absent"
      when: systemctl_is_active.rc == 0