34 lines
1.1 KiB
YAML
34 lines
1.1 KiB
YAML
- name: Check if node is installed
|
|
shell:
|
|
cmd: hash node 2> /dev/null
|
|
ignore_errors: yes
|
|
changed_when: no
|
|
register: node_installation_status
|
|
|
|
- block:
|
|
- name: Install nvm
|
|
shell: >
|
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
|
|
args:
|
|
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
|
|
|
|
- name: Install Node.JS
|
|
shell:
|
|
cmd: |
|
|
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
|
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
|
nvm install node
|
|
|
|
- name: Add NVM exports to bashrc
|
|
lineinfile:
|
|
path: "{{ ansible_env.HOME }}/.bashrc"
|
|
line: 'export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"'
|
|
regexp: '^export NVM_DIR=.+'
|
|
|
|
- name: Add NVM script to bashrc
|
|
lineinfile:
|
|
path: "{{ ansible_env.HOME }}/.bashrc"
|
|
line: '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"'
|
|
regexp: '\[ -s |\$NVM_DIR/nvm\.sh \].+'
|
|
|
|
when: node_installation_status.rc | int != 0 |