title: Running Forever in Ansible Provision Never Fires or Always Hangs
body: <p>I've come across a problem with Anisble hanging when trying to start a <code>forever</code> process on an Ansible node.  I have a very simple API server I'm creating in vagrant and provisioning with Ansible like so:</p>
  
  <pre><code>---
  - hosts: all
    sudo: yes
  
    roles:
      - Stouts.nodejs
      - Stouts.mongodb
  
    tasks:
      - name: Install Make Dependencies
        apt: name={{ item }} state=present
        with_items:
          - gcc
          - make
          - build-essential
  
      - name: Run NPM Update
        shell: /usr/bin/npm update
  
      - name: Create MongoDB Database Folder
        shell: /bin/mkdir -p /data/db
        notify:
          - mongodb restart
  
      - name: Generate Dummy Data
        command: /usr/bin/node /vagrant/dataGen.js
  
      - name: "Install forever (to run Node.js app)."
        npm: name=forever global=yes state=latest
  
      - name: "Check list of Node.js apps running."
        command: /usr/bin/forever list
        register: forever_list
        changed_when: false
  
      - name: "Start example Node.js app."
        command: /usr/bin/forever start /vagrant/server.js
        when: "forever_list.stdout.find('/vagrant/server.js') == -1"
  </code></pre>
  
  <p>But even though Ansible acts like everything is fine, no forever process is started.  When I change a few lines to remove the <code>when:</code> statement and force it to run, Ansible just hands, possibly running the forever process (forever, I presume) but not launching the VM to where I can interact with it.</p>
  
  <p>I've referenced essentially two points online; the <a href="https://stackoverflow.com/questions/20919222/ansible-hangs-when-starting-node-js-server">only</a> <a href="https://servercheck.in/blog/start-nodejs-app-with-forever-and-ansible" rel="nofollow noreferrer">sources</a> I can find.</p>