Skip to content

Commit

Permalink
cleaning and corrections
Browse files Browse the repository at this point in the history
adding missing before tag

linting'n cleaning
  • Loading branch information
Gildas Cotomale authored and Gildas Cotomale committed Mar 27, 2019
1 parent 23574a7 commit 265b457
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 105 deletions.
11 changes: 10 additions & 1 deletion .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
---
exclude_paths:
- tasks/aix.yml
- tasks/darwin.yml
parseable: true
quiet: true
skip_list:
# [E105] Deprecated module ...
- '105'
# [E204] Lines should be no longer than 160 chars
- '204'
# [E301] Commands should not change things if nothing needs doing
- '301'
use_default_rules: true
verbosity: 1
verbosity: 0
18 changes: 11 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ install:
# install Ansible
- pip install ansible
# add config to pick up roles path
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"
#script:
#- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"
script:
# check the role playbook syntax
- ansible-playbook -i test/inventory tests/test.yml --syntax-check
# run the role playbook for first install
- "ansible-playbook -i test/inventory test/test.yml --connection=local --sudo"
# run the role playbook once to make sure it's idempotent
- ansible-playbook -i tests/inventory tests/test.yml --syntax-check
# install the package a first time
- "ansible-playbook -i tests/inventory tests/test.yml -c local -b"
# Retry to make sure it's idempotent
- >
ansible-playbook -i test/inventory tests/test.yml --connection=local --sudo
ansible-playbook -i tests/inventory tests/test.yml -c local -b
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: passed' && exit 0)
|| (echo 'Idempotence test: failed' && exit 1)
Expand All @@ -27,5 +27,9 @@ install:
- "java -version"
# show java compiler version
- "javac -version"
# Now uninstall the package once
- "ansible-playbook -i tests/inventory tests/test.yml -c local -e 'ojdk_state=absent' -b"
# More fun with Trusty (the default GCE container)
- "ansible-playbook -i tests/inventory tests/test.yml -c local -e 'ojdk_state=absent' -e 'ojdk_repository=ppa:openjdk/ppa' -e 'ojdk_version=6' -b"
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
102 changes: 90 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ and [paid support](https://blogs.oracle.com/java-platform-group/oracle-jdk-relea
- [Installing](#installing)
- [Using](#using)
- [Variables](#variables)
- [Example Playbook](#example-playbook)
- [Examples](#examples)
- [Misc](#misc)
- [Licence](#licence)
- [Authors](#authors)
- [Contributions](#contributions)

## Starting

Expand All @@ -48,7 +49,7 @@ a nearly complete and up to date list.) Also note that available
may vary according to your distribution major release, and numbering differs
too.

| 6 | 7 | 8 | 9 | 10 | 11 | 12 | distribution release |
| v6 | v7 | v8 | v9 | v10 | v11 | v12 | distribution release |
| ------- | ------- | ------- | ------- | ---- | ---- | ---- | -------------------- |
| | `7` | `8` | | | | | Alpine 3.3 / 3.4 / 3.5 / 3.6 / 3.7 / 3.8 /3.9 |
| | `7` | `8` | `9` | | | | Alpine edge |
Expand Down Expand Up @@ -79,8 +80,8 @@ too.
| 1.`6`.0 | | | | | | | ROSA 2012.1 / Entreprise Desktop |
| | 1.`7`.0 | | | | | | ROSA 2014.1 |
| | | 1.`8`.0 | | | | | ROSA 2016.1 |
| | 7-`7` or `7` | `8` | | | | | Slackware 14.1/14.0/13.37/Current |
| 6-`6` | 7-`7` or `7` | 8-`8` or `8` | 9-`9` | | | | Slackware 14.2 |
| | (7-)`7` | `8` | | | | | Slackware 14.1/14.0/13.37/Current |
| 6-`6` | (7-)`7` | (8-)`8` | 9-`9` | | | | Slackware 14.2 |
| `6` | `7` | | | | | | Ubuntu 14.04 LTS (Trusty Thar) |
| | | `8` | `9` | | | | Ubuntu 16.04 LTS (Xenial Xerus) |
| | | `8` | | | `11` | | Ubuntu 18.04 LTS (Bionic Beaver) / 18.10 (Cosmic Cuttlefish) |
Expand Down Expand Up @@ -116,27 +117,50 @@ ansible-galaxy install -p roles -r specs -f

This role uses very few variables:

`ojdk_version` is the JDK version to install.
#### `ojdk_version`

That's the JDK version to install.
Beware, it's neither the package version nor the number in the package's
name! See [table above](#requirements)
This value is mandatory and must be an integer.

`ojdk_state` is the desired _state_ ; and thus is mandatory. It's either:
#### `ojdk_state`

This is the desired _state_ ; and thus is mandatory. It's either:
- `present` to install the package if not already done,
- `absent` to remove the package if still there,
- all other values accepted by the underlying module (e.g. `lastest` to upgrade the package to the latest fix release.)

`ojdk_gpg_uncheck` is a boolean (`no`/`false` or `yes`/`true`) use with some
#### `ojdk_gpg_uncheck`

It's a boolean (`no`/`false` or `yes`/`true`) use with some
packages managers to disable signatures/certificates check. That may be
usefull to disable such check in some rare cases.


`ojdk_repository` is used by few packages managers, to set an additionnal
#### `ojdk_repository`

This later is used by few packages managers, to set an additionnal
repository. This string format (URL or a path) and meaning is OS dependant
then.
ToDo: list different uses in a table.

### Example Playbook
| distribution | mandatory | used for |
| ------------ | --------- | -------- |
| AIX | ✓ | path with AIX packages (required to install) |
| Debian based | ✗ | URL to alternative repository where to found the desired OpenJDK versien |
| FreeBSD | ✗ | override the default ports source directory (package is build from source as no binary is available by default) |
| HP-UX | ✓ | the repository from which install or upgrade the package |
| Mac OSX | ✗ | the absolute path to the package file |
| OpenBSD | ✗ | override the default ports source directory (package is build from source as no binary is available by default) |
| Red Hat based | ✗ | URL to alternative repository where to found the desired OpenJDK versien |
| Solaris | ✓ | location to install the package from (must be an acceptable path for `pkgadd` or a valid repository path with definition found in `/etc/opt/csw/pkgutil.conf`) |
| Windows | ✗ | either the absolute path to the packaged file, or an alternative URL to Chocolatey feed or path to a folder with a `.nupkg` files) |

Note that for some distributions, like CentOS and Ubuntu, it may be useful to
add the repository (either manually or a previous task) before calling this
role. This parameter does very basic setting.

### Examples

Now, you're ready to use it in your playbooks.
Just be aware that operations should be performed as _root_ user
Expand Down Expand Up @@ -168,14 +192,68 @@ To remove JDK5 (example purpose, as this doesn't exist) on dummy host:
```
OK, now, if your control master's inventory is like:
```ini
[dummies]
dummy

[olders]
foo
bar

[newers]
baz
qix

[servlets:children]
olders
newers

[dummies:vars]
ojdk_version = 5
ojdk_state = absent

[olders:vars]
ojdk_version = 8

[newers:vars]
ojdk_version = 11

[servlets:vars]
ojdk_state = present
```
Then your playbook simply become:
```yaml
- hosts: dummy
become: yes
roles:
- openjdk
```
## Misc
[![Build Status](https://travis-ci.org/gilcot/ansible-ojdk.svg?branch=master)](https://travis-ci.org/gilcot/ansible-ojdk)
### License
This role is copyleft under
[GNU GPLv3](https://www.gnu.org/licenses/quick-guide-gplv3.html)
(in [LICENSE](LICENSE) file)
#### Author Information
#### Authors
@github/gilcot is a stanch defender of Free Software and only swears by Ansible system for deployments.
#### Contribution
- Rate this role on Ansible Galaxy
- Submit issues to help improving it
- Request code merge to the code
- Thank the author(s) with:
- a [beer](https://beerpay.io/gilcot/ansible-ojdk),
- a [coffee](buymeacoff.ee/4N0VtGXIj),
- a [ko-fi](Ko-fi.com/gilcot),
- a [penny](https://liberapay.com/gilcot/donate),
- etc.
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
ojdk_version: 'default'
ojdk_version: 8
ojdk_state: 'present'
ojdk_gpg_uncheck: no
#ojdk_repository: ''
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ galaxy_info:
- name: GenericLinux
versions:
- all
- name: HardenedLinux
- name: HardenedBSD
versions:
- all
#- name: IOS
Expand Down
5 changes: 3 additions & 2 deletions tasks/aix.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
## (IBM AIX) ;
## (IBM AIX/VIOS) ; AIX ; APV (Advanced PowerVM) VIOS ;
#@ https://developer.ibm.com/javasdk/2018/04/26/java-standard-edition-ibm-support-statement/
#@ https://openjdk.java.net/projects/ppc-aix-port/
#@ http://mail.openjdk.java.net/pipermail/ppc-aix-port-dev/2015-December/002329.html
#@ htps://sarungpandan.wordpress.com/2016/08/04/install-java-8-on-aix/
#@ http://www-01.ibm.com/support/docview.wss?uid=isg3T1022644
#@ http://www-01.ibm.com/support/docview.wss?uid=isg3T1022693
- name: "Ensure OpenJDK {{ ojdk_version }} is {{ ojdk_state | capitalize }}"
installpp:
#= Ansible 2.8
installp:
name: "openjdk{{ ojdk_version }}"
state: "{{ ojdk_state }}"
repository_path: "{{ ojdk_repository }}"
Expand Down
1 change: 0 additions & 1 deletion tasks/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
name: "openjdk{{ ojdk_version }}"
state: "{{ ojdk_state }}"
update_cache: "{% if ojdk_state in ['present','latest'] %}yes{% else %}no{% endif %}"

63 changes: 11 additions & 52 deletions tasks/darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@
#@ https://apple.stackexchange.com/a/346196
#@ https://sourceforge.net/p/fink/mailman/message/33092430/
- name: "Check if HomBrew is There"
shell: "which brew"
command: "which brew"
register: brew
ignore_errors: yes
- name: "Ensure via Brew that OpenJDK {{ ojdk_version }} is {{ ojdk_state | capitalize }}"
homebrew:
#@ https://github.com/AdoptOpenJDK/homebrew-openjdk
name: "adoptopenjdk{{ ojdk_version }}"
state: "{{ ojdk_state }}"
update_cache: "{% if ojdk_state in ['present','latest'] %}yes{% else %}no{% endif %}"
#update_homebrew: "{% if ojdk_gpg_uncheck %}yes{% else %}no{% endif %}"
update_homebrew: "{% if ojdk_state in ['head','present','latest'] %}yes{% else %}no{% endif %}"
path: "{{ brew.stdout_lines[0] }}"
when: "brew.rc == 0"
when:
- "brew.rc == 0"
- "ojdk_repository is not defined"
- name: "Check if MacPorts is There"
#@ https://apple.stackexchange.com/a/128794
#shell: "command -v port >/dev/null 2>&1"
shell: "command -v port"
command: "command -v port"
register: port
ignore_errors: yes
when: "brew.rc != 0"
- name: "Ensure OpenJDK {{ ojdk_version }} Port is {{ ojdk_state | capitalize }}"
macports:
#@ https://www.macports.org/ports.php?by=category&substr=java&page=4&pagesize=50
Expand All @@ -33,35 +32,7 @@
update_ports: "{% if ojdk_state in ['present','latest'] %}yes{% else %}no{% endif %}"
path: "{{ brew.stdout_lines[0] }}"
when: "brew.rc == 0"
- name: "Check if SDKMan is There"
shell: "which sdk"
register: sdk
ignore_errors: yes
when:
- "brew.rc != 0"
- "port.rc != 0"
- name: "Ensure via SDK that OpenJDK {{ ojdk_version }} is {{ ojdk_state | capitalize }}"
#@ https://sdkman.io/sdks#java
command: "{{ sdk.stdout_lines[0] }} {% if ojdk_state == 'absent' %}un{% endif %}install java {{ ojdk_version }}.0.0-open"
when:
- "sdk.rc == 0"
- "ojdk_state in ['present','absent']"
- name: "Check if Jabba is There"
shell: "which jabba"
register: jabba
ignore_errors: yes
when:
- "brew.rc != 0"
- "port.rc != 0"
- "sdk.rc != 0"
- name: "Ensure via Jabba that OpenJDK {{ ojdk_version }} is {{ ojdk_state | capitalize }}"
#@ https://github.com/shyiko/jabba#Usage
# ToDo: link system
command: "{{ jabba.stdout_lines[0] }} {% if ojdk_state == 'absent' %}un{% endif %}install openjdk@1.{{ ojdk_version }}-0"
when:
- "jabba.rc == 0"
- "ojdk_state in ['present','absent']"
- name: "Ensure {{ ojdk_repository | default('Local OpenJDK .dmg') }} is Present"
- name: "Ensure Homebrew Repository is Present"
#@ https://www.azul.com/downloads/zulu/zulu-mac/
command: "{{ item }}"
#@ https://serverfault.com/a/13632 (use installer ...or copy files)
Expand All @@ -72,25 +43,21 @@
- "installer -pkg {{ ojdk_repository | basename | splitext }}.pkg -target '/'"
- "hdiutil detach /Volumes/{{ ojdk_repository | basename | splitext }}"
when:
- "jabba.rc != 0"
- "brew.rc != 0"
- "port.rc != 0"
- "sdk.rc != 0"
- "ojdk_state == 'present'"
- "ojdk_repository is defined"
- "ojdk_repository is match('.*.dmg')"
- name: "Ensure {{ ojdk_repository | default('Local OpenJDK .pkg') }} is Present"
- name: "Ensure Alternative Repository is Present"
#@ https://aws.amazon.com/correto
command: "installer -pkg {{ ojdk_repository }} -target '/'"
when:
- "jabba.rc != 0"
- "brew.rc != 0"
- "port.rc != 0"
- "sdk.rc != 0"
- "ojdk_state == 'present'"
- "ojdk_repository is defined"
- "ojdk_repository is match('.*.pkg')"
- name: "Ensure {{ ojdk_repository | default('Local OpenJDK .tar.gz') }} is Present"
- name: "Ensure Alternative Image is Installed"
#@ https://www.azul.com/downloads/zulu/zulu-mac/
#@ https://aws.amazon.com/correto
unarchive:
Expand All @@ -100,31 +67,23 @@
- remote_src: yes
#- validate_certs: no
when:
- "jabba.rc != 0"
- "brew.rc != 0"
- "port.rc != 0"
- "sdk.rc != 0"
- "ojdk_state == 'present'"
- "ojdk_repository is defined"
- "ojdk_repository is match('.*.tar.gz')"
- name: "Ensure {{ ojdk_repository | default('Local OpenJDK') }} is Absent"
- name: "Ensure Alternative Image is Removed"
file:
path: "/Library/Java/JavaVirtual/Machines/{{ ojdk_repository | basename | splitext }}"
state: absent
when:
- "jabba.rc != 0"
- "brew.rc != 0"
- "port.rc != 0"
- "sdk.rc != 0"
- "ojdk_state == 'absent'"
- "ojdk_repository is defined"
- "ojdk_repository is match('.*.(tar.gz|dmg)')"
- name: "{{ unsupported_os_vers }}"
fail:
msg: "{{ ojdk_is_unavailable }}"
- import_tasks: 'na.yml'
when:
- "jabba.rc != 0"
- "brew.rc != 0"
- "port.rc != 0"
- "sdk.rc != 0"
- "ojdk_repository is not defined"
10 changes: 10 additions & 0 deletions tasks/debian.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
---
## (Debian) ; AbulÉdu ; Adamantix (Trusted Debian) ; Antemium ; antiX Linux ; Aptosid ; Armbian ; BlackBox ; Cumulus Linux ; CrunchBang ; Daylight Linux ; Debian ; DemoLinux ; Demudi Linux ; Devuan ; Edubuntu ; Elive ; Emmabuntus ; Freeduc-cd ; gNewSense ; gnuLinEx ; Guadalinex ; HandyLinux ; Jolicloud ; Kaella ; Kali Linux ; Knoppix ; Kubuntu ; Linspire ; Lubuntu ; Mint Debian Edition ; Morphix ; MX Linux ; OpenMediaVault ; PingOO ; PrimTux ; Proxmox ; PureOS ; Raspbian ; Skolelinux ; SpartkyLinux ; SteamOS ; Subgraph ; Tails ; Trisquel ; Ubuntu ; Whonix ; Xandros ; Xubuntu ; YunoHost ; ...
- name: "Ensure Alternative Repository is Present"
apt_repository:
#filename: "openjdk{{ ojdk_version }}"
repo: "{{ ojdk_repository }}"
#update_cache: "{% if ojdk_state in ['present','latest'] %}yes{% else %}no{% endif %}"
#state: "{{ ojdk_state }}"
#= Ansible 2.3
#codename: "{{ ansible_distribution_release | lower }}"
validate_certs: "{% if ojdk_gpg_uncheck %}no{% else %}yes{% endif %}"
when: "ojdk_repository is defined"
- name: "Ensure OpenJDK {{ ojdk_version }} is {{ ojdk_state | capitalize }}"
apt:
name: "openjdk-{{ ojdk_version }}-jdk"
Expand Down
Loading

0 comments on commit 265b457

Please sign in to comment.