LoginSignup
0
1

More than 5 years have passed since last update.

ansible で nvm をインストールすると以降 ansible-playbook できないときの対処

Posted at

現象

nvm を後述の設定で ansible-playbook し、その後もう一度 ansible-playbook すると以下のメッセージが発生し、GATHERING FACTS の時点でエラーとなる

GATHERING FACTS *************************************************************** 
<IP_ADDRESS> ESTABLISH CONNECTION FOR USER: USER_NAME
<IP_ADDRESS> REMOTE_MODULE setup
<IP_ADDRESS> EXEC ssh -C -tt -v -o ForwardAgent=yes -o ControlMaster=no -F ssh_config -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 IP_ADDRESS /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1476609685.34-231943826271836 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1476609685.34-231943826271836 && echo $HOME/.ansible/tmp/ansible-tmp-1476609685.34-231943826271836'
/root/.ansible/tmp/ansible-tmp-1476609685.34-231943826271836/setup
<IP_ADDRESS> EXEC ssh -C -tt -v -o ForwardAgent=yes -o ControlMaster=no -F ssh_config -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthenticat/root/.ansible/tmp/ansible-tmp-1476609685.34-231943826271836/ >/dev/null 2>&1'
failed: [IP_ADDRESS] => {"failed": true, "parsed": false}
/root/.ansible/tmp/ansible-tmp-1476609685.34-231943826271836/setup': [Errno 2] No such file or directory
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data ssh_config
debug1: ssh_config line 1: Applying options for IP_ADDRESS
debug1: Connecting to IP_ADDRESS [IP_ADDRESS] port 22.
debug1: fd 3 clearing O_NONBLOCK
debug1: Connection established.
debug1: identity file /Users/USER_NAME/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/USER_NAME/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000
debug1: Authenticating to IP_ADDRESS:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr umac-64@openssh.com zlib@openssh.com
debug1: kex: client->server aes128-ctr umac-64@openssh.com zlib@openssh.com
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:hogehogehoge
Warning: Permanently added 'IP_ADDRESS' (RSA) to the list of known hosts.
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/USER_NAME/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (publickey).
Authenticated to IP_ADDRESS ([IP_ADDRESS]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Requesting authentication agent forwarding.
debug1: Sending command: /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python \033[?25h\033[0G\033[K\033[?25h\033[0G\033[K/root/.ansible/tmp/ansible-tmp-1476609685.34-231943826271836/setup; rm -rf \033[?25h\033[0G\033[K\033[?25h\033[0G\033[K/root/.ansible/tmp/ansible-tmp-1476609685.34-231943826271836/ >/dev/null 2>&1'
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 1 clearing O_NONBLOCK
debug1: fd 2 clearing O_NONBLOCK
Connection to IP_ADDRESS closed.
Transferred: sent 4024, received 3040 bytes, in 0.9 seconds
Bytes per second: sent 4470.7, received 3377.5
debug1: Exit status 0
debug1: compress outgoing: raw data 727, compressed 449, factor 0.62
debug1: compress incoming: raw data 449, compressed 727, factor 1.62

発生環境

ホスト

  • Mac OS X 10.11.6
  • ansible 1.9.6

ゲスト

  • CentOS 6.8(digital ocean)

問題発生した設定

node.yml
---
- name: download and install nvm
  shell: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
  args:
    creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"

- name: Register the NVM_DIR
  shell: echo $NVM_DIR
  register: nvm_dir 

- name: install node
  shell: . {{ nvm_dir.stdout }}/nvm.sh && nvm install {{ node_version }} && nvm run {{ node_version }} --version && nvm alias default {{ node_version }}
  args:
    creates: "{{ nvm_dir.stdout }}/versions/node/v{{ node_version }}"

対処

nodebrew を使った

node.yml
---
- name: download and install nodebrew
  shell: curl -L git.io/nodebrew | perl - setup
  args:
    creates: "{{ ansible_env.HOME }}/.nodebrew"

- name: path to current node
  lineinfile:
    dest=~/.bashrc
    state=present
    line="PATH={{ ansible_env.HOME }}/.nodebrew/current/bin:$PATH"

- name: install node
  shell: nodebrew install-binary {{ node_version }} && nodebrew alias default {{ node_version }} && nodebrew use {{ node_version }} && npm install -g webpack
  args:
    creates: "{{ ansible_env.HOME }}/.nodebrew/node/{{ node_version }}"

 備考

  • ssh の環境に依存する問題なのかもしれないが、対処できなかったためツールを変えて対応した
  • nvmnodebrew でバージョン表記に v を含むかが微妙に異なるので注意
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1