in Technology by
How to Install Nginx using Ansible playbook?

1 Answer

0 votes
by

The playbook file would be:

- hosts: stagingwebservers
 gather_facts: False
 vars:
  - server_port: 8080
 tasks:
  - name: install nginx
    apt: pkg=nginx state=installed update_cache=true
  - name: serve nginx config
     template: src=../files/flask.conf dest=/etc/nginx/conf.d/
     notify:
     - restart nginx
 handlers:
   - name: restart nginx
     service: name=nginx state=restarted
   - name: restart flask app
     service: name=flask-demo state=restarted
...

In the above playbook, we are fetching all hosts of stagingwebservers group for executing these tasks. The first task is to install Nginx and then configure it. We are also taking a flask server for reference. In the end, we also defined handlers so that in case the state changes it will restart Nginx. After executing the above playbook we can verify whether Nginx is installed or not.

ps waux | grep nginx

Related questions

0 votes
    I am new at using Ansible. I tried to create directories and download files using Ansible. Should I use shell ... module is available? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    How to keep data secret in a Ansible playbook?...
asked Jan 29, 2023 in Technology by JackTerrance
0 votes
    I have a playbook that looks like the following. It is supposed to install python onto the remote machine ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    Which command tells ansible to run the playbook on all the hosts except host1? (i)ansible-playbook playbooks/ ... ansible-playbook playbooks/PLAYBOOK_NAME.yml -limit 'all:!host1'...
asked Jan 25, 2023 in Technology by JackTerrance
0 votes
    After a bit of a struggle to set up AWS Route53 IPv6 and my DSN (Ionos) I've managed to set up ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    How to automate the password input in playbook using encrypted files?...
asked Jul 28, 2021 in Technology by JackTerrance
0 votes
    A Playbook starts with three dots …. (1)False (2)True...
asked Jul 4, 2021 in Technology by JackTerrance
0 votes
    A Playbook starts with three dots …. (1)False (2)True...
asked Jan 26, 2023 in Education by JackTerrance
0 votes
    The handler runs only once even if you run the Playbook many times. (1)True (2)False...
asked Jul 5, 2021 in Education by JackTerrance
0 votes
    I've got a Node.js powered site that I'm running on Amazon Elastic Beanstalk. My Node.js app listens on port ... to my site via HTTPS. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Here is the problem I have a requirements.txt that looks like: BeautifulSoup==3.2.0 Django==1.3 Fabric==1.2.0 ... . So what went wrong? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Nginx supports __________ through round robin algorithm....
asked Mar 7, 2021 in Technology by JackTerrance
0 votes
    Nginx has become popular as it resolves...
asked Mar 7, 2021 in Technology by JackTerrance
0 votes
    Nginx was introduced in the year _________....
asked Mar 7, 2021 in Technology by JackTerrance
0 votes
    Nginx supports __________ through SCGI protocol....
asked Mar 7, 2021 in Technology by JackTerrance
...