---

- name: Install dependencies
  apt: name={{ item }}
  with_items:
  - fping
  - git
  - graphviz
  - imagemagick
  - mtr-tiny
  - mysql-server
  - nmap
  - php-net-ipv4
  - php-net-ipv6
  - php-pear
  - php7.0-cli
  - php7.0-curl
  - php7.0-fpm
  - php7.0-gd
  - php7.0-json
  - php7.0-mcrypt
  - php7.0-mysql
  - php7.0-snmp
  - python-mysqldb
  - rrdtool
  - snmp
  - snmpd
  - whois

- name: Configure MySQL database
  mysql_db: name={{ librenms_dbname }}

- name: Configure MySQL user
  mysql_user: name={{ librenms_dbuser }} password={{ librenms_dbpass }} priv={{ librenms_dbname }}.*:ALL state=present

- name: Ensure librenms user exists
  user: name=librenms groups=www-data createhome=no home=/usr/share/librenms system=yes

- name: Clone librenms
  git: repo=https://github.com/librenms/librenms.git dest=/usr/share/librenms depth=1 update=no

- name: Ensure rrd directory exists
  file: path=/var/lib/librenms/rrd owner=librenms group=www-data mode=0775 state=directory

- name: Ensure rrd link exists
  file: src=/var/lib/librenms/rrd dest=/usr/share/librenms/rrd state=link

- name: Configure librenms
  template: src=config.php.j2 dest=/usr/share/librenms/config.php owner=librenms group=www-data mode=0440

- name: Configure vhost
  template: src=vhost.j2 dest=/etc/nginx/sites-available/librenms
  notify: Restart nginx

- name: Enable vhost
  file: src=/etc/nginx/sites-available/librenms dest=/etc/nginx/sites-enabled/librenms state=link
  notify: Restart nginx

- name: Start php7.0-fpm
  service: name=php7.0-fpm state=started enabled=yes