Skip to content

Commit 07d92e3

Browse files
add golang role
1 parent 9f55b25 commit 07d92e3

File tree

21 files changed

+277
-63
lines changed

21 files changed

+277
-63
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.0.1
4+
5+
- add golang role
6+
37
## 1.0.0
48

59
- merge of existing roles to a collection

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ All provided roles do not use docker as container system.
2929
- [alphanodes.setup.gitlab](roles/gitlab/)
3030
- [alphanodes.setup.glances](roles/glances/)
3131
- [alphanodes.setup.goaccess](roles/goaccess/)
32+
- [alphanodes.setup.golang](roles/golang/)
3233
- [alphanodes.setup.hedgedoc](roles/hedgedoc/)
3334
- [alphanodes.setup.java](roles/java/)
3435
- [alphanodes.setup.jekyll](roles/jekyll/)

molecule/golang/converge.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
become: true
5+
6+
vars:
7+
golang_version: '1.20.11'
8+
golang_sha256_checksum: 'ced1b5cfd4e8aa7aff5e6a399ed111e5ed2903ee17aaa79ac0c93565fb229776'
9+
10+
roles:
11+
- role: alphanodes.setup.golang
12+
13+
post_tasks:
14+
- name: Run go version
15+
ansible.builtin.command: go version
16+
changed_when: false
17+
register: go_version_info
18+
19+
- name: Show instaled go version
20+
ansible.builtin.debug:
21+
var: go_version_info.stdout

molecule/golang/molecule.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: docker
6+
platforms:
7+
- name: instance
8+
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
9+
command: ${MOLECULE_DOCKER_COMMAND:-""}
10+
volumes:
11+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
12+
privileged: true
13+
pre_build_image: true
14+
cgroupns_mode: host
15+
provisioner:
16+
name: ansible
17+
options:
18+
diff: true
19+
config_options:
20+
defaults:
21+
interpreter_python: auto_silent
22+
playbooks:
23+
converge: ${MOLECULE_PLAYBOOK:-converge.yml}

roles/ansible_node/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ansible_node_disallowed_packages:
4747

4848
# fixed version or latest
4949
# use 7.2 or 7.2.1 for minor fixed version
50-
ansible_node_ansible_version: 8.5
50+
ansible_node_ansible_version: 8.6
5151

5252
# required switching from 2.9 to newer version
5353
ansible_node_remove_before_install: false

roles/common/defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22

33
ansible_pip_venv: ansible
44
python_venv_parent: "{{ ansible_env.HOME }}/.venvs"
5+
6+
# Directory, which is used for downloading software packages
7+
software_dir: /srv/software
8+
# software_dir_owner:
9+
# software_dir_group: "{{ software_dir_owner | omit }}"
10+
# software_dir_mode:

roles/common/tasks/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- name: Ensures software_dir exists
2+
ansible.builtin.file:
3+
path: '{{ software_dir }}'
4+
owner: '{{ software_dir_owner | default(omit) }}'
5+
group: '{{ software_dir_group | default(omit) }}'
6+
mode: '{{ software_dir_mode | default(omit) }}'
7+
state: directory

roles/gitlab/defaults/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ gitlab_packages:
170170
# see https://docs.gitlab.com/ee/install/installation.html#3-go
171171
# NOTE: version should be tests in gitlab pipeline
172172
# SEE https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/workhorse.gitlab-ci.yml#L30
173-
gitlab_go_version: '1.20.10'
173+
gitlab_go_version: '1.20.11'
174+
gitlab_go_sha256_checksum: ef79a11aa095a08772d2a69e4f152f897c4e96ee297b0dc20264b7dec2961abe
174175

175176
gitlab_nginx_auth_realm: 'Code access is restricted'
176177
gitlab_nginx_client_max_body_size: '0'

roles/gitlab/tasks/go.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

roles/gitlab/tasks/setup.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@
124124
register: gitlab_git_changed
125125
when: gitlab_update
126126

127-
- name: Include Go tasks
128-
ansible.builtin.include_tasks: go.yml
127+
- name: Include Go role
128+
ansible.builtin.include_role:
129+
name: alphanodes.setup.golang
130+
vars:
131+
golang_version: '{{ gitlab_go_version | default(omit) }}'
132+
golang_sha256_checksum: '{{ gitlab_go_sha256_checksum | default(omit) }}'
129133

130134
- name: Remove system yarnpkg is removed
131135
ansible.builtin.apt:

roles/gitlab/templates/gitlab-shell/config.yml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ http_settings:
3535
auth_file: "{{ gitlab_home }}/.ssh/authorized_keys"
3636

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

4141
# File that contains the secret key for verifying access to GitLab.

roles/golang/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Ansible Role: go
2+
3+
An Ansible Role that installs Go language on Debian and Ubuntu servers.
4+
5+
## Role Variables
6+
7+
Available variables can be found in [defaults/main.yml](defaults/main.yml)
8+
9+
## Example Playbook
10+
11+
```yaml
12+
- hosts: all
13+
14+
vars:
15+
golang_version: '1.20.10'
16+
golang_sha256_checksum: d355c5ae3a8f7763c9ec9dc25153aae373958cbcb60dd09e91a8b56c7621b2fc
17+
18+
roles:
19+
- alphanodes.setup.go
20+
```

roles/golang/defaults/main.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
3+
# Go language SDK version number
4+
# use fixed version e.g. '1.20.11' or latest
5+
golang_version: latest
6+
golang_arch: amd64
7+
8+
# use it with fixed version
9+
# golang_sha256_checksum: ef79a11aa095a08772d2a69e4f152f897c4e96ee297b0dc20264b7dec2961abe
10+
11+
# Mirror to download the Go language SDK redistributable package from
12+
golang_mirror: 'https://dl.google.com/go'
13+
14+
# Base installation directory the Go language SDK distribution
15+
golang_install_dir: '/usr/local/go'
16+
17+
# create link to /usr/local/bin to go binaries
18+
# NOTE: only if golang_dist_packages = false
19+
golang_link_to_local: true
20+
21+
golang_link_binaries:
22+
- go
23+
- gofmt
24+
25+
# Location for GOPATH environment variable
26+
golang_gopath:
27+
28+
# if true, golang is installed with packages from linux distribution
29+
# (not from golang_mirror)
30+
golang_dist_packages: false
31+
32+
# only used with golang_dist_packages = true
33+
golang_packages:
34+
- golang-go
35+
- golang-src
36+
37+
# set it to true, if you want to remove go
38+
golang_remove: false

roles/golang/meta/main.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
3+
dependencies:
4+
- role: alphanodes.setup.common
5+
public: true
6+
7+
galaxy_info:
8+
description: Install go language.
9+
author: alexandermeindl
10+
company: AlphaNodes GmbH
11+
license: Apache License 2.0
12+
min_ansible_version: '2.14'
13+
platforms:
14+
- name: Ubuntu
15+
versions:
16+
- focal
17+
- jammy
18+
- name: Debian
19+
versions:
20+
- buster
21+
- bullseye
22+
- bookworm

roles/golang/tasks/main.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
3+
- name: Include setup tasks
4+
ansible.builtin.import_tasks: setup.yml
5+
tags:
6+
- golang
7+
when: not golang_remove | bool
8+
9+
- name: Include remove tasks
10+
ansible.builtin.import_tasks: remove.yml
11+
tags:
12+
- golang
13+
when: golang_remove | bool

roles/golang/tasks/remove.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
3+
- name: Remove for non-dist installation
4+
when: not golang_dist_packages
5+
block:
6+
- name: Remove golang files and directories
7+
ansible.builtin.file:
8+
path: '{{ golang_install_dir }}'
9+
state: absent
10+
11+
- name: Remove links
12+
ansible.builtin.file:
13+
path: "/usr/local/bin/{{ item }}"
14+
state: absent
15+
when: golang_link_to_local
16+
loop: '{{ golang_link_binaries }}'
17+
18+
- name: Be sure debian packages are removed
19+
ansible.builtin.apt:
20+
name: '{{ golang_packages }}'
21+
purge: true
22+
state: absent
23+
when: golang_dist_packages

roles/golang/tasks/setup.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
3+
- name: Be sure debian packages are installed - {{ golang_latest_version_url }}
4+
ansible.builtin.apt:
5+
name: '{{ golang_packages }}'
6+
state: present
7+
when: golang_dist_packages
8+
9+
- name: Install for non-dist installation
10+
when: not golang_dist_packages
11+
block:
12+
- name: Set golang_real_version with latest version
13+
ansible.builtin.set_fact:
14+
golang_real_version: "{{ lookup('url', golang_latest_version_url, wantlist=True) | first }}"
15+
when: golang_version == 'latest'
16+
17+
- name: Show backup volkstheater
18+
ansible.builtin.debug:
19+
var: golang_real_version
20+
21+
- name: Set golang_real_version with fixed version
22+
ansible.builtin.set_fact:
23+
golang_real_version: "go{{ golang_version }}"
24+
when: golang_version != 'latest'
25+
26+
- name: Check golang_file exists - {{ golang_real_version }}
27+
ansible.builtin.stat:
28+
path: '{{ software_dir }}/{{ golang_file }}'
29+
register: golang_file_exists
30+
31+
- name: Check Go exists
32+
ansible.builtin.stat:
33+
path: '{{ golang_install_dir }}/bin/go'
34+
register: golang_install_dir_exists
35+
36+
- name: Delete existing path for update - {{ golang_install_dir }}
37+
ansible.builtin.file:
38+
path: '{{ golang_install_dir }}'
39+
state: absent
40+
when:
41+
- not golang_file_exists.stat.exists
42+
- golang_install_dir_exists.stat.exists
43+
44+
- name: Creating {{ golang_install_dir }}
45+
ansible.builtin.file:
46+
path: '{{ golang_install_dir }}'
47+
state: directory
48+
mode: 0755
49+
owner: root
50+
group: root
51+
52+
- name: Download golang_file archive version {{ golang_real_version }}
53+
ansible.builtin.get_url:
54+
url: '{{ golang_mirror }}/{{ golang_file }}'
55+
dest: '{{ software_dir }}/{{ golang_file }}'
56+
mode: 0644
57+
checksum: "{{ 'sha256:' + golang_sha256_checksum | default(omit) }}"
58+
force: false
59+
use_proxy: true
60+
validate_certs: true
61+
when: not golang_file_exists.stat.exists
62+
63+
- name: Extract golang_file archive
64+
ansible.builtin.unarchive:
65+
src: '{{ software_dir }}/{{ golang_file }}'
66+
dest: '{{ golang_install_dir }}'
67+
extra_opts: '--strip-components=1'
68+
owner: root
69+
group: root
70+
remote_src: true
71+
when: not golang_install_dir_exists.stat.exists or not golang_file_exists.stat.exists
72+
73+
- name: Create symlinks to go binaries
74+
ansible.builtin.file:
75+
src: '{{ golang_install_dir }}/bin/{{ item }}'
76+
dest: /usr/local/bin/{{ item }}
77+
force: true
78+
state: link
79+
when: golang_link_to_local
80+
loop: '{{ golang_link_binaries }}'

roles/golang/vars/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
golang_file: "{{ golang_real_version }}.linux-{{ golang_arch }}.tar.gz"
4+
golang_latest_version_url: https://go.dev/VERSION?m=text

roles/matomo/meta/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22

33
dependencies:
4+
- role: alphanodes.setup.common
5+
public: true
46
- role: alphanodes.setup.ssl
57
when: matomo_with_nginx
68
- role: alphanodes.setup.mysql_client

0 commit comments

Comments
 (0)