From 65ff8b432cad501d7ccd6809565004836bc79e5d Mon Sep 17 00:00:00 2001 From: Andrii Date: Mon, 9 Dec 2024 14:40:41 +0200 Subject: [PATCH] add rvm --- ansible1/playbook-develop-ubuntu.yml | 2 +- ansible1/roles/packages/tasks/main.yml | 99 ++++++++++++------- ansible1/roles/packages/tasks/rubies.yml | 65 ++++++++++++ ansible1/roles/packages/tasks/rvm.yml | 58 +++++++++++ .../roles/packages/tasks/setup-Debian.yml | 10 +- ansible1/roles/packages/vars/main.yml | 52 ++++++++++ ansible1/roles/postgresql/tasks/main.yml | 2 +- 7 files changed, 247 insertions(+), 41 deletions(-) create mode 100644 ansible1/roles/packages/tasks/rubies.yml create mode 100644 ansible1/roles/packages/tasks/rvm.yml diff --git a/ansible1/playbook-develop-ubuntu.yml b/ansible1/playbook-develop-ubuntu.yml index bbd4a7897..5fe99a116 100644 --- a/ansible1/playbook-develop-ubuntu.yml +++ b/ansible1/playbook-develop-ubuntu.yml @@ -5,6 +5,6 @@ become_method: sudo become_user: root roles: - # - packages + - packages - postgresql - redis diff --git a/ansible1/roles/packages/tasks/main.yml b/ansible1/roles/packages/tasks/main.yml index 511868aee..5250c4db3 100644 --- a/ansible1/roles/packages/tasks/main.yml +++ b/ansible1/roles/packages/tasks/main.yml @@ -1,4 +1,36 @@ --- +- name: Update apt cache. + apt: + update_cache: true + cache_valid_time: 86400 + +- name: Install system dependencies + run: sudo apt-get install -y libvips42 libvips-dev imagemagick + +- name: Define ruby_build_packages + set_fact: + ruby_build_packages: "{{ __ruby_build_packages }}" + when: ruby_build_packages is not defined + +- name: Update apt cache (Debian) + apt: update_cache=true cache_valid_time=86400 + when: ansible_os_family == 'Debian' + +- name: Get the username + become: false + local_action: command whoami + register: username_on_the_host + +- name: Install Ruby and Gems + import_tasks: "rvm.yml" + become: yes + become_user: "{{ username_on_the_host.stdout }}" + +- name: Install RVM + import_tasks: "rubies.yml" + become: yes + become_user: "{{ username_on_the_host.stdout }}" + - name: Add Yarn GPG key apt_key: url: https://dl.yarnpkg.com/debian/pubkey.gpg @@ -13,44 +45,43 @@ when: ruby_packages is not defined # Install ruby from source when ruby_install_from_source is true. -- include_tasks: install-from-source.yml - when: ruby_install_from_source +# - include_tasks: install-from-source.yml +# when: ruby_install_from_source - name: Add user installed RubyGems bin directory to global $PATH copy: src: rubygems.sh dest: /etc/profile.d/rubygems.sh mode: 644 - # Install Bundler and configured gems -- name: Install Bundler - gem: - name: bundler - state: present - user_install: false - when: ruby_install_bundler - -- name: Install configured gems - gem: - name: "{{ item.name | default(item) }}" - version: "{{ item.version | default(omit) }}" - user_install: false - state: present - become: true - become_user: "{{ ruby_install_gems_user }}" - with_items: "{{ ruby_install_gems }}" - -- name: Install development gems - gem: - name: "{{ item.name }}" - version: "{{ item.version | default(omit) }}" - user_install: false - with_items: - - { name: "pry-rails" } - - { name: "letter_opener" } - - { name: "web-console", version: ">= 4.1.0" } - when: ruby_install_gems_development - -- name: Install all nessessary dependencies via bundle - shell: | - sudo bundle install +# - name: Install Bundler +# gem: +# name: bundler +# state: present +# user_install: false +# when: ruby_install_bundler + +# - name: Install configured gems +# gem: +# name: "{{ item.name | default(item) }}" +# version: "{{ item.version | default(omit) }}" +# user_install: false +# state: present +# become: true +# become_user: "{{ ruby_install_gems_user }}" +# with_items: "{{ ruby_install_gems }}" + +# - name: Install development gems +# gem: +# name: "{{ item.name }}" +# version: "{{ item.version | default(omit) }}" +# user_install: false +# with_items: +# - { name: "pry-rails" } +# - { name: "letter_opener" } +# - { name: "web-console", version: ">= 4.1.0" } +# when: ruby_install_gems_development + +# - name: Install all nessessary dependencies via bundle +# shell: | +# sudo bundle install diff --git a/ansible1/roles/packages/tasks/rubies.yml b/ansible1/roles/packages/tasks/rubies.yml new file mode 100644 index 000000000..6788493f1 --- /dev/null +++ b/ansible1/roles/packages/tasks/rubies.yml @@ -0,0 +1,65 @@ +--- + +- name: Detect rubies + command: '{{ rvm1_rvm }}' + register: rvm_list_strings + changed_when: False + +- name: Install rubies + command: '{{ rvm1_rvm }} install {{ item }} {{ rvm1_ruby_install_flags }}' + loop: '{{ rvm1_rubies | difference(rvm_list_strings.stdout_lines) }}' + +- name: Detect default ruby version + command: '{{ rvm1_rvm }} alias list default' + changed_when: False + register: detect_default_ruby_version + +- name: Select default ruby + command: '{{ rvm1_rvm }} alias create default {{ rvm1_default_ruby_version }}' + when: detect_default_ruby_version.stdout|default() == '' or + rvm1_default_ruby_version not in detect_default_ruby_version.stdout + +- name: Detect installed ruby patch number + shell: > + {{ rvm1_rvm }} list strings | grep {{ item }} | tail -n -1 + with_items: '{{ rvm1_rubies }}' + changed_when: False + register: ruby_patch + check_mode: no + +- name: Install bundler if not installed + shell: > + ls {{ rvm1_install_path }}/wrappers/{{ item.stdout }} + | if !grep "^bundler" ; then {{ rvm1_install_path }}/wrappers/{{ item.stdout }}/gem install bundler ; fi + args: + creates: '{{ rvm1_install_path }}/wrappers/{{ item.stdout }}/bundler' + with_items: '{{ ruby_patch.results }}' + when: rvm1_bundler_install + register: bundler_install + changed_when: '"Successfuly installed bundler" in bundler_install.stdout' + +- name: Symlink ruby related binaries on the system path + file: + state: 'link' + src: '{{ rvm1_install_path }}/wrappers/default/{{ item }}' + dest: '{{ rvm1_symlink_to }}/{{ item }}' + owner: '{{ root_user }}' + group: '{{ root_group }}' + when: not '--user-install' in rvm1_install_flags and rvm1_symlink + with_items: '{{ rvm1_symlink_binaries }}' + +- name: Symlink bundler binaries on the system path + file: + state: 'link' + src: '{{ rvm1_install_path }}/wrappers/default/{{ item }}' + dest: '{{ rvm1_symlink_to }}/{{ item }}' + owner: '{{ root_user }}' + group: '{{ root_group }}' + when: not '--user-install' in rvm1_install_flags and rvm1_bundler_install and rvm1_symlink + with_items: '{{ rvm1_symlink_bundler_binaries }}' + +- name: Delete ruby if relevant + command: '{{ rvm1_rvm }} remove {{ rvm1_delete_ruby: }}' + register: rvm_delete_command + changed_when: "'#removing' in rvm_delete_command.stdout" + when: rvm1_delete_ruby is defined and rvm1_delete_ruby \ No newline at end of file diff --git a/ansible1/roles/packages/tasks/rvm.yml b/ansible1/roles/packages/tasks/rvm.yml new file mode 100644 index 000000000..1cd226258 --- /dev/null +++ b/ansible1/roles/packages/tasks/rvm.yml @@ -0,0 +1,58 @@ +--- + +- name: Detect rvm binary + stat: path='{{ rvm1_rvm }}' + register: rvm_binary + +- name: Detect rvm installer + stat: path='{{ rvm1_temp_download_path }}/rvm-installer.sh' + register: rvm_installer + +- name: Detect current rvm version + command: '{{ rvm1_rvm }} version' + changed_when: False + register: rvm_current_version + when: rvm_binary.stat.exists + +- name: Install rvm installer + get_url: + url: '{{ rvm1_rvm_latest_installer }}' + dest: '{{ rvm1_temp_download_path }}/rvm-installer.sh' + mode: 0755 + when: not rvm_installer.stat.exists + +- name: Import GPG keys from keyservers + shell: 'gpg --batch --keyserver {{ item }} --recv-keys {{ rvm1_gpg_keys }}' + changed_when: False + check_mode: False + with_items: '{{ rvm1_gpg_key_servers }}' + register: gpg_import + when: not ansible_check_mode and rvm1_gpg_keys != '' and (gpg_import is not defined or gpg_import.rc != 0) + ignore_errors: True + +- name: Was GPG import from keyservers succesfull? + set_fact: gpg_imported_from={{ item.item }} + when: "'rc' in item and item.rc == 0" + with_items: "{{ gpg_import.results }}" + +- name: Import GPG keys from rvm.io, if keyservers failed + shell: 'curl -sSL https://rvm.io/{{ item }} | gpg --batch --import -' + with_items: + - mpapis.asc + - pkuczynski.asc + when: not ansible_check_mode and rvm1_gpg_keys != '' and gpg_imported_from is not defined + +- name: Install rvm + shell: > + /usr/bin/env bash {{ rvm1_temp_download_path }}/rvm-installer.sh {{ rvm1_rvm_version }} + --path {{ rvm1_install_path }} {{ rvm1_install_flags }} + when: not rvm_binary.stat.exists + +- name: Update rvm + shell: '{{ rvm1_rvm }} get {{ rvm1_rvm_version }} && {{ rvm1_rvm }} reload' + changed_when: False + when: rvm_binary.stat.exists and rvm1_rvm_check_for_updates + +- name: Configure rvm + command: '{{ rvm1_rvm }} autolibs {{ rvm1_autolib_mode }}' + when: not rvm_binary.stat.exists \ No newline at end of file diff --git a/ansible1/roles/packages/tasks/setup-Debian.yml b/ansible1/roles/packages/tasks/setup-Debian.yml index dca2ae764..4da78cff5 100644 --- a/ansible1/roles/packages/tasks/setup-Debian.yml +++ b/ansible1/roles/packages/tasks/setup-Debian.yml @@ -1,10 +1,10 @@ --- -- name: Update apt cache. - apt: - update_cache: true - cache_valid_time: 86400 +# - name: Update apt cache. +# apt: +# update_cache: true +# cache_valid_time: 86400 -- name: Set rubygems package name for Ubuntu 14.04. +- name: Set rubygems package name for Ubuntu set_fact: ruby_rubygems_package_name: rubygems-integration when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'trusty' diff --git a/ansible1/roles/packages/vars/main.yml b/ansible1/roles/packages/vars/main.yml index fdb66ab86..201b3c863 100644 --- a/ansible1/roles/packages/vars/main.yml +++ b/ansible1/roles/packages/vars/main.yml @@ -29,6 +29,23 @@ __ruby_build_packages: - libffi-dev - libgdbm-dev - libpq-dev +rvm_dependencies: + - curl + - gnupg + - build-essential + - libssl-dev + - libyaml-dev + - libreadline-dev + - zlib1g-dev + - libsqlite3-dev + - sqlite3 + - libxml2-dev + - libxslt1-dev + - libcurl4-openssl-dev + - software-properties-common + - libffi-dev + - nodejs + - yarn ruby_rubygems_package_name: rubygems ruby_download_url: https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.5.tar.xz workspace: /root @@ -92,3 +109,38 @@ ruby_install_gems: version: "~> 6.4" - name: "factory_bot_rails" version: null +############ +rvm1_install_path: "~/.rvm" +rvm1_rvm: "{{ rvm1_install_path }}/bin/rvm" +rvm1_temp_download_path: "/tmp" +rvm1_rvm_latest_installer: "https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer" +rvm1_gpg_keys: "409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB" +rvm1_gpg_key_servers: + - "{{ rvm1_gpg_key_server }}" + - hkp://pgp.mit.edu + - hkp://keyserver.pgp.com + - hkp://keyserver.ubuntu.com +rvm1_rvm_version: "stable" +rvm1_install_flags: "--auto-dotfiles --user-install" +rvm1_autolib_mode: 3 +rvm1_ruby_install_flags: +rvm1_rubies: + - "ruby-3.3.5" +rvm1_default_ruby_version: "{{ rvm1_rubies | last if rvm1_rubies and rvm1_rubies is iterable else rvm1_rubies }}" +rvm1_bundler_install: True +rvm1_symlink_to: "/usr/local/bin" +root_user: "root" +root_group: "{{ root_user }}" +rvm1_symlink_binaries: + - "erb" + - "executable-hooks-uninstaller" + - "gem" + - "irb" + - "rake" + - "rdoc" + - "ri" + - "ruby" +rvm1_symlink_bundler_binaries: + - "bundle" + - "bundler" +rvm1_delete_ruby: diff --git a/ansible1/roles/postgresql/tasks/main.yml b/ansible1/roles/postgresql/tasks/main.yml index d73587a04..6ff830fe8 100644 --- a/ansible1/roles/postgresql/tasks/main.yml +++ b/ansible1/roles/postgresql/tasks/main.yml @@ -203,7 +203,7 @@ src: config/database.yml.docker dest: config/database.yml -- name: get the username running the deploy +- name: Get the username become: false local_action: command whoami register: username_on_the_host