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

Commit

Permalink
Install java using asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
xalvarez committed Dec 16, 2020
1 parent bbef2ae commit 1037989
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 118 deletions.
2 changes: 0 additions & 2 deletions group_vars/all.yml

This file was deleted.

41 changes: 9 additions & 32 deletions playbook.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
---
- hosts: all
pre_tasks:
- name: Verify Ansible version
assert:
that: "ansible_version.full is version_compare('2.9', '>=')"
fail_msg: This Ansible playbook requires Ansible version >= 2.9.1. Current version is {{ ansible_version.full }}
quiet: yes
tasks:
- name: Enable third-party sources
lineinfile:
path: /etc/apt/sources.list
regexp: '^#\s?(deb\s{1,}.*partner)$'
line: '\g<1>'
backrefs: yes
- name: Update repos and upgrade all packages
apt:
update_cache: yes
upgrade: safe
force_apt_get: yes
- name: Execute role 'common'
import_role:
name: common
- import_tasks: pre_tasks.yml
tags: ['common', 'gnome', 'dev', 'entertainment', 'work']
roles:
- role: common
tags: ['common']
- name: Execute role 'gnome'
import_role:
name: gnome
- role: gnome
tags: ['gnome']
- name: Execute role 'dev'
import_role:
name: dev
- role: dev
tags: ['dev']
- name: Execute role 'entertainment'
import_role:
name: entertainment
- role: entertainment
tags: ['entertainment']
- name: Execute role 'work'
import_role:
name: work
- role: work
tags: ['work']
post_tasks:
- name: Remove useless apt packages and dependencies
apt:
autoremove: yes
Expand Down
25 changes: 25 additions & 0 deletions pre_tasks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Verify Ansible version
assert:
that: "ansible_version.full is version_compare('2.9', '>=')"
fail_msg: This Ansible playbook requires Ansible version >= 2.9.1. Current version is {{ ansible_version.full }}
quiet: yes
- name: Enable third-party sources
lineinfile:
path: /etc/apt/sources.list
regexp: '^#\s?(deb\s{1,}.*partner)$'
line: '\g<1>'
backrefs: yes
- name: Update repos and upgrade all packages
apt:
update_cache: yes
upgrade: safe
force_apt_get: yes
- name: Install fish shell
apt:
name: fish
force_apt_get: yes
- name: Set current user's default shell to fish
user:
name: "{{ ansible_user }}"
shell: /usr/bin/fish
22 changes: 22 additions & 0 deletions roles/asdf/tasks/java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Add asdf java plugin
shell: . ~/.bashrc && asdf plugin add java
register: add_plugin
failed_when: add_plugin.rc == 1
changed_when: add_plugin.rc == 0

- name: Install AdoptOpenJDK 8, 11 and 14
shell: >
set -o pipefail && \
source ~/.bashrc && asdf latest java {{ item }} | xargs -i sh -c '. ~/.bashrc && asdf install java {}'
args:
executable: /bin/bash
register: install_other_java
failed_when:
- install_other_java.rc != 0
- '"is already installed" not in install_other_java.stdout'
changed_when: install_other_java.rc == 0
loop:
- adoptopenjdk-8
- adoptopenjdk-11
- adoptopenjdk-14
51 changes: 51 additions & 0 deletions roles/asdf/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
- name: Check if asdf is already installed
stat:
path: ~/.asdf
register: asdf

- name: Download asdf
git:
repo: https://github.com/asdf-vm/asdf.git
dest: ~/.asdf
version: "{{ version }}"
when: not asdf.stat.exists

- name: Create fish directory if missing
file:
path: ~/.config/fish
state: directory

- name: Add asdf to config.fish
lineinfile:
path: ~/.config/fish/config.fish
line: "source ~/.asdf/asdf.fish"
create: yes

- name: Create fish completions directory if missing
file:
path: ~/.config/fish/completions
state: directory

- name: Check if fish completions need to be set up
stat:
path: ~/.config/fish/completions/asdf.fish
register: completions

- name: Set up fish completions
command: cp ~/.asdf/completions/asdf.fish ~/.config/fish/completions
args:
executable: /bin/bash
when: not completions.stat.exists

- name: Add asdf to bashrc
blockinfile:
path: ~/.bashrc
marker: "# {mark} ANSIBLE MANAGED BLOCK (asdf)"
block: |
. ~/.asdf/asdf.sh
. ~/.asdf/completions/asdf.bash
- name: Set up Java
import_tasks: java.yml

1 change: 0 additions & 1 deletion roles/common/tasks/apt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
packages:
- chromium-browser
- curl
- fish
- flashplugin-installer
- flatpak
- fzf
Expand Down
6 changes: 0 additions & 6 deletions roles/common/tasks/fish.yml

This file was deleted.

1 change: 0 additions & 1 deletion roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
- import_tasks: apt.yml
- import_tasks: snap.yml
- import_tasks: flatpak.yml
- import_tasks: fish.yml

- name: Add .local/bin to $PATH
lineinfile:
Expand Down
6 changes: 6 additions & 0 deletions roles/dev/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
dependencies:
- role: asdf # noqa 701
vars:
version: v0.8.0
become: no
13 changes: 13 additions & 0 deletions roles/dev/tasks/asdf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Set AdoptOpenJDK 14 as default version
shell: >
set -o pipefail && \
source ~/.bashrc && asdf latest java adoptopenjdk-14 \
| xargs -i sh -c '. ~/.bashrc && asdf install java {} && asdf global java {}'
args:
executable: /bin/bash
register: set_default_java
failed_when:
- set_default_java.rc != 0
- '"is already installed" not in set_default_java.stdout'
changed_when: set_default_java.rc == 0
2 changes: 1 addition & 1 deletion roles/dev/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- import_tasks: snap.yml
- import_tasks: apt.yml

- import_tasks: sdkman.yml
- import_tasks: asdf.yml
become: no

- name: Check if Jetbrains Toolbox is already installed
Expand Down
37 changes: 0 additions & 37 deletions roles/dev/tasks/sdkman.yml

This file was deleted.

3 changes: 0 additions & 3 deletions roles/dev/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
adoptopenjdk14:
version: 14.0.2.hs-adpt

docker_compose:
version: 1.27.2

Expand Down
6 changes: 6 additions & 0 deletions roles/work/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
dependencies:
- role: asdf # noqa 701
vars:
version: v0.8.0
become: no
13 changes: 13 additions & 0 deletions roles/work/tasks/asdf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Set AdoptOpenJDK 11 as default version
shell: >
set -o pipefail && \
source ~/.bashrc && asdf latest java adoptopenjdk-11 \
| xargs -i sh -c '. ~/.bashrc && asdf install java {} && asdf global java {}'
args:
executable: /bin/bash
register: set_default_java
failed_when:
- set_default_java.rc != 0
- '"is already installed" not in set_default_java.stdout'
changed_when: set_default_java.rc == 0
2 changes: 1 addition & 1 deletion roles/work/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- import_tasks: terraform.yml
become: no

- import_tasks: sdkman.yml
- import_tasks: asdf.yml
become: no

- import_tasks: payara.yml
Expand Down
34 changes: 0 additions & 34 deletions roles/work/tasks/sdkman.yml

This file was deleted.

0 comments on commit 1037989

Please sign in to comment.