Skip to content
This repository was archived by the owner on Jul 14, 2022. It is now read-only.

Commit 1037989

Browse files
committed
Install java using asdf
1 parent bbef2ae commit 1037989

File tree

17 files changed

+147
-118
lines changed

17 files changed

+147
-118
lines changed

group_vars/all.yml

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

playbook.yml

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,20 @@
11
---
22
- hosts: all
33
pre_tasks:
4-
- name: Verify Ansible version
5-
assert:
6-
that: "ansible_version.full is version_compare('2.9', '>=')"
7-
fail_msg: This Ansible playbook requires Ansible version >= 2.9.1. Current version is {{ ansible_version.full }}
8-
quiet: yes
9-
tasks:
10-
- name: Enable third-party sources
11-
lineinfile:
12-
path: /etc/apt/sources.list
13-
regexp: '^#\s?(deb\s{1,}.*partner)$'
14-
line: '\g<1>'
15-
backrefs: yes
16-
- name: Update repos and upgrade all packages
17-
apt:
18-
update_cache: yes
19-
upgrade: safe
20-
force_apt_get: yes
21-
- name: Execute role 'common'
22-
import_role:
23-
name: common
4+
- import_tasks: pre_tasks.yml
5+
tags: ['common', 'gnome', 'dev', 'entertainment', 'work']
6+
roles:
7+
- role: common
248
tags: ['common']
25-
- name: Execute role 'gnome'
26-
import_role:
27-
name: gnome
9+
- role: gnome
2810
tags: ['gnome']
29-
- name: Execute role 'dev'
30-
import_role:
31-
name: dev
11+
- role: dev
3212
tags: ['dev']
33-
- name: Execute role 'entertainment'
34-
import_role:
35-
name: entertainment
13+
- role: entertainment
3614
tags: ['entertainment']
37-
- name: Execute role 'work'
38-
import_role:
39-
name: work
15+
- role: work
4016
tags: ['work']
17+
post_tasks:
4118
- name: Remove useless apt packages and dependencies
4219
apt:
4320
autoremove: yes

pre_tasks.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
- name: Verify Ansible version
3+
assert:
4+
that: "ansible_version.full is version_compare('2.9', '>=')"
5+
fail_msg: This Ansible playbook requires Ansible version >= 2.9.1. Current version is {{ ansible_version.full }}
6+
quiet: yes
7+
- name: Enable third-party sources
8+
lineinfile:
9+
path: /etc/apt/sources.list
10+
regexp: '^#\s?(deb\s{1,}.*partner)$'
11+
line: '\g<1>'
12+
backrefs: yes
13+
- name: Update repos and upgrade all packages
14+
apt:
15+
update_cache: yes
16+
upgrade: safe
17+
force_apt_get: yes
18+
- name: Install fish shell
19+
apt:
20+
name: fish
21+
force_apt_get: yes
22+
- name: Set current user's default shell to fish
23+
user:
24+
name: "{{ ansible_user }}"
25+
shell: /usr/bin/fish

roles/asdf/tasks/java.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: Add asdf java plugin
3+
shell: . ~/.bashrc && asdf plugin add java
4+
register: add_plugin
5+
failed_when: add_plugin.rc == 1
6+
changed_when: add_plugin.rc == 0
7+
8+
- name: Install AdoptOpenJDK 8, 11 and 14
9+
shell: >
10+
set -o pipefail && \
11+
source ~/.bashrc && asdf latest java {{ item }} | xargs -i sh -c '. ~/.bashrc && asdf install java {}'
12+
args:
13+
executable: /bin/bash
14+
register: install_other_java
15+
failed_when:
16+
- install_other_java.rc != 0
17+
- '"is already installed" not in install_other_java.stdout'
18+
changed_when: install_other_java.rc == 0
19+
loop:
20+
- adoptopenjdk-8
21+
- adoptopenjdk-11
22+
- adoptopenjdk-14

roles/asdf/tasks/main.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
- name: Check if asdf is already installed
3+
stat:
4+
path: ~/.asdf
5+
register: asdf
6+
7+
- name: Download asdf
8+
git:
9+
repo: https://github.com/asdf-vm/asdf.git
10+
dest: ~/.asdf
11+
version: "{{ version }}"
12+
when: not asdf.stat.exists
13+
14+
- name: Create fish directory if missing
15+
file:
16+
path: ~/.config/fish
17+
state: directory
18+
19+
- name: Add asdf to config.fish
20+
lineinfile:
21+
path: ~/.config/fish/config.fish
22+
line: "source ~/.asdf/asdf.fish"
23+
create: yes
24+
25+
- name: Create fish completions directory if missing
26+
file:
27+
path: ~/.config/fish/completions
28+
state: directory
29+
30+
- name: Check if fish completions need to be set up
31+
stat:
32+
path: ~/.config/fish/completions/asdf.fish
33+
register: completions
34+
35+
- name: Set up fish completions
36+
command: cp ~/.asdf/completions/asdf.fish ~/.config/fish/completions
37+
args:
38+
executable: /bin/bash
39+
when: not completions.stat.exists
40+
41+
- name: Add asdf to bashrc
42+
blockinfile:
43+
path: ~/.bashrc
44+
marker: "# {mark} ANSIBLE MANAGED BLOCK (asdf)"
45+
block: |
46+
. ~/.asdf/asdf.sh
47+
. ~/.asdf/completions/asdf.bash
48+
49+
- name: Set up Java
50+
import_tasks: java.yml
51+

roles/common/tasks/apt.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
packages:
1212
- chromium-browser
1313
- curl
14-
- fish
1514
- flashplugin-installer
1615
- flatpak
1716
- fzf

roles/common/tasks/fish.yml

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

roles/common/tasks/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
- import_tasks: apt.yml
33
- import_tasks: snap.yml
44
- import_tasks: flatpak.yml
5-
- import_tasks: fish.yml
65

76
- name: Add .local/bin to $PATH
87
lineinfile:

roles/dev/meta/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
dependencies:
3+
- role: asdf # noqa 701
4+
vars:
5+
version: v0.8.0
6+
become: no

roles/dev/tasks/asdf.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
- name: Set AdoptOpenJDK 14 as default version
3+
shell: >
4+
set -o pipefail && \
5+
source ~/.bashrc && asdf latest java adoptopenjdk-14 \
6+
| xargs -i sh -c '. ~/.bashrc && asdf install java {} && asdf global java {}'
7+
args:
8+
executable: /bin/bash
9+
register: set_default_java
10+
failed_when:
11+
- set_default_java.rc != 0
12+
- '"is already installed" not in set_default_java.stdout'
13+
changed_when: set_default_java.rc == 0

0 commit comments

Comments
 (0)