Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp90023-assignment-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Matthew O'Halloran
comp90023-assignment-2
Commits
8c3d7114
Commit
8c3d7114
authored
5 years ago
by
advait deshpande
Browse files
Options
Downloads
Patches
Plain Diff
yaml to install web server
parent
24dc53f3
Branches
Branches containing commit
No related tags found
1 merge request
!7
Webserver
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.yaml
+160
-0
160 additions, 0 deletions
main.yaml
with
160 additions
and
0 deletions
main.yaml
0 → 100644
+
160
−
0
View file @
8c3d7114
---
-
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment