Skip to content

Commit 8aed97e

Browse files
committed
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)
1 parent e8147c5 commit 8aed97e

File tree

11 files changed

+595
-150
lines changed

11 files changed

+595
-150
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
3+
- name: Ansible MacOS playbook
4+
hosts: "all"
5+
gather_facts: yes
6+
become_method: sudo
7+
vars:
8+
ansible_python_interpreter: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3
9+
Ant_Download_URL: https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.12-bin.zip
10+
known_keys:
11+
- {name: "github.com", value: "github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl"}
12+
xcode_version: '15.0.1'
13+
ansible_user: adminuser
14+
jdk_version: 17
15+
16+
17+
#########
18+
# Roles #
19+
#########
20+
roles:
21+
- role: brew
22+
tags: [build_tools, xcode, adoptopenjdk]
23+
- role: Xcode_offline
24+
tags: [build_tools, xcode, adoptopenjdk]
25+
- role: Common
26+
tags: [build_tools, build_tools_openj9]
27+
- role: Jenkins_User
28+
tags: [build_tools, build_tools_openj9, jenkins]
29+
- role: Semeru_install
30+
tags: [build_tools, build_tools_openj9, semeru]
31+
- role: ant
32+
tags: [build_tools, build_tools_openj9]
33+
- role: Ant-Contrib
34+
tags: [build_tools, build_tools_openj9]
35+
36+
# Macos do not let any Ansible activity before you install python manually. So you need to do a workaround before running this PB.
37+
# 1- download python from https://www.python.org/ftp/python/3.11.4/python-3.11.4-macos11.pkg
38+
# 2- scp downloaded file to macos (example: scp ~/Downloads/python-3.11.4-macos11.pkg [email protected]:~/)
39+
# 3- ssh to mac machine and run this to install python:
40+
# 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
41+
#
42+
# 4- then you can start using the PB as normal like other machine types:
43+
# example: ansible-playbook -i hosts.yml macos-setup.yml -Kk
44+
#
45+
# sample host.yml file:
46+
47+
# all:
48+
# children:
49+
# hosts:
50+
# macXXXXXX.yourdomain.com:
51+
52+
53+
54+
Lines changed: 94 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
2-
###############
3-
# Ant-Contrib #
4-
###############
2+
53

64
# ANT_HOME/lib is: /usr/local/apache-ant-*/lib
5+
# Use the following variables:
6+
# antContribVersion: default('1.0b2')
7+
- name: set ant binary file name to variable
8+
set_fact:
9+
ant_binary_file_name: "{{ Ant_Download_URL.split('/')[-1].split('-bin')[0] }}"
10+
tags: ant-contrib
711

812
- name: Set ant-contrib version
9-
set_fact: antContribVersion=1.0b2
13+
set_fact: antContribVersion={{ antContribVersion | default('1.0b2') }}
1014
tags: ant-contrib
1115

1216
- name: Set ant_lib_dir variable for on {{ ansible_distribution }} {{ ansible_architecture }}
1317
set_fact:
14-
ant_lib_dir: /usr/local/apache-ant-1.10.5/lib
15-
tags: ant-contrib
16-
17-
- name: "Print ant_lib_dir variable"
18-
debug: var=ant_lib_dir
18+
ant_lib_dir: /usr/local/{{ ant_binary_file_name }}/lib
1919
tags: ant-contrib
2020

2121
- name: Check if ant-contrib is already installed
@@ -25,79 +25,96 @@
2525
tags: ant-contrib
2626

2727
- name: Download ant-contrib
28-
get_url:
29-
url: https://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-{{ antContribVersion }}/ant-contrib-{{ antContribVersion }}-bin.tar.gz
30-
dest: /tmp/
31-
mode: 0440
32-
timeout: 25
33-
validate_certs: no
34-
checksum: sha256:c9b8b1ca18b13e293688cafbd8990c940ca49104dbeefc242e5c3f8de271abdf
35-
retries: 3
36-
delay: 5
37-
register: antContrib_download
38-
until: antContrib_download is not failed
39-
when:
40-
- not antcontrib_status.stat.exists
41-
- ansible_distribution != "MacOSX"
42-
- ansible_distribution != "Solaris"
43-
- not (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
44-
tags: ant-contrib
28+
block:
4529

46-
# Use wget instead of ansible's get_url for Centos 6 https://github.com/adoptium/infrastructure/issues/2486
30+
- name: Download ant-contrib
31+
get_url:
32+
url: https://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-{{ antContribVersion }}/ant-contrib-{{ antContribVersion }}-bin.tar.gz
33+
dest: /tmp/
34+
mode: 0440
35+
timeout: 25
36+
validate_certs: no
37+
checksum: sha256:c9b8b1ca18b13e293688cafbd8990c940ca49104dbeefc242e5c3f8de271abdf
38+
retries: 3
39+
delay: 5
40+
register: antContrib_download
41+
until: antContrib_download is not failed
42+
when:
43+
- ansible_distribution != "MacOSX"
44+
- ansible_distribution != "Solaris"
45+
- not (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
4746

48-
- name: Download ant-contrib (CentOS 6)
49-
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
50-
retries: 3
51-
delay: 5
52-
register: antContrib_download
53-
until: antContrib_download is not failed
54-
when:
55-
- not antcontrib_status.stat.exists
56-
- ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"
57-
tags: ant-contrib
47+
# Use wget instead of ansible's get_url for Centos 6 https://github.com/adoptium/infrastructure/issues/2486
5848

59-
- name: Verify sha256 checksum of download (CentOS 6)
60-
stat:
61-
path: /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz
62-
checksum_algorithm: sha256
63-
get_checksum: yes
64-
register: antcontrib_checksum
65-
failed_when: antcontrib_checksum.stat.checksum != 'c9b8b1ca18b13e293688cafbd8990c940ca49104dbeefc242e5c3f8de271abdf'
66-
when:
67-
- not antcontrib_status.stat.exists
68-
- ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"
69-
tags: ant-contrib
49+
- name: Download ant-contrib (CentOS 6)
50+
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
51+
retries: 3
52+
delay: 5
53+
register: antContrib_download
54+
until: antContrib_download is not failed
55+
when:
56+
- ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"
7057

71-
- name: Download ant-contrib (macOS) and (Solaris)
72-
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
73-
retries: 3
74-
delay: 5
75-
register: antContrib_download
76-
until: antContrib_download is not failed
77-
when:
78-
- not antcontrib_status.stat.exists
79-
- ansible_distribution == "MacOSX" or ansible_distribution == "Solaris"
80-
tags: ant-contrib
58+
- name: Verify sha256 checksum of download (CentOS 6)
59+
stat:
60+
path: /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz
61+
checksum_algorithm: sha256
62+
get_checksum: yes
63+
register: antcontrib_checksum
64+
failed_when: antcontrib_checksum.stat.checksum != 'c9b8b1ca18b13e293688cafbd8990c940ca49104dbeefc242e5c3f8de271abdf'
65+
when:
66+
- ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"
8167

82-
- name: Extract ant-contrib
83-
unarchive:
84-
src: /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz
85-
dest: /tmp/
86-
copy: False
87-
when: not antcontrib_status.stat.exists
88-
tags: ant-contrib
68+
- name: Download ant-contrib (macOS) and (Solaris)
69+
get_url:
70+
url: "https://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-{{ antContribVersion }}/ant-contrib-{{ antContribVersion }}-bin.tar.gz"
71+
dest: "/tmp"
72+
retries: 3
73+
delay: 5
74+
register: antContrib_download
75+
until: antContrib_download is not failed
76+
when:
77+
- ansible_distribution == "MacOSX" or ansible_distribution == "Solaris"
8978

90-
- name: Move ant-contrib.jar to ant lib folder
91-
command: mv /tmp/ant-contrib/lib/ant-contrib.jar {{ ant_lib_dir }}
92-
when: not antcontrib_status.stat.exists
93-
tags: ant-contrib
79+
- name: Creates directory {{ ant_lib_dir }}
80+
file:
81+
path: "{{ ant_lib_dir }}"
82+
state: directory
83+
become: true
84+
85+
- name: Extract ant-contrib
86+
unarchive:
87+
src: /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz
88+
dest: /tmp
89+
copy: False
90+
when:
91+
- ansible_distribution != "MacOSX"
92+
93+
- name: Extract ant-contrib tar -xf /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz -C /tmp
94+
command: tar -xf /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz -C /tmp
95+
register: antcontrib_unpack
96+
become: true
97+
until: antcontrib_unpack is not failed
98+
when:
99+
- ansible_distribution == "MacOSX"
94100

95-
- name: Remove downloaded packages for ant-contrib
96-
file:
97-
path: "{{ item }}"
98-
state: absent
99-
with_items:
100-
- /tmp/ant-contrib
101-
- /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz
102-
failed_when: false
101+
- name: copy ant-contrib /tmp/ant-contrib/lib/ant-contrib.jar into /usr/local/{{ ant_binary_file_name }}/lib
102+
copy:
103+
src: /tmp/ant-contrib/lib/ant-contrib.jar
104+
dest: "/usr/local/{{ant_binary_file_name }}/lib/"
105+
remote_src: true
106+
become: true
107+
108+
- name: Cleanup after ant-contrib installed
109+
file:
110+
path: "{{ item }}"
111+
state: absent
112+
with_items:
113+
- /tmp/ant-contrib/
114+
- /tmp/ant-contrib-{{ antContribVersion }}-bin.tar.gz
115+
failed_when: false
116+
become: true
117+
103118
tags: ant-contrib
119+
when:
120+
- not antcontrib_status.stat.exists
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#authorized key(s) here:

ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/Jenkins_User/tasks/main.yml

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
action: user name={{ Jenkins_Username }} group=staff state=present home={{ home_folder }} shell=/bin/bash
4040
when: ansible_distribution == "MacOSX"
4141
tags: [jenkins_user, adoptopenjdk]
42+
become: true
4243

4344
- name: Enable SSH login for Jenkins user (macOS)
4445
command: dseditgroup -o edit -a {{ Jenkins_Username }} -t staff com.apple.access_ssh
@@ -78,23 +79,20 @@
7879
authorized_key:
7980
user: "{{ Jenkins_Username }}"
8081
state: present
81-
key: "{{ Jenkins_User_SSHKey }}"
82+
key: "{{ lookup('file', 'authorized_key.pub') }}"
8283
tags: [jenkins_user, jenkins_authorized_key, adoptopenjdk]
84+
become: true
8385

84-
- name: Add github.com to known_hosts
86+
- name: Add needed items to "{{ home_folder }}/.ssh/known_hosts"
8587
known_hosts:
86-
name: github.com
87-
key: github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
88+
name: "{{ item.name }}"
89+
key: "{{ item.value }}"
8890
path: "{{ home_folder }}/.ssh/known_hosts"
8991
state: present
92+
with_items: "{{known_keys}}"
9093
tags: [jenkins_user, adoptopenjdk]
91-
92-
- name: Change ownership of jenkins' ~/.ssh/known_hosts
93-
file:
94-
path: "{{ home_folder }}/.ssh/known_hosts"
95-
owner: "{{ Jenkins_Username }}"
96-
mode: 0644
97-
tags: [jenkins_user, adoptopenjdk]
94+
become: true
95+
become_user: '{{ Jenkins_Username }}'
9896

9997
- name: Add Jenkins user to the audio group
10098
user: name={{ Jenkins_Username }}
@@ -104,6 +102,7 @@
104102
- (ansible_distribution == "Ubuntu" or ansible_distribution == "SLES")
105103
- ansible_architecture != "armv7l"
106104
tags: [jenkins_user, adoptopenjdk]
105+
become: true
107106

108107
- name: Unset expiry on user account for Redhat for Jenkins user
109108
command: chage -M -1 -E -1 {{ Jenkins_Username }}
@@ -138,3 +137,49 @@
138137
- ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7"
139138
tags:
140139
- jenkins_user
140+
141+
#additional settings for user jenkins
142+
- name: check if bin paths are exist before add them to {{ home_folder }}/.bashrc
143+
stat: path={{item}}
144+
with_items:
145+
- /opt/homebrew/bin/
146+
- /usr/local/bin/
147+
register: mac_bin_paths
148+
tags:
149+
- jenkins_user
150+
151+
- name: configure {{ home_folder }}/.bashrc
152+
copy:
153+
dest: "{{ home_folder }}/.bashrc"
154+
content: "export PATH={{ mac_bin_paths | join(':') }}:{{ lookup('ansible.builtin.env', 'PATH') }}"
155+
owner: "{{ Jenkins_Username }}"
156+
mode: 0700
157+
become: true
158+
tags:
159+
- jenkins_user
160+
161+
- name: create folder "{{ home_folder }}/openjdk_cache"
162+
file:
163+
path: "{{ home_folder }}/openjdk_cache"
164+
state: directory
165+
owner: "{{ Jenkins_Username }}"
166+
mode: 0755
167+
become: true
168+
tags:
169+
- jenkins_user
170+
171+
- name: fetch required JDK repo into {{ home_folder }}/openjdk_cache
172+
shell:
173+
cmd: |
174+
git init --bare
175+
git remote -v | grep jdk8 || git remote add jdk8 https://github.com/ibmruntimes/openj9-openjdk-jdk8.git
176+
git remote -v | grep jdk11 || git remote add jdk11 https://github.com/ibmruntimes/openj9-openjdk-jdk11.git
177+
git remote -v | grep jdk || git remote add jdk https://github.com/ibmruntimes/openj9-openjdk-jdk.git
178+
git remote -v | grep openj9 || git remote add openj9 https://github.com/eclipse-openj9/openj9.git
179+
git remote -v | grep omr || git remote add omr https://github.com/eclipse-openj9/openj9-omr.git
180+
git fetch --all
181+
chdir: "{{ home_folder }}/openjdk_cache"
182+
become: true
183+
become_user: "{{ Jenkins_Username }}"
184+
tags:
185+
- jenkins_user
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
#####################
3+
# install Semeru OE #
4+
#####################
5+
6+
- name: install Semeru OE
7+
include_tasks: semeru-install.yml
8+
tags: semeru_install

0 commit comments

Comments
 (0)