Saturday, December 8, 2018

Install Nginx and PostgreSQL using Ansible Playbook

Below Script will Install the NGiNX and PostgreSQL in linux ubuntu.

1) Copy the below code in ansible home directory using vi test.yml

---
- name: Install nginx
  hosts: all

  become: true

  tasks:
  - shell: apt-get upgrade -y; apt-get update

  - name: Install nginx
    apt:
      name: nginx
      state: latest

  - name: Start NGiNX
    service:
      name: nginx
      state: started

  - name: Install PostgreSQL
    apt:
      name: postgresql
      state: latest

  - name: Start PostgreSQL
    service:
      name: postgresql
      state: started
...


2) Save using esc button + :wq!

3) Run the command 

ansible-playbook -i myhosts test.yml





The output will look like this




14 comments:

sree said...

Supperb ...!

James Zicrov said...

Do Nginix and PostgreSQL have any connection with 'Write' functionality of PostgreSQL?Thanks.

SSIS PostgreSql Write

Rajani Bachina said...

Good post! keep sharing..
E- Learning Training Portal
Portal- ELearning
DevOps Online Hub
Online E- Learning Training Portal

Rajani said...

Good Information!!Thanks for sharing..
Docker Training in Hyderabad
Docker and Kubernetes Online Training
Docker Training

Rajani said...

Good Information!!Thanks for sharing..
Docker Training in Hyderabad
Docker and Kubernetes Online Training
Docker Training

James Zicrov said...

I think SSIS Postgresql Write is very important to break down complex and structural IT problems.

SSIS Postgresql Write

Bhanu Sree said...

well! Thanks for providing a good stuff
Microsoft Azure DevOps training hyderabad
Microsoft Azure DevOps Training

Rajani said...

This is really an amazing post, thanks for sharing!!
DevOps Training
DevOps Training institute in Ameerpet
DevOps Classroom Training in Hyderabad

Rajani said...

Thank you for sharing vauable infromation.
DevOps Training
DevOps Online Training
DevOps Training in Ameerpet

Rajani said...


Great article. Thanks for sharing it with us.
DevOps Training
DevOps Online Training
DevOps Training in Ameerpet

Gufran Zameer said...

This is not working in hacker rank.

the .score.sh file looks like
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%"

Gufran Zameer said...

Hi, I tried this in Hacker Rank. It is not working. I tried to solve this in many ways but still no luck. The .score.sh file in hacker rank is
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%"

Unknown said...

What error you are getting.

Unknown said...

score.sh will evaluate your score. But i meed to know what error you are getting. Did you copy pasted same code as above. I have tested this and it working fine. Ensure that yaml will work based on indentation.Ensure that you follow correct indetation and correct keywords.