---
- name: Determine if Atomic
  stat: path=/run/ostree-booted
  register: s
  changed_when: false
  check_mode: no

- name: Init the is_atomic fact
  set_fact:
    is_atomic: false

- name: Set the is_atomic fact
  set_fact:
    is_atomic: true
  when: s.stat.exists

- block:
    - name: be sure all pre-req packages are installed
      yum: name={{item}} state=installed
      with_items:
        - open-vm-tools
        - PyYAML
        - perl
        - net-tools
        - chrony
        - python-six
        - iptables
        - iptables-services
        - docker

    - name: be sure katello-agent is installed
      yum: name=katello-agent state=installed
      when: rhsm_activation_key is defined and rhsm_activation_key

    - name: be sure openvmtools is running and enabled
      service: name=vmtoolsd state=started enabled=yes

  when:
    - not is_atomic | bool
    - ansible_distribution == "RedHat"

- name: be sure chrony is configured
  template: src=chrony.conf.j2 dest=/etc/chrony.conf
  notify:
    - restart chronyd

- name: set link to localtime
  command: timedatectl set-timezone {{timezone}}

- name: be sure chronyd is running and enabled
  service: name=chronyd state=started enabled=yes

- block:
    - name: (Atomic) Remove extra docker lv from root vg
      lvol:
        lv: docker-pool
        vg: atomicos
        state: absent
        force: yes
    - name: (Atomic) Grow root lv to fill vg
      lvol:
        lv: root
        vg: atomicos
        size: +100%FREE
    - name: (Atomic) Grow root fs to match lv
      filesystem:
        dev: /dev/mapper/atomicos-root
        fstype: xfs
        resizefs: yes
    - name: (Atomic) Force Ansible to re-gather disk facts
      setup:
        filter: 'ansible_mounts'
  when:
    - is_atomic | bool
    - ansible_distribution == "RedHat"
