Upgrade ruby from 2.7.4 - 3.3.5 using Ansible

Hi all, im new to ansible and Ruby but Ive been tasked with creating a new AWS AMI using Packer and Ansible.

I have updated the following application.yml from version 2.7.4 to 3.3.5 and the build fails.

Heres the relevant part of the applications.yml file that ive updated:

rbenv:
env: user
version: v1.3.0
default_ruby: 3.3.5
rubies:
- version: 3.3.5
rbenv_users:

  • ‘{{ user }}’

and heres the config in main.yml


  • name: xxx-xxx-application
    hosts: all
    gather_facts: true
    become: true
    tasks:

    • name: Install a list of packages
      ansible.builtin.apt:
      pkg:

      • build-essential
      • libssl-dev
      • zlib1g-dev
      • libreadline-dev
      • libyaml-dev
      • libxml2-dev
      • libxslt1-dev
      • libffi-dev
    • name: Install libyaml-dev
      ansible.builtin.apt:
      name: libyaml-dev
      state: present

    roles:

    • role: common
    • role: acl
    • role: user
    • role: ssh-security
    • role: zzet.rbenv
      tags: [rbenv]
    • role: nginxinc.nginx_core.nginx
      tags: [nginx]
    • role: nginxinc.nginx_core.nginx_config
      tags: [nginx]
    • role: brotli
      tags: [brotli]
    • role: rails
      tags: [rails]
    • role: puma
      tags: [puma]
    • role: delayed_job
      tags: [delayed_job]
    • role: nickhammond.logrotate
      tags: [logs]
    • role: geerlingguy.nodejs
      nodejs_install_npm_user: deploy
      tags: [node]
    • role: fonts
    • role: ntp

The command I run to trigger the build is:
AWS_PROFILE=staging packer build -var “env=staging” -var “terraform-env=stage” packer-application

This results in the following error that seems to be related to zzet.rbenv having issues with ‘psych’ package which I cannot resolve. I cannot log into the instance to check the logfile that is mentioned in the error message. I am running this command from my M1 macbook pro

TASK [zzet.rbenv : install specified ruby versions for select users] ***********

failed: [default] (item=Install 3.3.5 for deploy) => {“ansible_loop_var”: “item”, “changed”: true, “cmd”: “$0 -lc "~/.rbenv/bin/rbenv install --skip-existing 3.3.5"”, “delta”: “0:54:15.124169”, “end”: “2024-11-26 19:35:25.609907”, “item”: [“deploy”, {“version”: “3.3.5”}], “msg”: “non-zero return code”, “rc”: 1, “start”: “2024-11-26 18:41:10.485738”, “stderr”: " % Total % Received % Xferd Average Speed Time Time Time Current\n Dload Upload Total Spent Left Speed\n\r 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0\r 43 21.1M 43 9386k 0 0 28.7M 0 --:–:-- --:–:-- --:–:-- 28.6M\r100 21.1M 100 21.1M 0 0 34.0M 0 --:–:-- --:–:-- --:–:-- 33.9M\n*** Following extensions are not compiled:\npsych:\n\tCould not be configured. It will not be installed.\n\tCheck /tmp/ruby-build.20241126184111.18009.DRx5Qy/ruby-3.3.5/ext/psych/mkmf.log for more details.\n\nBUILD FAILED (Ubuntu 20.04 on x86_64 using ruby-build 20241105-9-g7ccb143c)\n\nYou can inspect the build directory at /tmp/ruby-build.20241126184111.18009.DRx5Qy\nSee the full build log at /tmp/ruby-build.20241126184111.18009.log", “stderr_lines”: [" % Total % Received % Xferd Average Speed Time Time Time Current", " Dload Upload Total Spent Left Speed", “”, " 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0", " 43 21.1M 43 9386k 0 0 28.7M 0 --:–:-- --:–:-- --:–:-- 28.6M", “100 21.1M 100 21.1M 0 0 34.0M 0 --:–:-- --:–:-- --:–:-- 33.9M”, “*** Following extensions are not compiled:”, “psych:”, “\tCould not be configured. It will not be installed.”, “\tCheck /tmp/ruby-build.20241126184111.18009.DRx5Qy/ruby-3.3.5/ext/psych/mkmf.log for more details.”, “”, “BUILD FAILED (Ubuntu 20.04 on x86_64 using ruby-build 20241105-9-g7ccb143c)”, “”, “You can inspect the build directory at /tmp/ruby-build.20241126184111.18009.DRx5Qy”, “See the full build log at /tmp/ruby-build.20241126184111.18009.log”], “stdout”: “==> Downloading ruby-3.3.5.tar.gz…\n → curl -q -fL -o ruby-3.3.5.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.5.tar.gz\n==> Installing ruby-3.3.5…\n → ./configure "–prefix=$HOME/.rbenv/versions/3.3.5" --enable-shared --with-ext=openssl,psych,+\n → make -j 2”, “stdout_lines”: [“==> Downloading ruby-3.3.5.tar.gz…”, “-> curl -q -fL -o ruby-3.3.5.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.5.tar.gz”, “==> Installing ruby-3.3.5…”, “-> ./configure "–prefix=$HOME/.rbenv/versions/3.3.5" --enable-shared --with-ext=openssl,psych,+”, “-> make -j 2”]}

would appreciate if someone could point me in the right direction on how to fix this as ive added the “libyaml-dev” package that is a pre-req for the “psych” package but it makes no difference.

Many thanks in advance