Skip to content
Snippets Groups Projects
Commit 8c3d7114 authored by advait deshpande's avatar advait deshpande
Browse files

yaml to install web server

parent 24dc53f3
Branches
No related tags found
1 merge request!7Webserver
main.yaml 0 → 100644
---
- name: check if packages exits
package_facts:
manager: auto
- name: Check whether a package called nodejs is installed
debug:
var: result
register: result
when: "'nodejs' not in ansible_facts.packages"
- name: 'install all the dependencies for node js if not installed.'
tags: always
become: yes
apt:
name: ['nodejs','npm']
state: latest
install_recommends: no
update_cache: yes
- name: make sure the latest npm is installed
tags: 'node'
become: yes
npm:
name: npm
global: yes
state: latest
- name: install pm2 server
tags: 'pm2'
become: yes
npm:
name: pm2
global: yes
state: latest
- name: install react
tags: 'react'
become: yes
npm:
name: create-react-app
global: yes
state: present
- name: Checking folders
tags: 'volumes'
become: yes
stat:
path: "{{ item.mountpoint }}"
register: directory_stats
with_items:
- "{{ volumes }}"
- name: Create directory
tags: 'volumes'
become: yes
file:
path: "{{ item.item.mountpoint }}"
recurse: yes
state: directory
when: item.stat.exists == false
with_items:
- "{{ directory_stats.results }}"
- name: Mount device
tags: 'volumes'
become: yes
mount:
path: "{{ item.mountpoint }}"
src: "{{ item.device }}"
fstype: xfs
state: mounted
when: item.device is defined
with_items:
- "{{ volumes }}"
- name: traverse into the project directory.
become: yes
shell: cd
args:
chdir: /var/lib/react
register: dir_changed
############add logic to remove the existinf build from paretn foler
- name: clone git repo
become: yes
git:
repo: https://github.com/advait22/react-server.git
dest: /var/lib/react
force: yes
- debug:
msg: 'git repo cloned'
when: dir_changed.rc == 0
- name: change working directory to the app
become: yes
shell: cd
args:
chdir: /var/lib/react/express_react_example
register: server
- name: install all the packages for server
become: yes
npm:
path: /var/lib/react/express_react_example/
name: install
- debug:
msg: 'inside server'
when: server.rc == 0
- name: change working directory to the client
become: yes
shell: cd
args:
chdir: /var/lib/react/express_react_example/client
register: client
- name: install dependencies
become: yes
npm:
path: /var/lib/react/express_react_example/client
name: install
- debug:
msg: 'Client Dependencies installed'
when: client.rc == 0
- name: delete previous build folder
become: yes
shell: rm -rf
args:
chdir: /var/lib/react/express_react_example/client/build
register: build_delete
- name : compile the new build
tags: build
become: yes
shell: npm run build
args:
chdir: /var/lib/react/express_react_example/client
- debug:
msg: 'build successfull'
# when: build_delete.rc == 0
- name: copy new build to parent folder
become: yes
command: mv /var/lib/react/express_react_example/client/build /var/lib/react/express_react_example
register: build_copy
- name: start the server
become: yes
command: pm2 start /var/lib/react/express_react_example/server.js
- debug:
msg: 'yayyyyyyyyyyy app is running'
# when: build_copy.rc == 0
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment