From 8aed97e6ac3b17b127c14ecb56f31cc9d1b44b94 Mon Sep 17 00:00:00 2001 From: Mahdi Ardekanian Date: Wed, 21 Feb 2024 17:30:05 -0500 Subject: [PATCH] unixPB: macos ansible setup improvement This PR is amed to add Xcode_offline which installs xcode without need to use any other 3rd party resource. Also some minor code changes and improvement added (e.g. install brew) --- .../macos-setup.yml | 54 ++++++ .../roles/Ant-Contrib/tasks/main.yml | 171 +++++++++-------- .../Jenkins_User/files/authorized_key.pub | 1 + .../roles/Jenkins_User/tasks/main.yml | 67 +++++-- .../roles/Semeru_install/tasks/main.yml | 8 + .../Semeru_install/tasks/semeru-install.yml | 173 ++++++++++++++++++ .../files/offline_xcode_files_here | 0 .../roles/Xcode_offline/tasks/main.yml | 14 ++ .../Xcode_offline/tasks/xcode_offline.yml | 51 ++++++ .../roles/ant/tasks/main.yml | 125 ++++++------- .../roles/brew/tasks/main.yml | 81 ++++++++ 11 files changed, 595 insertions(+), 150 deletions(-) create mode 100644 ansible/playbooks/AdoptOpenJDK_Unix_Playbook/macos-setup.yml create mode 100644 ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Jenkins_User/files/authorized_key.pub create mode 100644 ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Semeru_install/tasks/main.yml create mode 100644 ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Semeru_install/tasks/semeru-install.yml create mode 100644 ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/files/offline_xcode_files_here create mode 100644 ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/tasks/main.yml create mode 100644 ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/tasks/xcode_offline.yml create mode 100644 ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/brew/tasks/main.yml diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/macos-setup.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/macos-setup.yml new file mode 100644 index 0000000000..53bc994d45 --- /dev/null +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/macos-setup.yml @@ -0,0 +1,54 @@ +--- + +- name: Ansible MacOS playbook + hosts: "all" + gather_facts: yes + become_method: sudo + vars: + ansible_python_interpreter: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 + Ant_Download_URL: https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.12-bin.zip + known_keys: + - {name: "github.com", value: "github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl"} + xcode_version: '15.0.1' + ansible_user: adminuser + jdk_version: 17 + + + ######### + # Roles # + ######### + roles: + - role: brew + tags: [build_tools, xcode, adoptopenjdk] + - role: Xcode_offline + tags: [build_tools, xcode, adoptopenjdk] + - role: Common + tags: [build_tools, build_tools_openj9] + - role: Jenkins_User + tags: [build_tools, build_tools_openj9, jenkins] + - role: Semeru_install + tags: [build_tools, build_tools_openj9, semeru] + - role: ant + tags: [build_tools, build_tools_openj9] + - role: Ant-Contrib + tags: [build_tools, build_tools_openj9] + +# Macos do not let any Ansible activity before you install python manually. So you need to do a workaround before running this PB. +# 1- download python from https://www.python.org/ftp/python/3.11.4/python-3.11.4-macos11.pkg +# 2- scp downloaded file to macos (example: scp ~/Downloads/python-3.11.4-macos11.pkg adminuser@macXXXXXX.rtp.raleigh.ibm.com:~/) +# 3- ssh to mac machine and run this to install python: +# sudo installer -pkg ~/python-3.11.4-macos11.pkg -target /Applications && /Applications/Python\ 3.11/Install\ Certificates.command && /Applications/Python\ 3.11/Update\ Shell\ Profile.command +# +# 4- then you can start using the PB as normal like other machine types: +# example: ansible-playbook -i hosts.yml macos-setup.yml -Kk +# +# sample host.yml file: + +# all: +# children: +# hosts: +# macXXXXXX.yourdomain.com: + + + + diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Ant-Contrib/tasks/main.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Ant-Contrib/tasks/main.yml index e1b62df104..df1a5d5cac 100644 --- a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Ant-Contrib/tasks/main.yml +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Ant-Contrib/tasks/main.yml @@ -1,21 +1,21 @@ --- -############### -# Ant-Contrib # -############### + # ANT_HOME/lib is: /usr/local/apache-ant-*/lib +# Use the following variables: +# antContribVersion: default('1.0b2') +- name: set ant binary file name to variable + set_fact: + ant_binary_file_name: "{{ Ant_Download_URL.split('/')[-1].split('-bin')[0] }}" + tags: ant-contrib - name: Set ant-contrib version - set_fact: antContribVersion=1.0b2 + set_fact: antContribVersion={{ antContribVersion | default('1.0b2') }} tags: ant-contrib - name: Set ant_lib_dir variable for on {{ ansible_distribution }} {{ ansible_architecture }} set_fact: - ant_lib_dir: /usr/local/apache-ant-1.10.5/lib - tags: ant-contrib - -- name: "Print ant_lib_dir variable" - debug: var=ant_lib_dir + ant_lib_dir: /usr/local/{{ ant_binary_file_name }}/lib tags: ant-contrib - name: Check if ant-contrib is already installed @@ -25,79 +25,96 @@ tags: ant-contrib - name: Download ant-contrib - get_url: - url: https://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-{{ antContribVersion }}/ant-contrib-{{ antContribVersion }}-bin.tar.gz - dest: /tmp/ - mode: 0440 - timeout: 25 - validate_certs: no - checksum: sha256:c9b8b1ca18b13e293688cafbd8990c940ca49104dbeefc242e5c3f8de271abdf - retries: 3 - delay: 5 - register: antContrib_download - until: antContrib_download is not failed - when: - - not antcontrib_status.stat.exists - - ansible_distribution != "MacOSX" - - ansible_distribution != "Solaris" - - not (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6") - tags: ant-contrib + block: -# Use wget instead of ansible's get_url for Centos 6 https://github.com/adoptium/infrastructure/issues/2486 + - name: Download ant-contrib + get_url: + url: https://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-{{ antContribVersion }}/ant-contrib-{{ antContribVersion }}-bin.tar.gz + dest: /tmp/ + mode: 0440 + timeout: 25 + validate_certs: no + checksum: sha256:c9b8b1ca18b13e293688cafbd8990c940ca49104dbeefc242e5c3f8de271abdf + retries: 3 + delay: 5 + register: antContrib_download + until: antContrib_download is not failed + when: + - ansible_distribution != "MacOSX" + - ansible_distribution != "Solaris" + - not (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6") -- name: Download ant-contrib (CentOS 6) - command: wget https://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-{{ antContribVersion }}/ant-contrib-{{ antContribVersion }}-bin.tar.gz -O /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz - retries: 3 - delay: 5 - register: antContrib_download - until: antContrib_download is not failed - when: - - not antcontrib_status.stat.exists - - ansible_distribution == "CentOS" and ansible_distribution_major_version == "6" - tags: ant-contrib + # Use wget instead of ansible's get_url for Centos 6 https://github.com/adoptium/infrastructure/issues/2486 -- name: Verify sha256 checksum of download (CentOS 6) - stat: - path: /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz - checksum_algorithm: sha256 - get_checksum: yes - register: antcontrib_checksum - failed_when: antcontrib_checksum.stat.checksum != 'c9b8b1ca18b13e293688cafbd8990c940ca49104dbeefc242e5c3f8de271abdf' - when: - - not antcontrib_status.stat.exists - - ansible_distribution == "CentOS" and ansible_distribution_major_version == "6" - tags: ant-contrib + - name: Download ant-contrib (CentOS 6) + command: wget https://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-{{ antContribVersion }}/ant-contrib-{{ antContribVersion }}-bin.tar.gz -O /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz + retries: 3 + delay: 5 + register: antContrib_download + until: antContrib_download is not failed + when: + - ansible_distribution == "CentOS" and ansible_distribution_major_version == "6" -- name: Download ant-contrib (macOS) and (Solaris) - command: wget https://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-{{ antContribVersion }}/ant-contrib-{{ antContribVersion }}-bin.tar.gz -O /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz - retries: 3 - delay: 5 - register: antContrib_download - until: antContrib_download is not failed - when: - - not antcontrib_status.stat.exists - - ansible_distribution == "MacOSX" or ansible_distribution == "Solaris" - tags: ant-contrib + - name: Verify sha256 checksum of download (CentOS 6) + stat: + path: /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz + checksum_algorithm: sha256 + get_checksum: yes + register: antcontrib_checksum + failed_when: antcontrib_checksum.stat.checksum != 'c9b8b1ca18b13e293688cafbd8990c940ca49104dbeefc242e5c3f8de271abdf' + when: + - ansible_distribution == "CentOS" and ansible_distribution_major_version == "6" -- name: Extract ant-contrib - unarchive: - src: /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz - dest: /tmp/ - copy: False - when: not antcontrib_status.stat.exists - tags: ant-contrib + - name: Download ant-contrib (macOS) and (Solaris) + get_url: + url: "https://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-{{ antContribVersion }}/ant-contrib-{{ antContribVersion }}-bin.tar.gz" + dest: "/tmp" + retries: 3 + delay: 5 + register: antContrib_download + until: antContrib_download is not failed + when: + - ansible_distribution == "MacOSX" or ansible_distribution == "Solaris" -- name: Move ant-contrib.jar to ant lib folder - command: mv /tmp/ant-contrib/lib/ant-contrib.jar {{ ant_lib_dir }} - when: not antcontrib_status.stat.exists - tags: ant-contrib + - name: Creates directory {{ ant_lib_dir }} + file: + path: "{{ ant_lib_dir }}" + state: directory + become: true + + - name: Extract ant-contrib + unarchive: + src: /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz + dest: /tmp + copy: False + when: + - ansible_distribution != "MacOSX" + + - name: Extract ant-contrib tar -xf /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz -C /tmp + command: tar -xf /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz -C /tmp + register: antcontrib_unpack + become: true + until: antcontrib_unpack is not failed + when: + - ansible_distribution == "MacOSX" -- name: Remove downloaded packages for ant-contrib - file: - path: "{{ item }}" - state: absent - with_items: - - /tmp/ant-contrib - - /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz - failed_when: false + - name: copy ant-contrib /tmp/ant-contrib/lib/ant-contrib.jar into /usr/local/{{ ant_binary_file_name }}/lib + copy: + src: /tmp/ant-contrib/lib/ant-contrib.jar + dest: "/usr/local/{{ant_binary_file_name }}/lib/" + remote_src: true + become: true + + - name: Cleanup after ant-contrib installed + file: + path: "{{ item }}" + state: absent + with_items: + - /tmp/ant-contrib/ + - /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz + failed_when: false + become: true + tags: ant-contrib + when: + - not antcontrib_status.stat.exists diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Jenkins_User/files/authorized_key.pub b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Jenkins_User/files/authorized_key.pub new file mode 100644 index 0000000000..cfd16663a7 --- /dev/null +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Jenkins_User/files/authorized_key.pub @@ -0,0 +1 @@ +#authorized key(s) here: \ No newline at end of file diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Jenkins_User/tasks/main.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Jenkins_User/tasks/main.yml index 7532741c61..0d9812c32b 100644 --- a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Jenkins_User/tasks/main.yml +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Jenkins_User/tasks/main.yml @@ -39,6 +39,7 @@ action: user name={{ Jenkins_Username }} group=staff state=present home={{ home_folder }} shell=/bin/bash when: ansible_distribution == "MacOSX" tags: [jenkins_user, adoptopenjdk] + become: true - name: Enable SSH login for Jenkins user (macOS) command: dseditgroup -o edit -a {{ Jenkins_Username }} -t staff com.apple.access_ssh @@ -78,23 +79,20 @@ authorized_key: user: "{{ Jenkins_Username }}" state: present - key: "{{ Jenkins_User_SSHKey }}" + key: "{{ lookup('file', 'authorized_key.pub') }}" tags: [jenkins_user, jenkins_authorized_key, adoptopenjdk] + become: true -- name: Add github.com to known_hosts +- name: Add needed items to "{{ home_folder }}/.ssh/known_hosts" known_hosts: - name: github.com - key: github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== + name: "{{ item.name }}" + key: "{{ item.value }}" path: "{{ home_folder }}/.ssh/known_hosts" state: present + with_items: "{{known_keys}}" tags: [jenkins_user, adoptopenjdk] - -- name: Change ownership of jenkins' ~/.ssh/known_hosts - file: - path: "{{ home_folder }}/.ssh/known_hosts" - owner: "{{ Jenkins_Username }}" - mode: 0644 - tags: [jenkins_user, adoptopenjdk] + become: true + become_user: '{{ Jenkins_Username }}' - name: Add Jenkins user to the audio group user: name={{ Jenkins_Username }} @@ -104,6 +102,7 @@ - (ansible_distribution == "Ubuntu" or ansible_distribution == "SLES") - ansible_architecture != "armv7l" tags: [jenkins_user, adoptopenjdk] + become: true - name: Unset expiry on user account for Redhat for Jenkins user command: chage -M -1 -E -1 {{ Jenkins_Username }} @@ -138,3 +137,49 @@ - ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7" tags: - jenkins_user + +#additional settings for user jenkins +- name: check if bin paths are exist before add them to {{ home_folder }}/.bashrc + stat: path={{item}} + with_items: + - /opt/homebrew/bin/ + - /usr/local/bin/ + register: mac_bin_paths + tags: + - jenkins_user + +- name: configure {{ home_folder }}/.bashrc + copy: + dest: "{{ home_folder }}/.bashrc" + content: "export PATH={{ mac_bin_paths | join(':') }}:{{ lookup('ansible.builtin.env', 'PATH') }}" + owner: "{{ Jenkins_Username }}" + mode: 0700 + become: true + tags: + - jenkins_user + +- name: create folder "{{ home_folder }}/openjdk_cache" + file: + path: "{{ home_folder }}/openjdk_cache" + state: directory + owner: "{{ Jenkins_Username }}" + mode: 0755 + become: true + tags: + - jenkins_user + +- name: fetch required JDK repo into {{ home_folder }}/openjdk_cache + shell: + cmd: | + git init --bare + git remote -v | grep jdk8 || git remote add jdk8 https://github.com/ibmruntimes/openj9-openjdk-jdk8.git + git remote -v | grep jdk11 || git remote add jdk11 https://github.com/ibmruntimes/openj9-openjdk-jdk11.git + git remote -v | grep jdk || git remote add jdk https://github.com/ibmruntimes/openj9-openjdk-jdk.git + git remote -v | grep openj9 || git remote add openj9 https://github.com/eclipse-openj9/openj9.git + git remote -v | grep omr || git remote add omr https://github.com/eclipse-openj9/openj9-omr.git + git fetch --all + chdir: "{{ home_folder }}/openjdk_cache" + become: true + become_user: "{{ Jenkins_Username }}" + tags: + - jenkins_user diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Semeru_install/tasks/main.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Semeru_install/tasks/main.yml new file mode 100644 index 0000000000..4010c8cc2a --- /dev/null +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Semeru_install/tasks/main.yml @@ -0,0 +1,8 @@ +--- +##################### +# install Semeru OE # +##################### + +- name: install Semeru OE + include_tasks: semeru-install.yml + tags: semeru_install diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Semeru_install/tasks/semeru-install.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Semeru_install/tasks/semeru-install.yml new file mode 100644 index 0000000000..aee65cc188 --- /dev/null +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Semeru_install/tasks/semeru-install.yml @@ -0,0 +1,173 @@ +--- +##################### +# install Semeru OE # +##################### + +# Install Semeru Open Edition into +# /usr/lib/jvm on Linux +# /Library/Java/JavaVirtualMachines on MacOSX +# Requires the following variables: +# jdk_version: 11 | 17 | 18 | 19 + +# Note: set "ansible_become_password: " in the AWX job for MacOSX + +- name: Set path variable for RedHat/CentOS/Ubuntu + set_fact: + install_path: "/usr/lib/jvm" + when: + - ansible_distribution != "MacOSX" + - ansible_distribution != "SLES" + tags: semeru_install + +- name: Set path variable for SLES + set_fact: + install_path: "/usr/lib64/jvm" + when: + - ansible_distribution == "SLES" + tags: semeru_install + +- name: Set path variable for MacOS + set_fact: + install_path: "/Library/Java/JavaVirtualMachines" + when: ansible_distribution == "MacOSX" + tags: semeru_install + +- name: Set api_architecture variable + set_fact: + api_architecture: "{{ ansible_architecture }}" + tags: semeru_install + +- name: Set api_architecture variable (Linux x86_64) + set_fact: + api_architecture: x64 + when: + - ansible_architecture == "x86_64" + tags: semeru_install + +- name: Set api_architecture variable (MacOS Arm64) + set_fact: + api_architecture: aarch64 + when: + - ansible_os_family == "Darwin" + - ansible_architecture == "arm64" + tags: semeru_install + +- name: Print api_architecture variable + debug: + var: api_architecture + tags: semeru_install + +- name: Checking for {{ install_path }} + stat: path={{ install_path }} + register: install_path_exists + tags: semeru_install + +- name: Create {{ install_path }} + file: + path: '{{ install_path }}' + state: directory + owner: root + mode: 0755 + when: + - ansible_distribution != "MacOSX" + - not install_path_exists.stat.exists + tags: semeru_install + +######### +# Linux # +######### + +- name: Install Semeru {{ jdk_version }} OE latest release (Linux) + unarchive: + src: https://api.adoptopenjdk.net/v3/installer/latest/{{ jdk_version }}/ga/linux/{{ api_architecture }}/jdk/openj9/normal/ibm?project=jdk + dest: '{{ install_path }}' + remote_src: yes + validate_certs: no + retries: 3 + delay: 5 + register: semeru_download + until: semeru_download is not failed + when: ansible_distribution != "MacOSX" + tags: semeru_install + +- name: Get {{ install_path }}/jdk-{{ jdk_version }}* full path name (Linux) + shell: ls -ld {{ install_path }}/jdk-{{ jdk_version }}.* 2>/dev/null | awk '{print $9}' + register: semeru_install_dir + when: ansible_distribution != "MacOSX" + tags: semeru_install + +- name: Create symlink to Semeru {{ jdk_version }} install directory (Linux) + file: + src: '{{ semeru_install_dir.stdout_lines[0] }}' + dest: '{{ install_path }}/semeru-{{ jdk_version }}' + owner: root + group: root + state: link + when: ansible_distribution != "MacOSX" + tags: semeru_install + +- name: Set Semeru {{ jdk_version }} OE as default java (Linux) + alternatives: + name: java + path: '{{ install_path }}/semeru-{{ jdk_version }}/bin/java' + link: /usr/bin/java + when: ansible_distribution != "MacOSX" + tags: semeru_install + +- name: Update /usr/bin/javac symlink (Linux) + alternatives: + name: javac + path: '{{ install_path }}/semeru-{{ jdk_version }}/bin/javac' + link: /usr/bin/javac + when: ansible_distribution != "MacOSX" + tags: semeru_install + +########## +# MacOSX # +########## + +- name: Install Semeru {{ jdk_version }} OE latest release (MacOS) + get_url: + url: https://api.adoptopenjdk.net/v3/installer/latest/{{ jdk_version }}/ga/mac/{{ api_architecture }}/jdk/openj9/normal/ibm?project=jdk + dest: /tmp/semeru-{{ jdk_version }}-installer.pkg + validate_certs: no + register: semeru_pkg_download + until: semeru_pkg_download is not failed + when: ansible_distribution == "MacOSX" + tags: semeru_install + +- name: Run MacOSX installer + shell: installer -pkg /tmp/semeru-{{ jdk_version }}-installer.pkg -target / + become: yes + become_user: root + when: ansible_distribution == "MacOSX" + tags: semeru_install + +- name: Find Semeru {{ jdk_version }} OE installation directory (MacOS) + find: + paths: '{{ install_path }}' + patterns: "^ibm-semeru-open-{{ jdk_version }}.*" + use_regex: yes + file_type: directory + become: yes + become_user: root + register: semeru_install_dir_mac + when: ansible_distribution == "MacOSX" + tags: semeru_install + +- name: Create symlink to Semeru {{ jdk_version }} install directory (MacOS) + file: + src: '{{ semeru_install_dir_mac.files[0].path }}/Contents/Home' + dest: '{{ install_path }}/semeru-{{ jdk_version }}' + state: link + become: yes + become_user: root + when: ansible_distribution == "MacOSX" + tags: semeru_install + +- name: Clean up Semeru {{ jdk_version }} OE installer + file: + path: '/Users/j9admin/semeru-{{ jdk_version }}-installer.pkg' + state: absent + when: ansible_distribution == "MacOSX" + tags: semeru_install \ No newline at end of file diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/files/offline_xcode_files_here b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/files/offline_xcode_files_here new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/tasks/main.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/tasks/main.yml new file mode 100644 index 0000000000..7d5405de30 --- /dev/null +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/tasks/main.yml @@ -0,0 +1,14 @@ +--- +######################### +# Xcdde offline install # +######################### + +# Install Xcode withou need to login with appleID +# Path /Applications/Xcode.app/ +# Requires the following variable: +# xcode_version: 12.4 | 13.1 | 13.2.1 | 13.4 | 14.3.1 | 15.0.1 +# Issue for xcode-version determination: https://github.ibm.com/runtimes/infrastructure/issues/8853 + +- name: xcode offline + include_tasks: xcode_offline.yml + tags: xcode_offline diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/tasks/xcode_offline.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/tasks/xcode_offline.yml new file mode 100644 index 0000000000..f96cd81082 --- /dev/null +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Xcode_offline/tasks/xcode_offline.yml @@ -0,0 +1,51 @@ + + +--- +- name: check xcode version + shell: xcodebuild -version + register: xcodebuild_version + failed_when: false + tags: xcode_offline + +- name: install and configure xcode if not installed + block: + + - name: test tag + debug: + var: xcodebuild_version + + - name: copy xcode file to remote host + copy: + src: Xcode_{{ xcode_version }}.xip + dest: '~' + force: false + + - name: install xcode {{ xcode_version }} + shell: | + xip -x ~/Xcode_{{ xcode_version }}.xip + args: + chdir: /Applications + become: yes + become_user: "{{ ansible_user }}" + + - name: Configure xcode {{ xcode_version }} + become: yes + shell: | + xcode-select -s /Applications/Xcode.app/Contents/Developer + xcodebuild -license accept + + - name: Clean up after install Xcode + shell: | + rm ~/Xcode_{{ xcode_version }}.xip + + - name: check xcode version + shell: xcodebuild -version + register: output + ignore_errors: true + + - name: check if xcode version is correct + debug: + var: output + + when: "'Xcode ' + xcode_version not in xcodebuild_version.stdout" + tags: xcode_offline diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/ant/tasks/main.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/ant/tasks/main.yml index cca5d09dd5..5a0669832c 100644 --- a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/ant/tasks/main.yml +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/ant/tasks/main.yml @@ -5,34 +5,9 @@ # Install Apache Ant from binaries on RHEL and Centos -- name: Check if Apache Ant is already installed in custom location /usr/local - shell: ls /usr/local/apache-ant-1.10.5 >/dev/null 2>&1 - failed_when: false - register: ant_installed - changed_when: false - tags: - - ant - - skip_ansible_lint - -- name: Download Apache Ant binaries - get_url: - url: https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.5-bin.zip - dest: /tmp/ - mode: 0440 - timeout: 25 - validate_certs: no - checksum: sha512:2e48f9e429d67708f5690bc307232f08440d01ebe414059292b6543971da9c7cd259c21533b9163b4dd753321c17bd917adf8407d03245a0945fc30a4e633163 - when: - - ant_installed.rc != 0 - - ansible_distribution != "MacOSX" - - ansible_distribution != "Solaris" - tags: ant - -- name: Download Apache Ant binaries (macOS) and (Solaris) - command: wget https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.5-bin.zip -O /tmp/apache-ant-1.10.5-bin.zip - when: - - ant_installed.rc != 0 - - ansible_distribution == "MacOSX" or ansible_distribution == "Solaris" +- name: set ant binary file name to variable + set_fact: + ant_binary_file_name: "{{ Ant_Download_URL.split('/')[-1] }}" tags: ant - name: Create /usr/local if it doesn't exist @@ -43,46 +18,13 @@ when: ansible_distribution == "Solaris" tags: ant -- name: GPG Signature verification - script: ../Supporting_Scripts/package_signature_verification.sh -f /tmp/apache-ant-1.10.5-bin.zip -sl "https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.5-bin.zip.asc" -k {{ key.apache_ant }} - when: ant_installed.rc != 0 - tags: ant - -- name: Extract ant - unarchive: - src: /tmp/apache-ant-1.10.5-bin.zip - dest: /usr/local - copy: False - when: - - ant_installed.rc != 0 - tags: ant - - name: Create /usr/local/bin if it doesn't exist file: path: /usr/local/bin state: directory mode: '0755' when: ansible_distribution != "MacOSX" - tags: ant - -- name: Create /usr/local/bin/ant symlink - file: - src: /usr/local/apache-ant-1.10.5/bin/ant - dest: /usr/local/bin/ant - state: link - when: - - ant_installed.rc != 0 - tags: ant - -- name: Clean up downloaded packages - file: - path: "{{ item }}" - state: absent - with_items: - - /tmp/apache-ant-1.10.5-bin.zip - when: - - ant_installed.rc != 0 - failed_when: false + become: true tags: ant - name: Remove the older Ant package via yum @@ -105,3 +47,62 @@ when: - ansible_distribution == "Ubuntu" tags: ant + +- name: Check if Apache Ant is already installed in custom location /usr/local + stat: + path: /usr/local/bin/ant + register: ant_installed + tags: + - ant + - skip_ansible_lint + +- name: install and configure ant + block: + + - name: Download Apache Ant binaries + get_url: + url: '{{ Ant_Download_URL }}' + dest: /tmp/ + mode: 0440 + timeout: 25 + validate_certs: no + checksum: sha512:2e48f9e429d67708f5690bc307232f08440d01ebe414059292b6543971da9c7cd259c21533b9163b4dd753321c17bd917adf8407d03245a0945fc30a4e633163 + when: + - ansible_distribution != "MacOSX" + - ansible_distribution != "Solaris" + + - name: Download Apache Ant binaries (macOS) and (Solaris) + get_url: url={{ Ant_Download_URL }} dest=/tmp/{{ ant_binary_file_name }} + when: + - ansible_distribution == "MacOSX" or ansible_distribution == "Solaris" + + - name: GPG Signature verification + script: ../Supporting_Scripts/package_signature_verification.sh -f /tmp/{{ ant_binary_file_name }} -sl "{{ Ant_Download_URL }}.asc" -k {{ key.apache_ant }} + ignore_errors: true + + - name: Extract ant + unarchive: + src: /tmp/{{ ant_binary_file_name }} + dest: /usr/local + copy: False + become: true + + - name: Create /usr/local/bin/ant symlink + file: + src: /usr/local/{{ ant_binary_file_name.split('-bin')[0] }}/bin/ant + dest: "{{ item }}" + state: link + with_items: + - /usr/local/bin/ant + become: true + + - name: Clean up downloaded packages + file: + path: "{{ item }}" + state: absent + with_items: + - /tmp/{{ ant_binary_file_name }} + failed_when: false + + when: not ant_installed.stat.exists + tags: ant diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/brew/tasks/main.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/brew/tasks/main.yml new file mode 100644 index 0000000000..6d9ab771a0 --- /dev/null +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/brew/tasks/main.yml @@ -0,0 +1,81 @@ +- name: Check if Homebrew is already installed + stat: + path: /usr/local/bin/brew + register: b + when: ansible_architecture == "x86_64" + tags: brew + +- name: Check if Homebrew is already installed + stat: + path: /opt/homebrew/bin/brew + register: b + when: ansible_architecture == "arm64" + tags: brew + +- set_fact: brew_is_installed="{{b.stat.exists}}" + when: b.stat.exists is defined + tags: brew + +- name: install home brew + block: + - name: add user j9admin to sudoers + template: + src: sudoers + dest: /etc/sudoers.d/{{ ansible_user }} + become: true + + - name: install home brew + shell: | + NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" + + - name: check brew installation + shell: /usr/local/bin/brew --version + register: check_brew + ignore_errors: true + when: ansible_architecture == "x86_64" + + - set_fact: brew_is_installed="{{check_brew.rc == 0}}" + when: check_brew.rc is defined + + - name: check brew installation + shell: /opt/homebrew/bin/brew --version + register: check_brew + ignore_errors: true + when: ansible_architecture == "arm64" + + - set_fact: brew_is_installed="{{check_brew.rc == 0}}" + when: check_brew.rc is defined + + - name: failed brew installation + fail: + msg: 'brew is not installed! exiting...' + when: not brew_is_installed + + - name: configure brew x86_64 + blockinfile: + state: present + insertafter: EOF + dest: ~/.zprofile + marker: "" + content: | + eval $(/usr/local/bin/brew shellenv) + when: ansible_architecture == "x86_64" + + - name: configure brew arm64 + blockinfile: + state: present + insertafter: EOF + dest: ~/.zprofile + marker: "" + content: | + eval $(/opt/homebrew/bin/brew shellenv) + when: ansible_architecture == "arm64" + + - name: remove user j9admin from sudoers + file: + path: /etc/sudoers.d/{{ ansible_user }} + state: absent + become: true + + when: not brew_is_installed + tags: brew