You are on page 1of 4

6/29/2021 write tasks to install nginx and postgresql using ansible-playbook - Stack Overflow

write tasks to install nginx and postgresql using ansible-playbook


Asked
10 months ago Active
12 days ago Viewed
3k times

.score.sh is given as

-1 #!/bin/bash

pass=0;

fail=0;

if [ $? -eq 0 ];then

worker=`ps -eaf|grep nginx|grep worker`

master=`ps -eaf|grep nginx|grep master`

serverup=`curl -Is http://localhost:9090/|grep -i "200 OK"`

serverurl=`curl -Is http://localhost:9090/|grep -io "google.com"`

if [[ ! -z ${worker} ]];then

((pass++))

echo "nginx is running as worker";

else

((fail++))

echo "nginx is not running as worker";

fi;

if [[ ! -z ${master} ]];then

((pass++))

echo "nginx is running as master";

else

((fail++))

echo "nginx is not running as master";

fi;

if [[ ! -z ${serverup} ]];then

((pass++))

echo "Nginx server is up";

else

((fail++))

echo "Nginx server is not up";

fi;

if [[ ! -z ${serverurl} ]];then

((pass++))

echo "Nginx server is redirecting to google.com";

else

((fail++))

echo "Nginx server is not redirecting to google.com ";

fi;

fi;

echo $pass $fail

score=$(( $pass * 25 ))

echo "FS_SCORE:$score%"

i was only able to install nginx and postgresql but not satisy the conditions given in .score.sh
Can
someone help me how do I install nginx as both master worker node and master and direct it to
google?

postgresql nginx ansible yaml

https://stackoverflow.com/questions/63546894/write-tasks-to-install-nginx-and-postgresql-using-ansible-playbook 1/4
6/29/2021 write tasks to install nginx and postgresql using ansible-playbook - Stack Overflow

Share Edit Follow Flag edited Aug 23 '20 at 12:36 asked Aug 23 '20 at 12:23
ilias-sp kalyani reddy
4,208 3 18 37 1 1 2

2 There are Ansible modules that can do the tasks you are running through the script. Specifically -
service, uri, etc.
– seshadri_c
Aug 24 '20 at 4:06

5 Answers Active Oldest Votes

This worked for me and the fresco course did get passed for me.

0 ---

#installing nginx and postgresql

- name: Install nginx

apt: name=nginx state=latest

tags: nginx

- name: restart nginx

service:

name: nginx

state: started

- name: Install PostgreSQL

apt: name=postgresql state=latest

tags: PostgreSQL

- name: Start PostgreSQL

service:

name: postgresql

state: started

Share Edit Follow Flag answered Dec 10 '20 at 5:47


Blah
1

Hi I am running the same command given above but not all Test case getting a pass
below is
result
0
nginx is running as worker

nginx is running as master

Nginx server is not up

Nginx server is not redirecting to google.com

2 2

https://stackoverflow.com/questions/63546894/write-tasks-to-install-nginx-and-postgresql-using-ansible-playbook 2/4
6/29/2021 write tasks to install nginx and postgresql using ansible-playbook - Stack Overflow

FS_SCORE:50%

I am running my playbook.yml using the command :" ansible-playbook master_playbook.yml"

Please suggest if I am missing any command to run.

Share Edit Follow Flag answered Aug 31 '20 at 7:54


issuesolver in
41 3

---

#installing nginx and postgresql

0 - name: Install nginx

apt: name=nginx state=latest

tags: nginx

- name: restart nginx

service:

name: nginx

state: started

- name: Install PostgreSQL

apt: name=postgresql state=latest

tags: PostgreSQL

- name: Start PostgreSQL

service:

name: postgresql

state: started

I have tried the above one getting below error message

ERROR! 'apt' is not a valid attribute for a Play

The error appears to be in '/projects/challenge/fresco_nginx/tasks/main.yml' : line 3, column 3,


but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

#installing nginx and postgresql

- name: Install nginx

^ here

Share Edit Follow Flag edited Feb 24 at 2:25 answered Feb 23 at 12:43
bguiz user15267116
23k 40 141 229 1

https://stackoverflow.com/questions/63546894/write-tasks-to-install-nginx-and-postgresql-using-ansible-playbook 3/4
6/29/2021 write tasks to install nginx and postgresql using ansible-playbook - Stack Overflow

0 #installing nginx and postgresql

name: Updating apt


command: sudo apt-get update

name: Install list of packages


apt:
pkg: ['nginx', 'postgresql']
state: latest

name: Start Ngnix service


service:
name: nginx
state: started

name: Start PostgreSQL service


service:
name: postgresql
state: started

if nginx not started use


'sudo service nginx restart'

Share Edit Follow Flag edited Aug 25 '20 at 14:16 answered Aug 25 '20 at 14:10
supraja
11 3

All the answers give above works on installing nginx, the problem is nginx is running port 80 and
the score script check 9090. If you curl using port 80 you will get response. So you need to find
0 some way to change the nginx conf file to use port 9090.

Share Edit Follow Flag answered Jun 17 at 6:55


Aritra Roy
3 1

https://stackoverflow.com/questions/63546894/write-tasks-to-install-nginx-and-postgresql-using-ansible-playbook 4/4

You might also like