---

- name: Set Hostname if exist
  hostname: name={{ hostname }}
  when: hostname is defined

- name: Install common needed packages for IRMA
  apt: name={{ item }} state=present
  with_items:
    - vim
    - aria2
    - git
    - python-pip
    - python-virtualenv

- name: Build /etc/hosts file
  lineinfile:
    dest=/etc/hosts
    regexp='.*{{ item }}$'
    line='{{ hostvars[item].ansible_default_ipv4.address }} {{ item }}'
    state=present
  when: hostvars[item].ansible_default_ipv4.address is defined and vagrant|default(False) == False
  with_items: groups['all']

# For Vagrant, public address is on eth1 interface.
- name: Build /etc/hosts file (Vagrant)
  lineinfile:
    dest=/etc/hosts
    regexp='.*{{ item }}$'
    line='{{ hostvars[item].ansible_eth1.ipv4.address }} {{ item }}'
    state=present
  when: hostvars[item].ansible_eth1.ipv4.address is defined and vagrant|default(False) == True
  with_items: groups['all']

---

- name: Set Hostname if exist
  hostname: name={{ hostname }}
  when: hostname is defined

# From https://coderwall.com/p/0xtstw
- name: Check Apt last update
  stat: path=/var/cache/apt
  register: apt_cache_stat

- name: Update Apt if needed
  apt: update_cache=yes
  when: ansible_date_time.epoch|float - apt_cache_stat.stat.mtime > 60*60*24 and ansible_os_family == "Debian"

- name: Install common needed packages for IRMA
  apt: name={{ item }} state=present
  with_items:
    - vim
    - aria2
    - git
    - python-pip
    - python-virtualenv

- name: Build /etc/hosts file
  lineinfile:
    dest=/etc/hosts
    regexp='.*{{ item }}$'
    line='{{ hostvars[item].ansible_default_ipv4.address }} {{ item }}'
    state=present
  when: hostvars[item].ansible_default_ipv4.address is defined and vagrant|default(False) == False
  with_items: groups['all']

# For Vagrant, public address is on eth1 interface.
- name: Build /etc/hosts file (Vagrant)
  lineinfile:
    dest=/etc/hosts
    regexp='.*{{ item }}$'
    line='{{ hostvars[item].ansible_eth1.ipv4.address }} {{ item }}'
    state=present
  when: hostvars[item].ansible_eth1.ipv4.address is defined and vagrant|default(False) == True
  with_items: groups['all']

Add automatic Apt cache update every 24 hours
Add automatic Apt cache update every 24 hours
