---
- hosts: localhost
connection: local
become: yes
tasks:
- name: Update and Upgrade
apt:
upgrade: full
update_cache: yes
- name: Install software-properties-common
apt:
name: software-properties-common
- name: Add php repository
ansible.builtin.apt_repository:
repo: ppa:ondrej/php
state: present
update_cache: true
- name: Install php packages
apt:
pkg:
- php8.1
- php8.1-fpm
- php8.1-cli
- name: Add nginx repository
ansible.builtin.apt_repository:
repo: ppa:nginx/stable
state: present
update_cache: true
- name: Install nginx
apt:
name: nginx
- name: Enable nginx should start on boot
ansible.builtin.systemd:
name: nginx
enabled: yes
- name: Download composer
get_url:
url: https://getcomposer.org/installer
dest: /tmp/composer-installer.php
- name: Install composer
shell: php /tmp/composer-installer.php --install-dir=/usr/local/bin --filename=composer
- name: Remove composer installer
file:
path: /tmp/composer-installer.php
state: absent
- name: Install Git
apt:
name: git
state: present
- name: Install Postgres
apt:
name: postgresql
state: present
- name: Create Postgres User
shell: sudo -u postgres psql -c "CREATE USER profithero WITH PASSWORD '12345678';" ignore_errors: yes
- name: Create Postgres DB
shell: sudo -u postgres psql -c "create database profitherodb;"
ignore_errors: yes
- name: Create Site Directory
ansible.builtin.file:
path: /var/www/profithero
state: directory
mode: '0777'
- name: Load Project from Git
shell: git clone git@github.com:koliane/profithero_web.git /var/www/profithero
- name: Change frontend host
ansible.builtin.replace:
dest: "/var/www/profithero/resources/rider_vue/src/data/clients/api/api_client.ts"
after: "BaseUrl"
before: "instance"
regexp: "http://localhost"
replace: 'http://localhost:8081'
- name: Install php laravel packages
apt:
name: "{{item}}"
state: present
loop:
- php8.1-xml
- php8.1-mbstring
- zip
- unzip
- php8.1-pgsql
- name: Configure nginx
template:
src=templates/nginx/available_site_default.conf
dest=/etc/nginx/sites-available/default
- name: Enable PDO for postgres
lineinfile:
dest: "{{item.location}}"
regexp: "{{item.reg}}"
line: "{{item.line}}"
loop:
- { location: '/etc/php/8.1/cli/php.ini', reg: '^;extension=pdo_pgsql', line: 'extension=pdo_pgsql'}
- { location: '/etc/php/8.1/cli/php.ini', reg: '^;extension=pgsql', line: 'extension=pgsql'}
- { location: '/etc/php/8.1/fpm/php.ini', reg: '^;extension=pdo_pgsql', line: 'extension=pdo_pgsql'}
- { location: '/etc/php/8.1/fpm/php.ini', reg: '^;extension=pgsql', line: 'extension=pgsql'}
- name: restart nginx
shell: sudo systemctl reload nginx
- name: Add Laravel Env
template:
src=templates/laravel/.env
dest=/var/www/profithero/.env
- name: Install composer packages
composer:
command: install
working_dir: /var/www/profithero
- name: Change WEB directory Owner and Group
shell: sudo chown -R www-data:www-data /var/www/profithero/
- name: NodeJs install
apt: '{{item}}'
with_items:
- build-essential
- checkinstall
- libssl-dev
- name: Download nvm
get_url:
url: https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh
dest: /tmp/nvm-installer.sh
- name: Start nvm-installer
shell: bash /tmp/nvm-installer.sh
- name: Install node and set nvm version
shell: "source /root/.nvm/nvm.sh && nvm install 16.0"
args:
executable: /bin/bash
- name: Remove nvm installer
file:
path: /tmp/nvm-installer.sh
state: absent
- name: Install npm
apt:
name: npm
- name: Execute npm install from Project Root
become: no
shell: npm install
args:
chdir: /var/www/profithero/
- name: update npm and nodejs
shell: '{{item}}'
with_items:
- npm update -g npm
- npm cache clean -f
- npm install -g n
- n stable
- update-alternatives --install /usr/bin/npm npm /usr/local/bin/npm 2
- name: Run npm build
shell: npm run dev
args:
chdir: /var/www/profithero/
- name: Run migrations
shell: php artisan migrate
args:
chdir: /var/www/profithero/
- name: Install yarn
shell: npm install --global yarn
- name: Install rider_vue packages
shell: yarn
args:
chdir: /var/www/profithero/resources/rider_vue
- name: Build rider_vue
shell: yarn build
args:
chdir: /var/www/profithero/resources/rider_vue
- name: Install supervisor
apt:
name: supervisor
- name: Configure supervisor
template:
src=templates/supervisor/laravel-worker.conf
dest=/etc/supervisor/conf.d/laravel-worker.conf
- name: Apply Supervisor settings
shell: '{{item}}'
with_items:
- supervisorctl reread
- supervisorctl update
- supervisorctl start laravel-worker:*