-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ansible): implement Helix Core setup playbook
- Replace p4_configure.sh and p4_setup.sh with Ansible playbook - Eliminate need for Packer-built AMI and automates Amazon Linux 2023 - Add tasks for downloading and configuring Helix binaries - Implement platform-specific binary selection - Ensure correct placement of binaries in /hxdepots/sdp/helix_binaries - Add error handling and retries for binary downloads - Improve automation and consistency in Perforce Helix Core setup This playbook automates the Perforce Helix Core installation and configuration process, providing a more robust and maintainable solution compared to the previous shell scripts. It dynamically selects the appropriate binaries based on the target system's architecture, enhancing cross-platform compatibility.
- Loading branch information
Showing
1 changed file
with
175 additions
and
0 deletions.
There are no files selected for viewing
175 changes: 175 additions & 0 deletions
175
assets/ansible-playbooks/perforce/helix-core/p4_configure_playbook.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
--- | ||
- name: Install and Configure Perforce | ||
hosts: all | ||
become: yes | ||
vars: | ||
log_file: "/var/log/p4_setup.log" | ||
sdp_root: "/hxdepots/sdp/helix_binaries" | ||
sdp: "/hxdepots/sdp" | ||
package: "policycoreutils-python-utils" | ||
required_binaries: | ||
- p4 | ||
- p4broker | ||
- p4d | ||
- p4p | ||
default_helix_version: "r23.1" | ||
default_bin_list: "p4,p4d,p4p,p4broker" | ||
perforce_ftp_base_url: "https://ftp.perforce.com/perforce" | ||
stage_bin_dir: "/hxdepots/sdp/helix_binaries" | ||
download_apis: false | ||
|
||
tasks: | ||
- name: Ensure running as root | ||
fail: | ||
msg: "This playbook must be run as root" | ||
when: ansible_user_id != "root" | ||
|
||
- name: Ensure perforce group exists | ||
group: | ||
name: perforce | ||
state: present | ||
|
||
- name: Ensure perforce user exists | ||
user: | ||
name: perforce | ||
group: perforce | ||
home: /home/perforce | ||
shell: /bin/bash | ||
create_home: yes | ||
|
||
- name: Set up sudoers for perforce user | ||
copy: | ||
content: "perforce ALL=(ALL) NOPASSWD:ALL" | ||
dest: /etc/sudoers.d/perforce | ||
mode: '0400' | ||
|
||
- name: Create required directories | ||
file: | ||
path: "{{ item }}" | ||
state: directory | ||
owner: perforce | ||
group: perforce | ||
mode: '0755' | ||
loop: | ||
- /hxdepots | ||
- /hxlogs | ||
- /hxmetadata | ||
|
||
- name: Download SDP | ||
get_url: | ||
url: https://swarm.workshop.perforce.com/download/guest/perforce_software/sdp/downloads/sdp.Unix.tgz | ||
dest: /hxdepots/sdp.Unix.tgz | ||
|
||
- name: Extract SDP | ||
unarchive: | ||
src: /hxdepots/sdp.Unix.tgz | ||
dest: /hxdepots | ||
remote_src: yes | ||
|
||
- name: Set permissions for SDP | ||
file: | ||
path: "{{ sdp }}" | ||
state: directory | ||
recurse: yes | ||
mode: 'u+w' | ||
|
||
- name: Check for required binaries | ||
stat: | ||
path: "{{ sdp_root }}/{{ item }}" | ||
register: binary_stats | ||
loop: "{{ required_binaries }}" | ||
|
||
- name: Ensure the target directory exists | ||
file: | ||
path: "{{ stage_bin_dir }}" | ||
state: directory | ||
mode: '0755' | ||
|
||
- name: Set Helix version | ||
set_fact: | ||
helix_version: "{{ helix_version | default(default_helix_version) }}" | ||
|
||
- name: Set binary list | ||
set_fact: | ||
bin_list: "{{ bin_list | default(default_bin_list) }}" | ||
|
||
- name: Determine OS and architecture | ||
set_fact: | ||
os_name: "{{ ansible_system | lower }}" | ||
os_arch: "{{ ansible_architecture }}" | ||
|
||
- name: Set platform for each binary | ||
set_fact: | ||
platform: >- | ||
{%- if os_name == 'linux' -%} | ||
linux26{{ 'x86_64' if os_arch == 'x86_64' else '' }} | ||
{%- else -%} | ||
{{ os_name }}{{ '64' if os_arch == 'x86_64' else '' }} | ||
{%- endif -%} | ||
- name: Download binaries | ||
get_url: | ||
url: "{{ perforce_ftp_base_url }}/{{ helix_version }}/bin.{{ platform | trim }}/{{ item }}" | ||
dest: "{{ stage_bin_dir }}/{{ item }}" | ||
mode: '0755' | ||
loop: "{{ bin_list.split(',') }}" | ||
register: download_result | ||
retries: 3 | ||
delay: 5 | ||
until: download_result is success | ||
|
||
|
||
- name: Get binary versions | ||
command: "{{ stage_bin_dir }}/{{ item }} -V" | ||
register: version_info | ||
changed_when: false | ||
loop: "{{ bin_list.split(',') }}" | ||
|
||
- name: Display binary versions | ||
debug: | ||
msg: "Version of {{ item.item }}: {{ item.stdout_lines[0] }}" | ||
loop: "{{ version_info.results }}" | ||
|
||
- name: Download APIs | ||
block: | ||
- name: Get API directory listing | ||
uri: | ||
url: "{{ perforce_ftp_base_url }}/{{ helix_version }}/bin.{{ platform }}/" | ||
return_content: yes | ||
register: api_dir_content | ||
|
||
- name: Extract API filenames | ||
set_fact: | ||
api_files: "{{ api_dir_content.content | regex_findall('href=\"(p4api-.*?.tgz)\"') }}" | ||
|
||
- name: Download API files | ||
get_url: | ||
url: "{{ perforce_ftp_base_url }}/{{ helix_version }}/bin.{{ platform }}/{{ item }}" | ||
dest: "{{ stage_bin_dir }}/{{ item }}" | ||
loop: "{{ api_files }}" | ||
|
||
- name: Display API versions | ||
command: tar -tzf {{ stage_bin_dir }}/{{ item }} | head -1 | ||
register: api_versions | ||
changed_when: false | ||
loop: "{{ api_files }}" | ||
|
||
- name: Show API versions | ||
debug: | ||
msg: "Version of {{ item.item }}: {{ item.stdout.split('/')[0] }}" | ||
loop: "{{ api_versions.results }}" | ||
when: download_apis | bool | ||
|
||
- name: Set ownership of SDP_Root | ||
file: | ||
path: "{{ sdp_root }}" | ||
state: directory | ||
recurse: yes | ||
owner: perforce | ||
group: perforce | ||
|
||
- name: Log completion | ||
lineinfile: | ||
path: "{{ log_file }}" | ||
line: "{{ ansible_date_time.iso8601 }} - Perforce installation and configuration completed" | ||
create: yes |