Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kitchen converge fails with rvm due to environment variable RUBYOPT #1926

Open
rorra opened this issue Dec 22, 2022 · 1 comment
Open

kitchen converge fails with rvm due to environment variable RUBYOPT #1926

rorra opened this issue Dec 22, 2022 · 1 comment

Comments

@rorra
Copy link

rorra commented Dec 22, 2022

👻 Brief Description

I'm using test-kitchen with rvm, it is an old version of chef, and therefore I'm using ruby 2, and the chef workstation works with its own isolated installation of ruby 3.

When I run any chef command, it runs fine:

chef update /Users/rod/my_project/chef/cookbooks/my_cookbook/Policyfile.rb

But then, whenever I run kitchen converge with rvm, it breaks with an error saying that a gem cannot be found. The reason it breaks, is that the environment variable RUBYOPT is sent to Mixlib::ShellOut, and chef-cli, when receives this environment variable, cannot find the right gem path.

Version

3.5.0

Environment

  • MacBook M1
  • ruby 2.73 installed from RVM
  • custom gemset
  • Chef workstation 22.10.1013

Scenario

Trying to test the cookbooks with kitchen and docker.

Steps to Reproduce

  1. Install rvm
  2. Install ruby 2.7.3 rvm install ruby --version 2.7.3
  3. Install chef workstation from brew: chef install --cask chef-workstation
  4. Install docker
  5. Clone sample project: git clone git@github.com:rorra/kitchen-issue.git
  6. Run cd kitchen-issue && bundle
  7. Run kitchen with cd my_cookbook && bundle exec kitchen converge

Expected Result

Command should run without error

Actual Result

-----> Starting Test Kitchen (v3.5.0)
-----> Converging <default-centos-71>...
       Preparing files for transfer
       Policy lock file doesn't exist, running `/usr/local/bin/chef-cli install` for Policyfile /Users/rod/a/b/kitchen-issue/my_cookbook/Policyfile.rb...
       /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/spec_set.rb:86:in `block in materialize': Could not find racc-1.6.1 in any of the sources (Bundler::GemNotFound)
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/spec_set.rb:80:in `map!'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/spec_set.rb:80:in `materialize'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/definition.rb:170:in `specs'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/definition.rb:237:in `specs_for'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/definition.rb:226:in `requested_specs'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/runtime.rb:101:in `block in definition_method'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/runtime.rb:20:in `setup'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler.rb:149:in `setup'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/setup.rb:20:in `block in <top (required)>'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/ui/shell.rb:136:in `with_level'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/ui/shell.rb:88:in `silence'
       	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/setup.rb:20:in `<top (required)>'
       	from /usr/local/bin/chef-cli:in `require'
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #converge action: [Expected process to exit with [0], but received '1'
---- Begin output of /usr/local/bin/chef-cli install /Users/rod/a/b/kitchen-issue/my_cookbook/Policyfile.rb --chef-license accept-no-persist ----
STDOUT:
STDERR: /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/spec_set.rb:86:in `block in materialize': Could not find racc-1.6.1 in any of the sources (Bundler::GemNotFound)
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/spec_set.rb:80:in `map!'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/spec_set.rb:80:in `materialize'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/definition.rb:170:in `specs'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/definition.rb:237:in `specs_for'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/definition.rb:226:in `requested_specs'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/runtime.rb:101:in `block in definition_method'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/runtime.rb:20:in `setup'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler.rb:149:in `setup'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/setup.rb:20:in `block in <top (required)>'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/ui/shell.rb:136:in `with_level'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/ui/shell.rb:88:in `silence'
	from /Users/rod/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/setup.rb:20:in `<top (required)>'
	from /usr/local/bin/chef-cli:in `require'
---- End output of /usr/local/bin/chef-cli install /Users/rod/a/b/kitchen-issue/my_cookbook/Policyfile.rb --chef-license accept-no-persist ----
Ran /usr/local/bin/chef-cli install /Users/rod/a/b/kitchen-issue/my_cookbook/Policyfile.rb --chef-license accept-no-persist returned 1] on default-centos-71
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

➕ Additional context

Output of kitchen-diagnose --all

---
timestamp: 2022-12-22 03:12:18 UTC
kitchen_version: 3.5.0
plugins:
  driver:
    Docker:
      class: Kitchen::Driver::Docker
      version:
      api_version:
  provisioner:
    ChefInfra:
      class: Kitchen::Provisioner::ChefInfra
      version: 3.5.0
      api_version: 2
  transport:
    Ssh:
      class: Kitchen::Transport::Ssh
      version: 3.5.0
      api_version: 1
  verifier:
    Busser:
      class: Kitchen::Verifier::Busser
      version: 3.5.0
      api_version: 1
loader:
  process_erb: true
  process_local: true
  process_global: true
  global_config:
  project_config:
    filename: "/Users/rod/a/b/kitchen-issue/my_cookbook/kitchen.yml"
    raw_data:
      driver:
        name: docker
        use_sudo: false
        privileged: true
      provisioner:
        name: chef_zero
        always_update_cookbooks: true
        deprecations_as_errors: false
        product_name: chef
        chef_license: accept-no-persist
        product_version: latest
      platforms:
      - name: centos-7.1
        driver_config:
          image: centos:7
          privileged: true
        attributes:
          network:
            datacenter: aws-us-east
      suites:
      - name: default
        verifier:
          inspec_tests:
          - test/integration/default
  local_config:
  combined_config:
    filename:
    raw_data:
      driver:
        name: docker
        use_sudo: false
        privileged: true
      provisioner:
        name: chef_zero
        always_update_cookbooks: true
        deprecations_as_errors: false
        product_name: chef
        chef_license: accept-no-persist
        product_version: latest
      platforms:
      - name: centos-7.1
        driver_config:
          image: centos:7
          privileged: true
        attributes:
          network:
            datacenter: aws-us-east
      suites:
      - name: default
        verifier:
          inspec_tests:
          - test/integration/default
instances:
  default-centos-71:
    platform:
      os_type: unix
      shell_type: bourne
    state_file:
      container_id: bef49a74a14b0b3769843659b90f3d2ecb0f02eefee78b4531a3c0641883b774
      hostname: localhost
      image_id: sha256:48cb068f9e34e19365e4a7d913c9f56a7a129f0a71b9a77606c7d10f984948e9
      last_action: create
      last_error: Kitchen::ShellOut::ShellCommandFailed
      port: 58583
      ssh_key: "/Users/rod/a/kitchen-issue/my_cookbook/.kitchen/docker_id_rsa"
      username: kitchen
    driver:
      binary: docker
      build_context: true
      build_options:
      cap_add:
      cap_drop:
      disable_upstart: true
      env_variables:
      image: centos:7
      instance_name: defaultcentos71-rod-rodrigosmacbookproloc-gd4uwcfk
      interactive: false
      isolation:
      kitchen_root: "/Users/rod/a/b/kitchen-issue/my_cookbook"
      log_level: :info
      name: docker
      platform: centos
      pre_create_command:
      private_key: "/Users/rod/a/b/kitchen-issue/my_cookbook/.kitchen/docker_id_rsa"
      privileged: true
      public_key: "/Users/rod/a/b/kitchen-issue/my_cookbook/.kitchen/docker_id_rsa.pub"
      publish_all: false
      remove_images: false
      run_command: "/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no -o PasswordAuthentication=yes
        -o UsePrivilegeSeparation=no -o PidFile=/tmp/sshd.pid"
      run_options:
      security_opt:
      socket: unix:///var/run/docker.sock
      test_base_path: "/Users/rod/a/b/kitchen-issue/my_cookbook/test/integration"
      tls: false
      tls_cacert:
      tls_cert:
      tls_key:
      tls_verify: false
      tty: false
      use_cache: true
      use_internal_docker_network: false
      use_sudo: false
      username: kitchen
      wait_for_transport: true
    provisioner:
      always_update_cookbooks: true
      architecture:
      attributes:
        network:
          datacenter: aws-us-east
      berksfile_path:
      channel: :stable
      checksum:
      chef_client_path: "/bin/chef-client"
      chef_license: accept-no-persist
      chef_omnibus_install_options:
      chef_omnibus_url: https://omnitruck.chef.io/install.sh
      chef_zero_host:
      chef_zero_port: 8889
      client_rb: {}
      clients_path:
      command_prefix:
      config_path:
      cookbook_files_glob: README.*,VERSION,metadata.{json,rb},attributes.rb,recipe.rb,attributes/**/*,definitions/**/*,files/**/*,libraries/**/*,providers/**/*,recipes/**/*,resources/**/*,templates/**/*,ohai/**/*,compliance/**/*
      data_bags_path:
      data_path:
      debug:
      deprecations_as_errors: false
      download_url:
      downloads: {}
      encrypted_data_bag_secret_key_path:
      enforce_idempotency: false
      environments_path:
      ftp_proxy:
      http_proxy:
      https_proxy:
      install_strategy: once
      json_attributes: true
      kitchen_root: "/Users/rod/a/b/kitchen-issue/my_cookbook"
      log_file:
      log_level: auto
      max_retries: 1
      multiple_converge: 1
      name: chef_infra
      named_run_list: {}
      nodes_path:
      platform:
      platform_version:
      policy_group:
      policyfile:
      policyfile_path:
      product_name: chef
      product_version: latest
      profile_ruby: false
      require_chef_omnibus: true
      retry_on_exit_code:
      - 35
      - 213
      roles_path:
      root_path: "/tmp/kitchen"
      ruby_bindir: "/embedded/bin"
      run_list: []
      sudo: true
      sudo_command: sudo -E
      test_base_path: "/Users/rod/a/b/kitchen-issue/my_cookbook/test/integration"
      uploads: {}
      wait_for_retry: 30
    transport:
      compression: false
      compression_level: 0
      connection_retries: 5
      connection_retry_sleep: 1
      connection_timeout: 15
      keepalive: true
      keepalive_interval: 60
      keepalive_maxcount: 3
      kitchen_root: "/Users/rod/a/b/kitchen-issue/my_cookbook"
      log_level: :info
      max_ssh_sessions: 9
      max_wait_until_ready: 600
      name: ssh
      port: 22
      ssh_gateway:
      ssh_gateway_port: 22
      ssh_gateway_username:
      ssh_http_proxy:
      ssh_http_proxy_password:
      ssh_http_proxy_port:
      ssh_http_proxy_user:
      ssh_key:
      test_base_path: "/Users/rod/a/b/kitchen-issue/my_cookbook/test/integration"
      username: root
    verifier:
      busser_bin: "/tmp/verifier/bin/busser"
      chef_omnibus_root: "/opt/chef"
      command_prefix:
      debug:
      ftp_proxy:
      http_proxy:
      https_proxy:
      inspec_tests:
      - test/integration/default
      kitchen_root: "/Users/rod/a/b/kitchen-issue/my_cookbook"
      log_level: :info
      name: busser
      root_path: "/tmp/verifier"
      ruby_bindir: "/opt/chef/embedded/bin"
      sudo: true
      sudo_command: sudo -E
      suite_name: default
      test_base_path: "/Users/rod/a/b/kitchen-issue/my_cookbook/test/integration"
      version: busser
    lifecycle_hooks:
      debug:
      kitchen_root: "/Users/rod/a/b/kitchen-issue/my_cookbook"
      log_level: :info
      test_base_path: "/Users/rod/a/b/kitchen-issue/my_cookbook/test/integration"

Hack

From the bundle file, edit lib/kitchen/shell_out.rb

after

debug("#{subject} BEGIN (#{cmd})")

add

ENV.delete('RUBYOPT')

and now it works fine

@heliumlove
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants