Ansible-playbook to install and configure Nginx+Nodejs+Npm+PM2

+1 vote
Hi Guys, I want to create a Ansible-playbook to install and configure Nginx which should mapped with port 80, nodejs version 8, npm version 6, pm2 on aws ubuntu 16. I have one project as zip file in my local system. So once installed all then i need to move this .zip file to remote system with file path /home/ubuntu. How to achieve this? If you people have any play book please post here. It will help me. Thanks
Sep 3 in Ansible by Latchu

edited Sep 3 151 views

1 answer to this question.

+1 vote
Best answer

Try thhis out:

- hosts: hosts
    - name: Installs nginx web server
      apt: pkg=nginx state=installed update_cache=true

     - name: add apt key for nodesource
      apt_key: url=

    - name: add repo for nodesource
            repo: 'deb {{ ansible_distribution_release }} main'
            update_cache: yes

    - name: install nodejs
      apt: name=nodejs

    - name: install NPM
         shell: npm i
           chdir: /home/ubuntu

    - name: Install PM2
        name: pm2
        global: yes
answered Sep 3 by Kalgi
• 42,410 points
Many Thanks Kalgi. I have completed that nginx, nodejs, npm, pm2. Now i would like to implement my project using ansible. I have my project as zip in my local directory. i have copied and stored then unzip in remote system using copy and unarchive module. My issue that i couldn't copy .(dot) file like hidden file. How to copy a hidden file from local system to remote system. Please let me know pa. Many Thanks for your support.
My project in remote system following directory /home/ubuntu/proj/ . When i try to start my project using pm2 start through ansible then it thrown error like below.

FAILED! => {"changed": true, "cmd": ["pm2", "start", "index.js", "--name", "Proj-US", "/home/ubuntu/proj-us/"], "delta": "0:00:00.716599", "end": "2019-09-04 05:24:18.904163", "msg": "non-zero return code", "rc": 1, "start": "2019-09-04 05:24:18.187564", "stderr": "[PM2][ERROR] script not found : /home/ubuntu/index.js\nscript not found : /home/ubuntu/index.js", "stderr_lines": ["[PM2][ERROR] script not found : /home/ubuntu/index.js", "script not found : /home/ubuntu/index.js"],

But index.file is available in /home/ubuntu/proj-us. below one is my playbook portion for pm2 start projec

- name: To Start a App
    command: pm2 start index.js --name Proj-US chdir= /home/ubuntu/proj-us
    ignore_errors: yes
    when: npm_finished.changed

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
0 votes
1 answer
0 votes
1 answer