---
- hosts: all
  become: yes
  become_method: sudo
  tasks:
  - name: Update OS
    package:
     name: '*'
     state: latest
  - name: wget percona release installation file
    shell: cd /root/ && wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb; dpkg -i /root/percona-release_latest.$(lsb_release -sc)_all.deb

  - name: setup percona repositories to percona server 5.7
    shell: percona-release setup ps57

  - name: Update repositories cache
    apt:
      update_cache: yes

  - name: ensure nginx is at the latest version
    apt: name=nginx state=latest
  - name: start nginx
    service:
        name: nginx
        state: started

  - name: Add nginx stable repository from PPA and install its signing key on Ubuntu target
    ansible.builtin.apt_repository:
      repo: ppa:ondrej/php

  - name: ensure php7.4-fpm is at the latest version
    apt: name=php7.4-fpm state=latest

  - name: install php7.4-curl
    apt: name=php7.4-curl state=latest

  - name: install php7.4-xml
    apt: name=php7.4-xml state=latest

  - name: install php7.4-pdo
    apt: name=php7.4-pdo state=latest

  - name: install php7.4-mysql
    apt: name=php7.4-mysql state=latest

  - name: ensure gpupg2 is at the latest version
    apt: name=gnupg2 state=latest

  - name: ensure percona-server-57 is installed
    apt: name=percona-server-server-5.7 state=latest

    #  - name: Create a new database with name 'psm'
    #    shell: mysql -e "CREATE DATABASE psm;"
  - name: setup mysql
    shell: /vagrant/setup-mysql.sh

  - name: copy psm nginx vhost
    shell: /bin/cp -far /vagrant/dev/phpservermon-default /etc/nginx/sites-available/default

  - name: setup php dependencies
    shell: /vagrant/setup-php.sh

  - name: copy psm config file
    shell: /bin/cp -far /vagrant/dev/vagrant-config.php /vagrant/config.php

  - name: apply nginx modifications
    service:
        name: nginx
        state: restarted