# Copyright 2018 The Kubernetes Authors.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: upgrade pip to latest
  pip:
    name: pip
    executable: pip3
    state: latest

- name: install aws clients
  pip:
    name: "{{ packages }}"
    executable: pip3
  vars:
    packages:
      - awscli
  when: ansible_distribution != "Amazon"

# Remove after https://github.com/aws/amazon-ssm-agent/issues/235 is fixed.
- name: install aws agents RPM on Redhat distributions
  package:
    name: "{{ item }}"
    state: present
    disable_gpg_check: true
  with_items:
    - "{{ amazon_ssm_agent_rpm }}"
  when:
    - ansible_os_family == "RedHat"
    - ansible_distribution != "Amazon"

- name: install aws agents RPM
  package:
    name: "{{ item }}"
    state: present
  with_items:
    - amazon-ssm-agent
    - awscli
  when: ansible_distribution == "Amazon"

- name: Ensure ssm agent is running RPM
  service:
    name: amazon-ssm-agent
    state: started
    enabled: yes
  when: ansible_os_family == "RedHat"

- name: install aws agents Ubuntu
  shell: snap install amazon-ssm-agent --classic
  when: ansible_distribution == "Ubuntu"

- name: Ensure ssm agent is running Ubuntu
  service:
    name: snap.amazon-ssm-agent.amazon-ssm-agent.service
    state: started
    enabled: yes
  when: ansible_distribution == "Ubuntu"

- name: Disable Hyper-V KVP protocol daemon on Ubuntu
  systemd:
    name: hv-kvp-daemon
    state: stopped
    enabled: false
  when: ansible_os_family == "Debian"