Giter Club home page Giter Club logo

ansible-nodejs-role's Introduction

ansible-nodejs-role

This is an Ansible role which adds the the NodeSource APT repository and installs Node.js.

Currently this role supports the following operating systems and releases.

  • Ubuntu 14.04 LTS (Trusty Tahr)
  • Ubuntu 16.04 LTS (Xenial Xerus)

Usage

You can either:

  • Install the playbook via Ansible Galaxy:
$ ansible-galaxy install nodesource.node
- src: https://github.com/nodesource/ansible-nodejs-role
$ ansible-galaxy install -r requirements.txt

Configure

Then configure it as follows:

- hosts: servers
  roles:
     - nodesource.node

Role Variables

  • nodejs_nodesource_pin_priority: Pin-Priority of the NodeSource repository (default: 500).
  • nodejs_version: Set Node version (options: 0.10 or 0.12 or 4.6, default: 4.6)

Testing

To test this role using molecule:

$ make
$ molecule test

Author

Mark Wolfe [email protected]

License

This code is Copyright (c) 2014 NodeSource and Mark Wolfe and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.

ansible-nodejs-role's People

Contributors

chrislea avatar eins78 avatar jwhitlock avatar luissquall avatar mblayman avatar rvagg avatar ryanlelek avatar spk avatar thlorenz avatar tjanez avatar wolfeidau avatar yanchek99 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-nodejs-role's Issues

Question: Is this role still maintained / recommended?

I'm investigating the possibility of using this role to install node, but I can't tell if it's still a good way to proceed. There are a lot of really old open issues referencing problems installing now-old versions of node. Is this flexible enough to install current (8.x / 10.x) versions of node, or should I be looking elsewhere? The README only specifies version 4.6 as the highest version supported... Doesn't seem promising. Is there a better way to install node using ansible these days?

Importing NodeSource GPG key fails with ansible 1.9

After upgrading to ansible 1.9, importing the GPG fails with a sudo error. It appears to be an upstream problem as there are bugs that sound similar, but I thought it might save someone time if they came here looking for a solution.

TASK: [nodesource.node | Import the NodeSource GPG key into apt] **************
failed: [default] => {"cmd": "apt-key add -", "failed": true, "rc": 1}
stdout: ERROR: This command can only be used by root.

SSL Failure on Import the NodeSource GPG key into apt

In the last 24 hours, I began getting a failure on the "Import the NodeSource GPG key into apt" step with Ansible 1.9.2

A full run can be seen in TravisCI:
https://travis-ci.org/mozilla/kuma/jobs/158534929

The full URL seems to have a valid certificate:
https://deb.nodesource.com/gpgkey/nodesource.gpg.key

However, the root URL now redirects to GitHub:
https://deb.nodesource.com

I suspect the problem is that Ansible does certificate validation of the root URL, not the full path, and is detecting a problem with the hostname change.

Here's the output from a verbose run:

TASK: [nodesource.node | Import the NodeSource GPG key into apt] ************** 
<127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant
<127.0.0.1> REMOTE_MODULE apt_key state=present url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key
<127.0.0.1> EXEC ssh -C -tt -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/john/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=2222 -o IdentityFile="/Users/john/src/kuma/.vagrant/machines/developer-local/virtualbox/private_key" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 127.0.0.1 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1473372799.77-250761793755640 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1473372799.77-250761793755640 && echo $HOME/.ansible/tmp/ansible-tmp-1473372799.77-250761793755640'
<127.0.0.1> PUT /var/folders/61/s6_xxhqd3nl27_vgq9fzjmkr0000gq/T/tmpHnT09K TO /home/vagrant/.ansible/tmp/ansible-tmp-1473372799.77-250761793755640/apt_key
<127.0.0.1> EXEC ssh -C -tt -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/john/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=2222 -o IdentityFile="/Users/john/src/kuma/.vagrant/machines/developer-local/virtualbox/private_key" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 127.0.0.1 /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=peqdhgbtpdvxszbvlonushpnfpjjmcyq] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-peqdhgbtpdvxszbvlonushpnfpjjmcyq; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 PYTHONDONTWRITEBYTECODE=1 /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1473372799.77-250761793755640/apt_key'"'"''
failed: [developer-local] => {"failed": true}
msg: Failed to validate the SSL certificate for deb.nodesource.com:443. Use validate_certs=False (insecure) or make sure your managed systems have a valid CA certificate installed. Paths checked for this platform: /etc/ssl/certs, /etc/pki/ca-trust/extracted/pem, /etc/pki/tls/certs, /usr/share/ca-certificates/cacert.org, /etc/ansible

FATAL: all hosts have already failed -- aborting
TASK: [nodesource.node | Import the NodeSource GPG key into apt] ************** 
<127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant
<127.0.0.1> REMOTE_MODULE apt_key state=present url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key
<127.0.0.1> EXEC ssh -C -tt -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/john/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=2222 -o IdentityFile="/Users/john/src/kuma/.vagrant/machines/developer-local/virtualbox/private_key" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 127.0.0.1 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1473372799.77-250761793755640 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1473372799.77-250761793755640 && echo $HOME/.ansible/tmp/ansible-tmp-1473372799.77-250761793755640'
<127.0.0.1> PUT /var/folders/61/s6_xxhqd3nl27_vgq9fzjmkr0000gq/T/tmpHnT09K TO /home/vagrant/.ansible/tmp/ansible-tmp-1473372799.77-250761793755640/apt_key
<127.0.0.1> EXEC ssh -C -tt -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/john/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=2222 -o IdentityFile="/Users/john/src/kuma/.vagrant/machines/developer-local/virtualbox/private_key" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 127.0.0.1 /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=peqdhgbtpdvxszbvlonushpnfpjjmcyq] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-peqdhgbtpdvxszbvlonushpnfpjjmcyq; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 PYTHONDONTWRITEBYTECODE=1 /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1473372799.77-250761793755640/apt_key'"'"''
failed: [developer-local] => {"failed": true}
msg: Failed to validate the SSL certificate for deb.nodesource.com:443. Use validate_certs=False (insecure) or make sure your managed systems have a valid CA certificate installed. Paths checked for this platform: /etc/ssl/certs, /etc/pki/ca-trust/extracted/pem, /etc/pki/tls/certs, /usr/share/ca-certificates/cacert.org, /etc/ansible

FATAL: all hosts have already failed -- aborting

node version

Does this role support explicit Node version installation?

io.js Ansible role

putting this note here .. we need to offer the same thing but for io.js

Support for 20.04 is missing

Currently Ubuntu 16.04 LTS (Xenial Xerus) is latest supported version.

Can you add support for versions which are not EOLed?

Can't install the specific version of nodejs

TASK [ansible-nodejs-role : Install Node.js] ***********************************
fatal: [192.168.33.33]: FAILED! => {"cache_update_time": 1472710763, "cache_updated": true, "changed": false, "failed": true, "msg": "'/usr/bin/apt-get -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" install 'nodejs=4.4_'' failed: E: Version '4.4_' for 'nodejs' was not found\n", "stderr": "E: Version '4.4*' for 'nodejs' was not found\n", "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information..."]}

Role Broken, possible external package removed

Error:

TASK [nodesource.node : Install Node.js] ***************************************
fatal: [MYDOMAIN.COM]: FAILED! => {"cache_update_time": 1455109514, "cache_updated": true, "changed": false, "failed": true, "msg": "'/usr/bin/apt-get -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" install 'nodejs=4.2_'' failed: E: Version '4.2_' for 'nodejs' was not found\n", "stderr": "E: Version '4.2*' for 'nodejs' was not found\n", "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information..."]}

Previous installed Node doesn't get upgraded

When there's already a version of node installed (in my case v0.10.33), it doesn't update the package.

If however I manually run apt-get upgrade on the server, it presents nodejs as being upgradeable.

Register variable for task completion

This is more of a question than a bug.

Q: Does it make sense to register a variable for the "Install Node.js" task?

I use this playbook to install node.js and have other tasks in the ansible build that have a dependency on it. I would like to test that node.js installed before the running the dependent tasks. For my build, I ended up adding a task that makes sure node.js is present and register "nodeInstalled". Thoughts?

Install Node.js fails, "Could not fetch updated apt files"

Installing on Ubuntu 14.04, I get

TASK [nodesource.node : Install Node.js] ***************************************
fatal: [CCAP4]: FAILED! => {"changed": false, "failed": true, "msg": "Could not fetch updated apt files"}

on the last task. I can install node via the command line fine at this stage using apt-get install nodejs. Using -vvv produces

fatal: [CCAP4]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"allow_unauthenticated": false, "autoremove": false, "cache_valid_time": null, "deb": null, "default_release": null, "dpkg_options": "force-confdef,force-confold", "force": false, "install_recommends": null, "only_upgrade": false, "package": ["nodejs"], "pkg": ["nodejs"], "purge": false, "state": "present", "update_cache": true, "upgrade": null}, "module_name": "apt"}, "msg": "Could not fetch updated apt files"}

Does the role require sudo privileges?

I did not see any other issues asking this same question, so I think I must be doing something wrong since it runs for other users. I am running the role and getting errors that sudo is required to install the gpg signing key, etc.

TASK: [nodesource.node | Check nodejs_version variable] ***********************
ok: [52.20.7.220]

TASK: [nodesource.node | Ensure the system can use the HTTPS transport for APT] ***
ok: [52.20.7.220]

TASK: [nodesource.node | Install HTTPS transport for APT] *********************
skipping: [52.20.7.220]

TASK: [nodesource.node | Import the NodeSource GPG key into apt] **************
failed: [52.20.7.220] => {"cmd": "apt-key add -", "failed": true, "rc": 1}
stdout: ERROR: This command can only be used by root.


FATAL: all hosts have already failed -- aborting

If I change the role inline to add sudo: yes to the following tasks, then it runs correctly without errors.

# Install Node.js using packages crafted by NodeSource

---
- name: Check nodejs_version variable
  assert:
    that: nodejs_version in [ "0.10", "0.12" ]

- name: Ensure the system can use the HTTPS transport for APT
  stat: path=/usr/lib/apt/methods/https
  register: apt_https_transport

- name: Install HTTPS transport for APT
  sudo: yes
  apt: pkg=apt-transport-https state=installed
  when: not apt_https_transport.stat.exists

- name: Import the NodeSource GPG key into apt
  sudo: yes
  apt_key: url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key state=present

- name: Add NodeSource deb repository
  sudo: yes
  apt_repository: repo='deb https://deb.nodesource.com/node_{{ nodejs_version }} {{ ansible_distribution_release }} main' state=present

- name: Add NodeSource deb-src repository
  sudo: yes
  apt_repository: repo='deb-src https://deb.nodesource.com/node_{{ nodejs_version }} {{ ansible_distribution_release }} main' state=present

- name: Add NodeSource repository preferences
  sudo: yes
  template:
    src: etc/apt/preferences.d/deb_nodesource_com_node.pref.2
    dest: /etc/apt/preferences.d/deb_nodesource_com_node.pref

- name: Install Node.js
  sudo: yes
  apt: pkg=nodejs={{ nodejs_version }}.* state=installed update_cache=yes

Any advice on what I am doing wrong here would be greatly appreciated. Thanks!

Have to use sudo with npm -g

This causes issues with some npms, e.g. bower.

To get around it I added the following to the task:

- name: Set place for global npms
  shell: npm config set prefix '/home/{{ node_user }}/.npm-packages'
  sudo: no

- name: Add it to your paths
  shell: echo 'export PATH="$PATH:$HOME/.npm-packages/bin"' >> /home/{{ node_user }}/.zshrc

I didn't do a pull request because I wasn't sure how to inorporate the node_user and .zshrc vs .bashrc etc.... but the above fixes the issue and lets you use npm -g without sudo for node_user

Provision issue with hosts file.

The ansible.raw_arguments configuration in the Vagrantfile causes the provision to fail. The following error results when trying to provision the server:

ERROR: Unable to find an inventory file, specify one with -i ?
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

Currently work around is to comment out the ansible.raw_arguments line in the Vagrantfile and provision the server.

Versions used when the error occured:

  • vagrant: 1.7.0
  • virtualbox: 4.3.20
  • ansible: 1.7.2
    • note: ansible was installed from macports.

Yum instead of apt

What happens if i want to use yum instead of apt? It doesn't work, do you know what the required changes would have to be to make it compatible?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.