O nvm exige que um usuário efetue logout / login após a instalação para que as alterações entrem em vigor. Como posso permitir isso em uma tarefa ansible executando via vagrant. aqui está o que eu tentei:
- name : Install nvm
shell: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash
failed_when: False
register: nvm_installed
- name: Kill open ssh sessions - ansible should log back in on next task
shell: "ps -ef | grep sshd | grep 'whoami' | awk '{print \"kill -9\", $2}' | sh"
when: nvm_installed | changed
failed_when: false
- name : Install Node.js v 4.2.x
command : nvm install v4.2
Mas recebo o erro:
fatal: [default] => SSH Error: ssh_exchange_identification: Connection closed by remote host
while connecting to 127.0.0.1:2222
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.
TASK: [check if rpmforge installed] *******************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
o comando vagrant ssh
também falha com o erro:
ssh_exchange_identification: Connection closed by remote host
Eu baseei isso na resposta dada aqui - link
Eu acho que talvez o comando kill esteja matando o daemon sshd em si?
ps -ef | grep sshd | grep 'whoami'
root 2621 1247 0 11:30 ? 00:00:00 sshd: vagrant [priv]
vagrant 2625 2621 0 11:30 ? 00:00:00 sshd: vagrant@notty
root 3232 1247 4 11:34 ? 00:00:00 sshd: vagrant [priv]
vagrant 3235 3232 0 11:34 ? 00:00:00 sshd: vagrant@pts/0
vagrant 3252 3236 0 11:34 pts/0 00:00:00 grep sshd
UPDATE
Eu também tentei o seguinte:
- name : Install nvm
shell: "curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash"
register: nvm_installed
failed_when: False
- name : source bash profiles
shell : source /home/vagrant/.bashrc
when: nvm_installed
register: sourced
- name : Install Node.js v 4.2.x
command : nvm install v4.2
when: sourced
mas receba o seguinte erro:
TASK: [Install Node.js v 4.2.x] ***********************************************
failed: [default] => {"cmd": "nvm install v4.2", "failed": true, "rc": 2}
msg: [Errno 2] No such file or directory
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/lukemackenzie/playbook.retry
default : ok=10 changed=3 unreachable=0 failed=1
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
Se eu executar a etapa Instalar nvm manualmente na máquina gerenciada, ele diz que o seguinte foi anexado a .bashrc
:
export NVM_DIR="/home/vagrant/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm