rvm / rvm1-ansible

The official ansible RVM role to install and manage your Ruby versions.
MIT License
271 stars 136 forks source link

Unable to install for single user on a fresh machine: freezes asking for sudo password #127

Closed jogaco closed 7 years ago

jogaco commented 7 years ago

I'm quite familiar with rvm.

I've tried several options, as documented in README, to install rvm and ruby on a fresh Ubuntu 16.04 machine for single user, without luck.

The machine has a myuser sudoer, with disabled root login for security reasons.

The task freezes when installing rubies.

First try:

---
- name: Configure servers with ruby support for single user
  hosts: newservers

  roles:
    - { role: rvm_io.ruby,
        tags: ruby,
        rvm1_rubies: ['ruby-2.3.3'],
        rvm1_user: 'myuser',
      }

With command ansible-playbook -i hosts.ini ruby_script1.yml --user myuser --ask-sudo-pass -v

Freezes and doing a ps at terminal I can see a task: sudo -p %p password required for 'apt-get --quiet --yes update': apt-get --quiet --yes update

Which is rvm waiting for a password trying to install pre-requisites.

Second try: If I try something slightly different: not disabling root login, with:

---
- name: Configure servers with ruby support for single user
  hosts: newservers

  roles:
    - { role: rvm_io.ruby,
        tags: ruby,
        rvm1_rubies: ['ruby-2.3.3'],
        rvm1_user: 'myuser',
        rvm1_install_flags: '--auto-dotfiles --user-install',
        rvm1_install_path: '/home/myuser/.rvm'
      }

With command: ansible-playbook -i hosts.ini ruby_script2.yml --user root --ask-pass -v

Freezes again, with same password task listed.

I am quite desperate to automate this task. Without deep knowledge of ansible, if you lunch rvm with sudo, that would certainly work, as it is working by issuing the command manually at the console:

sudo rvm install 2.3.3

Whereas if you try the command

rvm install 2.3.3

It stops and asks for password to install pre-requisites.

jogaco commented 7 years ago

Seems to be related to #113 but in no way has it been addressed, as I am hitting the same problem

jogaco commented 7 years ago

This does the trick and avoids rvm asking for the password, which is the cause the task freezes. Notice the become_user: root for installing rvm requirements

- name: Install rvm requirements
  become: yes
  command: '{{ rvm1_rvm }} requirements'
  become_method: sudo
  become_user: root
  when: rvm1_rubies

- name: Install rubies
  command: '{{ rvm1_rvm }} install {{ item.item }} {{ rvm1_ruby_install_flags }}'
  when: rvm1_rubies and item.rc|default(0) != 0
  with_items: '{{ detect_rubies.results }}'
matthewlein commented 7 years ago

I had this issue as well, and @jogaco's PR didn't work for me, unless I missed something (I just copied over the 1 changed file).

I went with the manually dependency list approach from https://github.com/rvm/rvm1-ansible/issues/113 and that did work. Not super elegant, but working for now.

lpaulmp commented 7 years ago

@jogaco

- { role: rvm_io.ruby,
     tags: ruby,
     rvm1_rubies: ['ruby-2.3.3'],
     rvm1_user: 'myuser',
     rvm1_install_path: '/home/myuser/.rvm'
      }

Also which version did you used?

jogaco commented 7 years ago

Ansible 2.2.0

jogaco commented 7 years ago

@matthewlein Just re-tested on a fresh Ubuntu machine and it works.

---
- name: Configure servers with ruby support for single user
  hosts: newservers
  become: yes

  roles:
    - { role: rvm_io.ruby,
        tags: ruby,
        rvm1_rubies: [2.4.0],
        rvm1_user: 'myuser',
        rvm1_install_flags: '--auto-dotfiles --user-install',
        rvm1_install_path: '/home/{{ ansible_user }}/.rvm',
      }

With command: ansible-playbook -i hosts.ini ruby_script2.yml --user myuser --ask-sudo-pass -v

Check my PR #141

jogaco commented 7 years ago

Hold on. It works fine with rvm 1.28.0. It freezes with rvm 1.29.0 and master. I am trying to open an issue with rvm but the Submit button is not enabled, after I fill in a very long list of required details.

matthewlein commented 7 years ago

@jogaco Thanks for the tip, 1.28.0 worked with my manual dependencies approach while the latest stable did not either.

pkuczynski commented 7 years ago

@mpapis could it be that your latest change for pclinuxos broke it?

mpapis commented 7 years ago

should not be related to pclinxos change, how about trying to disable autolibs if it's not desired functionality? rvm autolibs disabled or rvm --autolibs=0 install ruby?

jogaco commented 7 years ago

This is the issue I tried to submit without luck to https://github.com/rvm/rvm repository. Was not able as the submit button was not enabled.

Description

Impossible to automate installation of rubies with ansible: password required for 'apt-get --quiet --yes update': ..- even if running rvm requirements before ruby installation.

Steps to reproduce

OS: Ubuntu Description: Ubuntu 14.04.5 LTS With version 1.28, I can do this without any problem: In a machine with rvm pre-installed:

  1. Log in as non-root user
  2. run sudo .rvm/bin/rvm requirements
  3. exit
  4. Log-in again
  5. run rvm install 2.4.0
    
    Warning, new version of rvm available '1.29.0', you are using older version '1.28.0'.
    You can disable this warning with:    echo rvm_autoupdate_flag=0 >> ~/.rvmrc
    You can enable  auto-update  with:    echo rvm_autoupdate_flag=2 >> ~/.rvmrc
    Searching for binary rubies, this might take some time.
    Found remote file https://rubies.travis-ci.org/ubuntu/14.04/x86_64/ruby-2.4.0.tar.bz2
    Checking requirements for ubuntu.
    Requirements installation successful.
    ruby-2.4.0 - #configure
    ruby-2.4.0 - #download

No password is asked to install the ruby version.

With version 1.29 (master).

 1. Log in as non-root user
 2. run `sudo .rvm/bin/rvm requirements`

Checking requirements for ubuntu. Installing requirements for ubuntu. Updating system.......


 3. exit
 4. Log-in again
 5. run `rvm install 2.4.0`
This outputs:
`Updating system myuser password required for 'apt-get --quiet --yes update': ..-`

This prevents from installing rvm and rubies in an automated script, like ansible.

## Expected behavior

After installing requirements with rvm requirements, it should not try to update the system, which prompts for password.

## Actual behavior

Tries to update the system, even after a requirements command, and prompts for a password.

https://gist.github.com/jogaco/033f5b474ff5ff76b9bcb00c67d3f0ad

## Environment info

ruby-2.4.0:

  system:
    uname:        "Linux ubuntu-1gb-swapon-empty-1gb-fra1-01 4.4.0-53-generic #74~14.04.1-Ubuntu SMP Fri Dec 2 03:43:31 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux"
    name:         "Ubuntu"
    version:      "14.04"
    architecture: "x86_64"
    bash:         "/bin/bash => GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)"
    zsh:          " => not installed"
    remote path:  "ubuntu/14.04/x86_64"

  rvm:
    version:      "rvm 1.29.0 (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]"
    updated:      "6 seconds ago
    path:         "/home/myuser/.rvm"
    autolibs:     "[3] Allow RVM to use package manager if found, install missing dependencies."

  ruby:
    interpreter:  "ruby"
    version:      "2.4.0p0"
    date:         "2016-12-24"
    platform:     "x86_64-linux"
    patchlevel:   "2016-12-24 revision 57164"
    full_version: "ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]"

  homes:
    gem:          "/home/myuser/.rvm/gems/ruby-2.4.0"
    ruby:         "/home/myuser/.rvm/rubies/ruby-2.4.0"

  binaries:
    ruby:         "/home/myuser/.rvm/rubies/ruby-2.4.0/bin/ruby"
    irb:          "/home/myuser/.rvm/rubies/ruby-2.4.0/bin/irb"
    gem:          "/home/myuser/.rvm/rubies/ruby-2.4.0/bin/gem"
    rake:         "/home/myuser/.rvm/rubies/ruby-2.4.0/bin/rake"

  environment:
    PATH:         "/home/myuser/.rvm/gems/ruby-2.4.0/bin:/home/myuser/.rvm/gems/ruby-2.4.0@global/bin:/home/myuser/.rvm/rubies/ruby-2.4.0/bin:/home/myuser/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
    GEM_HOME:     "/home/myuser/.rvm/gems/ruby-2.4.0"
    GEM_PATH:     "/home/myuser/.rvm/gems/ruby-2.4.0:/home/myuser/.rvm/gems/ruby-2.4.0@global"
    MY_RUBY_HOME: "/home/myuser/.rvm/rubies/ruby-2.4.0"
    IRBRC:        "/home/myuser/.rvm/rubies/ruby-2.4.0/.irbrc"
    RUBYOPT:      ""
    gemset:       ""
mpapis commented 7 years ago

@jogaco this is what --auotlibs=0 does, have you tried adding it to rvm1_ruby_install_flags?

jogaco commented 7 years ago

Thanks @mpapis for the tip. It works fine. Example of working script:

---
- name: Configure servers with ruby support for single user
# ansible-playbook -i hosts.ini ruby_script.yml --user deploy --ask-sudo-pass -v
  hosts: newservers
  become: yes
  vars:
  - ruby_version: 2.4.0

  roles:
    - { role: rvm_io.ruby,
        tags: ruby,
        rvm1_rubies: ["{{ ruby_version }}"],
        rvm1_user: myuser,
        rvm1_install_flags: '--auto-dotfiles --user-install',
        rvm1_install_path: '/home/myuser/.rvm',
        rvm1_ruby_install_flags: '--autolibs=0'
      }
karloskalcium commented 7 years ago

Note: There is also a task here: https://github.com/rvm/rvm1-ansible/blob/master/tasks/rvm.yml that is supposed to set the autolibs; however, this doesn't work on any machine that already has a version of RVM installed. This autolibs variable should either be removed, or the 'when' clause removed as it shouldn't limit when you can set the autolibs variable...

Setting --autolibs=0 does work however. Setting rvm1_autolib_mode will not (because that block doesn't run if RVM is already installed)