Skip to content

Commit

Permalink
add golang role
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermeindl committed Nov 9, 2023
1 parent 9f55b25 commit 07d92e3
Show file tree
Hide file tree
Showing 21 changed files with 277 additions and 63 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.1

- add golang role

## 1.0.0

- merge of existing roles to a collection
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ All provided roles do not use docker as container system.
- [alphanodes.setup.gitlab](roles/gitlab/)
- [alphanodes.setup.glances](roles/glances/)
- [alphanodes.setup.goaccess](roles/goaccess/)
- [alphanodes.setup.golang](roles/golang/)
- [alphanodes.setup.hedgedoc](roles/hedgedoc/)
- [alphanodes.setup.java](roles/java/)
- [alphanodes.setup.jekyll](roles/jekyll/)
Expand Down
21 changes: 21 additions & 0 deletions molecule/golang/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Converge
hosts: all
become: true

vars:
golang_version: '1.20.11'
golang_sha256_checksum: 'ced1b5cfd4e8aa7aff5e6a399ed111e5ed2903ee17aaa79ac0c93565fb229776'

roles:
- role: alphanodes.setup.golang

post_tasks:
- name: Run go version
ansible.builtin.command: go version
changed_when: false
register: go_version_info

- name: Show instaled go version
ansible.builtin.debug:
var: go_version_info.stdout
23 changes: 23 additions & 0 deletions molecule/golang/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
privileged: true
pre_build_image: true
cgroupns_mode: host
provisioner:
name: ansible
options:
diff: true
config_options:
defaults:
interpreter_python: auto_silent
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
2 changes: 1 addition & 1 deletion roles/ansible_node/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ansible_node_disallowed_packages:

# fixed version or latest
# use 7.2 or 7.2.1 for minor fixed version
ansible_node_ansible_version: 8.5
ansible_node_ansible_version: 8.6

# required switching from 2.9 to newer version
ansible_node_remove_before_install: false
Expand Down
6 changes: 6 additions & 0 deletions roles/common/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@

ansible_pip_venv: ansible
python_venv_parent: "{{ ansible_env.HOME }}/.venvs"

# Directory, which is used for downloading software packages
software_dir: /srv/software
# software_dir_owner:
# software_dir_group: "{{ software_dir_owner | omit }}"
# software_dir_mode:
7 changes: 7 additions & 0 deletions roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: Ensures software_dir exists

Check warning on line 1 in roles/common/tasks/main.yml

View workflow job for this annotation

GitHub Actions / build

1:1 [document-start] missing document start "---"
ansible.builtin.file:
path: '{{ software_dir }}'
owner: '{{ software_dir_owner | default(omit) }}'
group: '{{ software_dir_group | default(omit) }}'
mode: '{{ software_dir_mode | default(omit) }}'
state: directory
3 changes: 2 additions & 1 deletion roles/gitlab/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ gitlab_packages:
# see https://docs.gitlab.com/ee/install/installation.html#3-go
# NOTE: version should be tests in gitlab pipeline
# SEE https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/workhorse.gitlab-ci.yml#L30
gitlab_go_version: '1.20.10'
gitlab_go_version: '1.20.11'
gitlab_go_sha256_checksum: ef79a11aa095a08772d2a69e4f152f897c4e96ee297b0dc20264b7dec2961abe

gitlab_nginx_auth_realm: 'Code access is restricted'
gitlab_nginx_client_max_body_size: '0'
Expand Down
58 changes: 0 additions & 58 deletions roles/gitlab/tasks/go.yml

This file was deleted.

8 changes: 6 additions & 2 deletions roles/gitlab/tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@
register: gitlab_git_changed
when: gitlab_update

- name: Include Go tasks
ansible.builtin.include_tasks: go.yml
- name: Include Go role
ansible.builtin.include_role:
name: alphanodes.setup.golang
vars:
golang_version: '{{ gitlab_go_version | default(omit) }}'
golang_sha256_checksum: '{{ gitlab_go_sha256_checksum | default(omit) }}'

- name: Remove system yarnpkg is removed
ansible.builtin.apt:
Expand Down
2 changes: 1 addition & 1 deletion roles/gitlab/templates/gitlab-shell/config.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ http_settings:
auth_file: "{{ gitlab_home }}/.ssh/authorized_keys"

# SSL certificate dir where custom certificates can be placed
# https://golang.org/pkg/crypto/x509/
# https://pkg.go.dev/crypto/x509
# ssl_cert_dir: /opt/gitlab/embedded/ssl/certs/

# File that contains the secret key for verifying access to GitLab.
Expand Down
20 changes: 20 additions & 0 deletions roles/golang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Ansible Role: go

An Ansible Role that installs Go language on Debian and Ubuntu servers.

## Role Variables

Available variables can be found in [defaults/main.yml](defaults/main.yml)

## Example Playbook

```yaml
- hosts: all

vars:
golang_version: '1.20.10'
golang_sha256_checksum: d355c5ae3a8f7763c9ec9dc25153aae373958cbcb60dd09e91a8b56c7621b2fc

roles:
- alphanodes.setup.go
```
38 changes: 38 additions & 0 deletions roles/golang/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---

# Go language SDK version number
# use fixed version e.g. '1.20.11' or latest
golang_version: latest
golang_arch: amd64

# use it with fixed version
# golang_sha256_checksum: ef79a11aa095a08772d2a69e4f152f897c4e96ee297b0dc20264b7dec2961abe

# Mirror to download the Go language SDK redistributable package from
golang_mirror: 'https://dl.google.com/go'

# Base installation directory the Go language SDK distribution
golang_install_dir: '/usr/local/go'

# create link to /usr/local/bin to go binaries
# NOTE: only if golang_dist_packages = false
golang_link_to_local: true

golang_link_binaries:
- go
- gofmt

# Location for GOPATH environment variable
golang_gopath:

# if true, golang is installed with packages from linux distribution
# (not from golang_mirror)
golang_dist_packages: false

# only used with golang_dist_packages = true
golang_packages:
- golang-go
- golang-src

# set it to true, if you want to remove go
golang_remove: false
22 changes: 22 additions & 0 deletions roles/golang/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---

dependencies:
- role: alphanodes.setup.common
public: true

galaxy_info:
description: Install go language.
author: alexandermeindl
company: AlphaNodes GmbH
license: Apache License 2.0
min_ansible_version: '2.14'
platforms:
- name: Ubuntu
versions:
- focal
- jammy
- name: Debian
versions:
- buster
- bullseye
- bookworm
13 changes: 13 additions & 0 deletions roles/golang/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---

- name: Include setup tasks
ansible.builtin.import_tasks: setup.yml
tags:
- golang
when: not golang_remove | bool

- name: Include remove tasks
ansible.builtin.import_tasks: remove.yml
tags:
- golang
when: golang_remove | bool
23 changes: 23 additions & 0 deletions roles/golang/tasks/remove.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

- name: Remove for non-dist installation
when: not golang_dist_packages
block:
- name: Remove golang files and directories
ansible.builtin.file:
path: '{{ golang_install_dir }}'
state: absent

- name: Remove links
ansible.builtin.file:
path: "/usr/local/bin/{{ item }}"
state: absent
when: golang_link_to_local
loop: '{{ golang_link_binaries }}'

- name: Be sure debian packages are removed
ansible.builtin.apt:
name: '{{ golang_packages }}'
purge: true
state: absent
when: golang_dist_packages
80 changes: 80 additions & 0 deletions roles/golang/tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---

- name: Be sure debian packages are installed - {{ golang_latest_version_url }}
ansible.builtin.apt:
name: '{{ golang_packages }}'
state: present
when: golang_dist_packages

- name: Install for non-dist installation
when: not golang_dist_packages
block:
- name: Set golang_real_version with latest version
ansible.builtin.set_fact:
golang_real_version: "{{ lookup('url', golang_latest_version_url, wantlist=True) | first }}"
when: golang_version == 'latest'

- name: Show backup volkstheater
ansible.builtin.debug:
var: golang_real_version

- name: Set golang_real_version with fixed version
ansible.builtin.set_fact:
golang_real_version: "go{{ golang_version }}"
when: golang_version != 'latest'

- name: Check golang_file exists - {{ golang_real_version }}
ansible.builtin.stat:
path: '{{ software_dir }}/{{ golang_file }}'
register: golang_file_exists

- name: Check Go exists
ansible.builtin.stat:
path: '{{ golang_install_dir }}/bin/go'
register: golang_install_dir_exists

- name: Delete existing path for update - {{ golang_install_dir }}
ansible.builtin.file:
path: '{{ golang_install_dir }}'
state: absent
when:
- not golang_file_exists.stat.exists
- golang_install_dir_exists.stat.exists

- name: Creating {{ golang_install_dir }}
ansible.builtin.file:
path: '{{ golang_install_dir }}'
state: directory
mode: 0755
owner: root
group: root

- name: Download golang_file archive version {{ golang_real_version }}
ansible.builtin.get_url:
url: '{{ golang_mirror }}/{{ golang_file }}'
dest: '{{ software_dir }}/{{ golang_file }}'
mode: 0644
checksum: "{{ 'sha256:' + golang_sha256_checksum | default(omit) }}"
force: false
use_proxy: true
validate_certs: true
when: not golang_file_exists.stat.exists

- name: Extract golang_file archive
ansible.builtin.unarchive:
src: '{{ software_dir }}/{{ golang_file }}'
dest: '{{ golang_install_dir }}'
extra_opts: '--strip-components=1'
owner: root
group: root
remote_src: true
when: not golang_install_dir_exists.stat.exists or not golang_file_exists.stat.exists

- name: Create symlinks to go binaries
ansible.builtin.file:
src: '{{ golang_install_dir }}/bin/{{ item }}'
dest: /usr/local/bin/{{ item }}
force: true
state: link
when: golang_link_to_local
loop: '{{ golang_link_binaries }}'
4 changes: 4 additions & 0 deletions roles/golang/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

golang_file: "{{ golang_real_version }}.linux-{{ golang_arch }}.tar.gz"
golang_latest_version_url: https://go.dev/VERSION?m=text
2 changes: 2 additions & 0 deletions roles/matomo/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---

dependencies:
- role: alphanodes.setup.common
public: true
- role: alphanodes.setup.ssl
when: matomo_with_nginx
- role: alphanodes.setup.mysql_client
Expand Down
Loading

0 comments on commit 07d92e3

Please sign in to comment.