---
- debug: var=aws verbosity=1
  tags:
    - vars
    - always

- name: Make sure AWS CLI is present
  become: yes
  apt:
    name: "awscli"
    state: present
    update_cache: yes
    cache_valid_time: 86400

- name: Download AWS CloudWatch Logs installer
  get_url:
    url: "{{ aws.cloudwatch.agent_url }}"
    dest: /tmp/awslogs-agent-setup.py

- name: Install AWS CloudWatch Logs deamon
  become: yes
  shell: "/usr/bin/python /tmp/awslogs-agent-setup.py --non-interactive --region us-east-1 -c /var/awslogs/etc/aws.conf"
  args:
    creates: "{{ aws.cloudwatch.conf_file }}"

- name: Make sure the AWS CloudWatch Logs config is present
  become: yes
  template:
    src: awslogs.conf.j2
    dest: "{{ aws.cloudwatch.conf_file }}"
  notify: restart awslogs

- name: Use CloudWatch Logs credentials
  become: yes
  template:
    src: aws.conf.j2
    dest: /var/awslogs/etc/aws.conf
    mode: 0600

- name: Make sure the AWS-CLI directory is present
  file:
    dest: "~/.aws/"
    state: directory

- name: Use AWS Credentials
  template:
    src: credentials.j2
    dest: ~/.aws/credentials
    mode: 0600

- name: Use AWS Config
  template:
    src: config.j2
    dest: ~/.aws/config
    mode: 0600

---
- debug: var=aws verbosity=1
  tags: vars

- name: Make sure AWS CLI is present
  become: yes
  apt:
    name: "awscli"
    state: present
    update_cache: yes
    cache_valid_time: 86400

- name: Download AWS CloudWatch Logs installer
  get_url:
    url: "{{ aws.cloudwatch.agent_url }}"
    dest: /tmp/awslogs-agent-setup.py

- name: Install AWS CloudWatch Logs deamon
  become: yes
  shell: "/usr/bin/python /tmp/awslogs-agent-setup.py --non-interactive --region us-east-1 -c /var/awslogs/etc/aws.conf"
  args:
    creates: "{{ aws.cloudwatch.conf_file }}"

- name: Make sure the AWS CloudWatch Logs config is present
  become: yes
  template:
    src: awslogs.conf.j2
    dest: "{{ aws.cloudwatch.conf_file }}"
  notify: restart awslogs

- name: Use CloudWatch Logs credentials
  become: yes
  template:
    src: aws.conf.j2
    dest: /var/awslogs/etc/aws.conf
    mode: 0600

- name: Make sure the AWS-CLI directory is present
  file:
    dest: "~/.aws/"
    state: directory

- name: Use AWS Credentials
  template:
    src: credentials.j2
    dest: ~/.aws/credentials
    mode: 0600

- name: Use AWS Config
  template:
    src: config.j2
    dest: ~/.aws/config
    mode: 0600

Disable variables debug always output
Disable variables debug always output
