├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── Vagrantfile ├── circle.yml ├── defaults └── main.yml ├── files ├── check-java-version.sh ├── delete-messy-rpm-files.sh └── uninstall-messy-jdk-packages.sh ├── meta └── main.yml ├── prefetch.yml ├── tasks ├── fetch.yml ├── fetch_jce.yml ├── install.yml ├── install_jce.yml ├── main.yml ├── set-role-variables.yml ├── use-dmg.yml ├── use-rpm.yml └── use-tarball.yml ├── templates └── java_home.sh.j2 ├── test.yml └── test ├── Dockerfile-centos6 ├── Dockerfile-centos7 ├── Dockerfile-debian7 ├── Dockerfile-debian8 ├── Dockerfile-prefetch-rpm ├── Dockerfile-prefetch-tarball ├── Dockerfile-ubuntu12.04 ├── Dockerfile-ubuntu14.04 └── travis ├── before_install.sh └── script.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | *.retry 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: true 2 | os: 3 | - linux 4 | - osx 5 | 6 | services: 7 | - docker 8 | 9 | before_install: 10 | - test/travis/before_install.sh 11 | 12 | script: 13 | - test/travis/script.sh 14 | 15 | notifications: 16 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ 17 | 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014-2016 William Yeh 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | williamyeh.oracle-java for Ansible Galaxy 3 | ============ 4 | 5 | [![Build Status](https://travis-ci.org/William-Yeh/ansible-oracle-java.svg?branch=master)](https://travis-ci.org/William-Yeh/ansible-oracle-java) [![Circle CI](https://circleci.com/gh/William-Yeh/ansible-oracle-java.svg?style=shield)](https://circleci.com/gh/William-Yeh/ansible-oracle-java) 6 | 7 | ## Summary 8 | 9 | Role name in Ansible Galaxy: **[williamyeh.oracle-java](https://galaxy.ansible.com/williamyeh/oracle-java/)** 10 | 11 | This Ansible role has the following features for Oracle JDK: 12 | 13 | - Install JDK 7 or 8 version. 14 | - Install optional Java Cryptography Extensions (JCE) 15 | - Install for CentOS, Debian/Ubuntu, SUSE, and Mac OS X families. 16 | 17 | If you prefer OpenJDK, try alternatives such as [geerlingguy.java](https://galaxy.ansible.com/geerlingguy/java/) or [smola.java](https://galaxy.ansible.com/smola/java/). 18 | 19 | 20 | ## Role Variables 21 | 22 | ### Mandatory variables 23 | 24 | None. 25 | 26 | ### Optional variables 27 | 28 | 29 | User-configurable defaults: 30 | 31 | ```yaml 32 | # which version? 33 | java_version: 8 34 | 35 | # which subversion? 36 | java_subversion: 112 37 | 38 | # which directory to put the download file? 39 | java_download_path: /tmp 40 | 41 | # rpm/tar.gz file location: 42 | # - true: download from Oracle on-the-fly; 43 | # - false: copy from `{{ playbook_dir }}/files` on the control machine. 44 | java_download_from_oracle: true 45 | 46 | # remove temporary downloaded files? 47 | java_remove_download: true 48 | 49 | # set $JAVA_HOME? 50 | java_set_javahome: false 51 | 52 | # install JCE? 53 | java_install_jce: false 54 | ``` 55 | 56 | For other configurable internals, read `tasks/set-role-variables.yml` file; for example, supported `java_version`/`java_subversion` combinations. 57 | 58 | If you want to install a Java release which is not supported out-of-the-box, you have to specify the corresponding Java build number in the variable `java_build` in addition to `java_version` and `java_subversion`, e.g. 59 | ```yaml 60 | --- 61 | - hosts: all 62 | 63 | roles: 64 | - williamyeh.oracle-java 65 | 66 | vars: 67 | java_version: 8 68 | java_subversion: 91 69 | java_build: 14 70 | ``` 71 | 72 | 73 | ### Customized variables, if absolutely necessary 74 | 75 | If you have a pre-downloaded `jdk_tarball_file` whose filename cannot be inferred successfully by `tasks/set-role-variables.yml`, you may specify it explicitly: 76 | 77 | ```yaml 78 | # Specify the pre-fetch filename (without tailing .tar.gz or .rpm or .dmg); 79 | # used in conjunction with `java_download_from_oracle: false`. 80 | 81 | jdk_tarball_file 82 | 83 | # For example, if you have a `files/jdk-7u79-linux-x64.tar.gz` locally, 84 | # but the filename cannot be inferred successfully by `tasks/set-role-variables.yml`, 85 | # you may specify the following variables in your playbook: 86 | # 87 | # java_version: 7 88 | # java_subversion: 79 89 | # java_download_from_oracle: false 90 | # jdk_tarball_file: jdk-7u79-linux-x64 91 | # 92 | ``` 93 | 94 | 95 | ## Usage 96 | 97 | 98 | ### Step 1: add role 99 | 100 | Add role name `williamyeh.oracle-java` to your playbook file. 101 | 102 | 103 | ### Step 2: add variables 104 | 105 | Set vars in your playbook file. 106 | 107 | Simple example: 108 | 109 | ```yaml 110 | --- 111 | # file: simple-playbook.yml 112 | 113 | - hosts: all 114 | 115 | roles: 116 | - williamyeh.oracle-java 117 | 118 | vars: 119 | java_version: 8 120 | ``` 121 | 122 | 123 | ### (Optionally) pre-fetch .rpm and .tar.gz files 124 | 125 | For some reasons, you may want to pre-fetch .rpm and .tar.gz files *before the execution of this role*, instead of downloading from Oracle on-the-fly. 126 | 127 | To do this, put the file on the `{{ playbook_dir }}/files` directory in advance, and then set the `java_download_from_oracle` variable to `false`: 128 | 129 | ```yaml 130 | --- 131 | # file: prefetch-playbook.yml 132 | 133 | - hosts: all 134 | 135 | roles: 136 | - williamyeh.oracle-java 137 | 138 | vars: 139 | java_version: 8 140 | java_download_from_oracle: false 141 | ``` 142 | 143 | 144 | 145 | 146 | 147 | 148 | ## Dependencies 149 | 150 | 151 | ## License 152 | 153 | Licensed under the Apache License V2.0. See the [LICENSE file](LICENSE) for details. 154 | 155 | 156 | ## History 157 | 158 | Rewritten from my pre-Galaxy version: [server-config-template](https://github.com/William-Yeh/server-config-template). 159 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | 3 | # main & default: normal OS series... 4 | config.vm.define "main", primary: true do |node| 5 | node.vm.box = "ubuntu/trusty64" 6 | #node.vm.box = "ubuntu/precise64" 7 | #node.vm.box = "debian/jessie64" 8 | #node.vm.box = "debian/wheezy64" 9 | #node.vm.box = "bento/centos-7.2" 10 | #node.vm.box = "bento/centos-6.7" 11 | 12 | node.vm.provision "ansible" do |ansible| 13 | ansible.playbook = "test.yml" 14 | #ansible.playbook = "prefetch.yml" 15 | ansible.sudo = true 16 | #ansible.verbose = "vvv" 17 | end 18 | end 19 | 20 | 21 | # docker: for auto build & testing (e.g., Travis CI) 22 | config.vm.define "docker" do |node| 23 | node.vm.box = "williamyeh/ubuntu-trusty64-docker" 24 | 25 | node.vm.provision "shell", inline: <<-SHELL 26 | cd /vagrant 27 | docker build -f test/Dockerfile-ubuntu14.04 -t java_trusty . 28 | docker build -f test/Dockerfile-ubuntu12.04 -t java_precise . 29 | docker build -f test/Dockerfile-debian8 -t java_jessie . 30 | docker build -f test/Dockerfile-debian7 -t java_wheezy . 31 | docker build -f test/Dockerfile-centos7 -t java_centos7 . 32 | docker build -f test/Dockerfile-centos6 -t java_centos6 . 33 | SHELL 34 | end 35 | 36 | end 37 | 38 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | services: 3 | - docker 4 | 5 | dependencies: 6 | override: 7 | - docker info 8 | - docker version 9 | 10 | - echo "==> Prefetching .rpm and .tar.gz to `{{ playbook_dir }}/files`..." 11 | - docker build -f test/Dockerfile-prefetch-rpm -t java_prefetch_rpm . 12 | - docker run -v $(pwd):/data java_prefetch_rpm 13 | - docker build -f test/Dockerfile-prefetch-tarball -t java_prefetch_tarball . 14 | - docker run -v $(pwd):/data java_prefetch_tarball 15 | - sed -i -e 's/^\(java_download_from_oracle:\).*$/\1 false/' defaults/main.yml 16 | 17 | - echo "==> Building test cases..." 18 | - docker build -f test/Dockerfile-ubuntu14.04 -t java_trusty . 19 | - docker build -f test/Dockerfile-ubuntu12.04 -t java_precise . 20 | - docker build -f test/Dockerfile-debian8 -t java_jessie . 21 | - docker build -f test/Dockerfile-debian7 -t java_wheezy . 22 | - docker build -f test/Dockerfile-centos7 -t java_centos7 . 23 | - docker build -f test/Dockerfile-centos6 -t java_centos6 . 24 | 25 | test: 26 | override: 27 | - docker run -i java_trusty 2> result-ubuntu14.04 28 | - docker run -i java_precise 2> result-ubuntu12.04 29 | - docker run -i java_jessie 2> result-debian8 30 | - docker run -i java_wheezy 2> result-debian7 31 | - docker run -i java_centos7 2> result-centos7 32 | - docker run -i java_centos6 2> result-centos6 33 | 34 | - echo "==> Validating the test results..." 35 | - sh -c "[ -s result-ubuntu14.04 ]" 36 | - sh -c "[ -s result-ubuntu12.04 ]" 37 | - sh -c "[ -s result-debian8 ]" 38 | - sh -c "[ -s result-debian7 ]" 39 | - sh -c "[ -s result-centos7 ]" 40 | - sh -c "[ -s result-centos6 ]" 41 | 42 | - echo "==> Saving artifacts to CircleCI for reference..." 43 | - cp files/jdk-* $CIRCLE_ARTIFACTS 44 | - cp files/*.zip $CIRCLE_ARTIFACTS 45 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # 4 | # variables needed to be defined in user's playbook 5 | # 6 | 7 | 8 | 9 | # 10 | # user-configurable defaults 11 | # 12 | 13 | java_version: 8 14 | java_subversion: 112 15 | 16 | java_download_path: /tmp 17 | java_download_from_oracle: true 18 | java_remove_download: true 19 | java_install_jce: false 20 | 21 | java_set_javahome: false 22 | -------------------------------------------------------------------------------- /files/check-java-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # simple script to query the existance of specific Oracle jdk executable, if installed. 3 | # 4 | # @return: JSON string : { "found": true/false, "not_found": true/false } 5 | # 6 | 7 | PACKAGE="\"$1\"" 8 | 9 | line=$(java -version 2>&1 | grep $PACKAGE | grep -iv openjdk | wc -l) 10 | #echo $line 11 | 12 | 13 | if [[ $line =~ 0 ]]; then 14 | echo '{ "found": false , "not_found": true }' 15 | 16 | else 17 | echo '{ "found": true , "not_found": false }' 18 | 19 | fi 20 | -------------------------------------------------------------------------------- /files/delete-messy-rpm-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # simple script to delete messy .rpm files generated by Oracle(Sun) JDK; 3 | # esp. sun-javadb series. 4 | # 5 | 6 | 7 | path_prefix=$1 8 | 9 | messy_files=( 10 | 'sun-javadb-*.rpm' 11 | '*-linux-amd64.rpm' 12 | ); 13 | 14 | 15 | for item in "${messy_files[@]}" 16 | do 17 | echo $item 18 | rm -f --interactive=never $path_prefix/$item 19 | done 20 | 21 | exit 0 22 | -------------------------------------------------------------------------------- /files/uninstall-messy-jdk-packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # simple script to uninstall messy packages provided by Oracle(Sun) JDK; 3 | # esp. sun-javadb series. 4 | # 5 | 6 | 7 | messy_packages=( 8 | 'sun-javadb-core' 9 | 'sun-javadb-client' 10 | 'sun-javadb-docs' 11 | 'sun-javadb-javadoc' 12 | 'sun-javadb-demo' 13 | 'sun-javadb-common' 14 | ); 15 | 16 | 17 | for pkg in "${messy_packages[@]}" 18 | do 19 | echo $pkg 20 | rpm -e $pkg 21 | done 22 | 23 | exit 0 24 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # nginx/meta/main.yml 3 | 4 | galaxy_info: 5 | author: williamyeh 6 | description: Oracle JDK 7/8 for CentOS/Debian/Ubuntu/Suse/MacOSX 7 | license: Apache 8 | 9 | min_ansible_version: 2.0.0 10 | 11 | platforms: 12 | - name: Ubuntu 13 | versions: 14 | - precise 15 | - trusty 16 | - name: Debian 17 | versions: 18 | - wheezy 19 | - jessie 20 | - name: EL 21 | versions: 22 | - 6 23 | - 7 24 | - name: opensuse 25 | versions: 26 | - all 27 | - name: SLES 28 | versions: 29 | - all 30 | - name: Darwin 31 | versions: 32 | - all 33 | 34 | galaxy_tags: 35 | - development 36 | - system 37 | - java 38 | - jdk 39 | - jvm 40 | 41 | dependencies: [] 42 | -------------------------------------------------------------------------------- /prefetch.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | become: yes 3 | become_method: sudo 4 | tasks: 5 | - include: tasks/set-role-variables.yml 6 | - name: fetch .rpm or .tar.gz files from Oracle site 7 | include: tasks/fetch.yml 8 | - name: fetch JCE files from Oracle site 9 | include: tasks/fetch_jce.yml 10 | 11 | #vars_files: 12 | # - 'defaults/main.yml' 13 | 14 | vars: 15 | - java_version: 8 16 | - java_subversion: 112 17 | - java_download_path: /tmp 18 | - java_install_jce: true 19 | -------------------------------------------------------------------------------- /tasks/fetch.yml: -------------------------------------------------------------------------------- 1 | # 2 | # fetch .rpm or .tar.gz files 3 | # 4 | 5 | - name: get JDK tarball (as RPM file) 6 | get_url: 7 | url: "{{ jdk_tarball_url }}.rpm" 8 | headers: 'Cookie:oraclelicense=accept-securebackup-cookie' 9 | dest: "{{ java_download_path }}/{{ jdk_tarball_file }}.rpm" 10 | when: (ansible_pkg_mgr == "yum" or ansible_pkg_mgr == "zypper") and ansible_os_family != 'Darwin' 11 | 12 | 13 | - name: get JDK tarball (as tar.gz file) 14 | get_url: 15 | url: "{{ jdk_tarball_url }}.tar.gz" 16 | headers: 'Cookie:oraclelicense=accept-securebackup-cookie' 17 | dest: "{{ java_download_path }}/{{ jdk_tarball_file }}.tar.gz" 18 | when: ansible_pkg_mgr != "yum" and ansible_pkg_mgr != "zypper" and ansible_os_family != 'Darwin' 19 | 20 | - name: get JDK package (as Mac OS X .dmg) 21 | get_url: 22 | url: "{{ jdk_tarball_url }}.dmg" 23 | headers: 'Cookie:oraclelicense=accept-securebackup-cookie' 24 | dest: "{{ java_download_path }}/{{ jdk_tarball_file }}.dmg" 25 | when: ansible_os_family == 'Darwin' 26 | 27 | -------------------------------------------------------------------------------- /tasks/fetch_jce.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Script for fetching Java Cryptography Extensions (JCE) 3 | 4 | - name: get JCE 5 | get_url: 6 | url: "{{ jce_zip_url }}" 7 | headers: 'Cookie:oraclelicense=accept-securebackup-cookie' 8 | dest: "{{ java_download_path }}/{{ jce_zip_file }}" 9 | -------------------------------------------------------------------------------- /tasks/install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: tasks/install.yml 3 | # Top-level installer for Oracle JDK. 4 | # 5 | 6 | 7 | - name: fetch .rpm or .tar.gz files from Oracle site 8 | include: fetch.yml 9 | when: java_download_from_oracle 10 | 11 | - block: 12 | 13 | - name: copy RPM from local 14 | copy: 15 | src: "{{ playbook_dir }}/files/{{ jdk_tarball_file }}.rpm" 16 | dest: "{{ java_download_path }}/{{ jdk_tarball_file }}.rpm" 17 | when: ansible_pkg_mgr == "yum" or ansible_pkg_mgr == "zypper" 18 | 19 | - name: copy tarball from local 20 | copy: 21 | src: "{{ playbook_dir }}/files/{{ jdk_tarball_file }}.tar.gz" 22 | dest: "{{ java_download_path }}/{{ jdk_tarball_file }}.tar.gz" 23 | when: ansible_pkg_mgr != "yum" and ansible_pkg_mgr != "zypper" 24 | 25 | when: not java_download_from_oracle 26 | 27 | 28 | 29 | - name: delegate to RPM installation process 30 | include: use-rpm.yml 31 | when: (ansible_pkg_mgr == "yum" or ansible_pkg_mgr == "zypper") and ansible_os_family != 'Darwin' 32 | 33 | - name: delegate to raw tarball installation process 34 | include: use-tarball.yml 35 | when: ansible_pkg_mgr != "yum" and ansible_pkg_mgr != "zypper" and ansible_os_family != 'Darwin' 36 | 37 | - name: delegate to Mac OS X dmg installation 38 | include: use-dmg.yml 39 | when: ansible_os_family == 'Darwin' 40 | 41 | - block: 42 | 43 | - name: make sure /etc/profile.d exists 44 | file: path=/etc/profile.d state=directory 45 | 46 | - name: export JAVA_HOME 47 | template: 48 | src: ../templates/java_home.sh.j2 49 | dest: /etc/profile.d/java_home.sh 50 | mode: "a+x" 51 | 52 | when: java_set_javahome 53 | 54 | 55 | 56 | - block: 57 | 58 | # No link creation is necessary on Mac OS X -- 59 | # the package installer automatically creates symlinks in /usr/bin. 60 | 61 | - name: link "{{ java_install_dir }}/{{ java_default_link_name }}" 62 | file: 63 | dest: "{{ java_install_dir }}/{{ java_default_link_name }}" 64 | src: "{{ java_install_dir }}/jdk{{ jdk_version }}" 65 | state: link 66 | 67 | - name: alternatives link for "java" 68 | alternatives: 69 | name: java 70 | link: /usr/bin/java 71 | path: "{{ java_install_dir }}/{{ java_default_link_name }}/bin/java" 72 | 73 | - name: alternatives link for "javac" 74 | alternatives: 75 | name: javac 76 | link: /usr/bin/javac 77 | path: "{{ java_install_dir }}/{{ java_default_link_name }}/bin/javac" 78 | 79 | - name: alternatives link for "jar" 80 | alternatives: 81 | name: jar 82 | link: /usr/bin/jar 83 | path: "{{ java_install_dir }}/{{ java_default_link_name }}/bin/jar" 84 | 85 | - name: check if "java_sdk" target exists 86 | stat: path=/usr/lib/jvm/java 87 | register: filecheck 88 | 89 | - name: alternatives link for "java_sdk" 90 | alternatives: 91 | name: java_sdk 92 | link: /usr/lib/jvm/java 93 | path: "{{ java_install_dir }}/{{ java_default_link_name }}" 94 | when: filecheck and filecheck.stat.exists 95 | 96 | when: ansible_os_family != "Darwin" 97 | 98 | 99 | 100 | - name: remove temporary downloaded files, if requested 101 | file: path={{ item }} state=absent 102 | with_items: 103 | - "{{ java_download_path }}/{{ jdk_tarball_file }}.rpm" 104 | - "{{ java_download_path }}/{{ jdk_tarball_file }}.tar.gz" 105 | - "{{ java_download_path }}/{{ jdk_tarball_file }}.dmg" 106 | - "{{ java_download_path }}/check-tarball-installed.sh" 107 | ignore_errors: true 108 | when: java_remove_download 109 | -------------------------------------------------------------------------------- /tasks/install_jce.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Installation script for Java Cryptography Extensions (JCE) 3 | 4 | - block: 5 | - name: Find Java Home in Mac 6 | shell: /usr/libexec/java_home 7 | register: java_home_cmd 8 | changed_when: false 9 | - name: Set java_home 10 | set_fact: java_home={{ java_home_cmd.stdout }} 11 | when: java_home_cmd.skipped is not defined and java_home is not defined 12 | when: ansible_os_family == "Darwin" 13 | 14 | - block: 15 | - name: Make sure 'which' is installed 16 | package: name=which state=present 17 | when: ansible_os_family == "RedHat" 18 | - name: Find Java Home in Linux 19 | shell: dirname $(dirname $(readlink -e $(which java))) 20 | register: java_home_cmd 21 | changed_when: false 22 | - name: Set java_home 23 | set_fact: java_home={{ java_home_cmd.stdout }} 24 | when: java_home_cmd.skipped is not defined and java_home is not defined 25 | when: ansible_os_family != "Darwin" 26 | 27 | - name: Check if JCE is already installed 28 | shell: "{{ java_home }}/bin/jrunscript -e 'print (javax.crypto.Cipher.getMaxAllowedKeyLength(\"RC5\") >= 256);'" 29 | changed_when: false 30 | ignore_errors: true 31 | register: jce_check 32 | 33 | - block: 34 | - include: fetch_jce.yml 35 | when: java_download_from_oracle 36 | 37 | - name: copy JCE zip from local 38 | copy: 39 | src: "{{ playbook_dir }}/files/{{ jce_zip_file }}" 40 | dest: "{{ java_download_path }}/{{ jce_zip_file }}" 41 | when: not java_download_from_oracle 42 | 43 | - name: install unzip 44 | package: name=unzip state=present 45 | when: ansible_os_family != "Darwin" 46 | 47 | - name: unzip JCE 48 | unarchive: 49 | src: "{{ java_download_path }}/{{ jce_zip_file }}" 50 | dest: "{{ java_download_path }}/" 51 | copy: no 52 | creates: "{{ java_download_path }}/{{ jce_zip_folder }}" 53 | 54 | - name: install JCE policies 55 | copy: 56 | src: "{{ java_download_path }}/{{ jce_zip_folder }}/{{ item }}" 57 | dest: "{{ java_home }}/jre/lib/security/{{ item }}" 58 | remote_src: True 59 | mode: 0664 60 | become: true 61 | with_items: 62 | - local_policy.jar 63 | - US_export_policy.jar 64 | 65 | - name: remove temporary downloaded JCE files, if requested 66 | file: path={{ item }} state=absent 67 | with_items: 68 | - "{{ java_download_path }}/{{ jce_zip_file }}" 69 | - "{{ java_download_path }}/{{ jce_zip_folder }}" 70 | ignore_errors: true 71 | when: java_remove_download 72 | when: jce_check.stdout == "false" 73 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: tasks/main.yml 3 | # Top-level installer for Oracle JDK. 4 | # 5 | 6 | - name: precondition - java_version 7 | fail: msg="ERROR - required variable 'java_version' missing." 8 | when: java_version is not defined 9 | 10 | - name: precondition - java_subversion 11 | fail: msg="ERROR - required variable 'java_subversion' missing." 12 | when: java_subversion is not defined 13 | 14 | - name: precondition - java_install_jce 15 | fail: msg="ERROR - required variable 'java_install_jce' missing." 16 | when: java_install_jce is not defined 17 | 18 | - include: set-role-variables.yml 19 | 20 | 21 | 22 | - name: install libselinux-python binary for Ansible to work 23 | yum: name=libselinux-python state=present 24 | when: ansible_pkg_mgr == "yum" 25 | 26 | - name: copy scripts to server 27 | copy: src="../files/check-java-version.sh" dest="{{ java_download_path }}/" mode="a+x" 28 | 29 | - name: check if specific version of Oracle JDK is installed? 30 | shell: LC_ALL="en_US.UTF-8" {{ java_download_path }}/check-java-version.sh "{{ jdk_version }}" 31 | register: jdk_info 32 | changed_when: false 33 | failed_when: jdk_info.rc > 0 34 | 35 | #- debug: var=jdk_info 36 | 37 | - include: install.yml 38 | when: (jdk_info.stdout|from_json).not_found 39 | 40 | - name: delegate to JCE zip installation process 41 | include: install_jce.yml 42 | when: java_install_jce 43 | -------------------------------------------------------------------------------- /tasks/set-role-variables.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: tasks/set-role-variables.yml 3 | # set necessary role variables. 4 | # 5 | 6 | 7 | - name: set general internal vars 8 | set_fact: 9 | jdk_version: "1.{{ java_version }}.0_{{ java_subversion }}" 10 | 11 | 12 | # 13 | # platform-specific variables 14 | # 15 | 16 | - name: set java architecture 17 | set_fact: 18 | jdk_arch: "{{ 'i586' if ansible_architecture == 'i386' else 'x64' }}" 19 | 20 | - name: set java OS for Linux 21 | set_fact: 22 | jdk_os: linux 23 | when: ansible_system == 'Linux' 24 | 25 | - name: set java OS for Mac OS X 26 | set_fact: 27 | jdk_os: macosx 28 | when: ansible_os_family == 'Darwin' 29 | 30 | 31 | # 32 | # version-specific variables 33 | # 34 | - name: set internal vars for 1.8.0_112 35 | set_fact: 36 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b15" 37 | when: java_version == 8 and java_subversion == 112 38 | 39 | - name: set internal vars for 1.8.0_111 40 | set_fact: 41 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b14" 42 | when: java_version == 8 and java_subversion == 111 43 | 44 | - name: set internal vars for 1.8.0_102 45 | set_fact: 46 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b14" 47 | when: java_version == 8 and java_subversion == 102 48 | 49 | - name: set internal vars for 1.8.0_101 50 | set_fact: 51 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b13" 52 | when: java_version == 8 and java_subversion == 101 53 | 54 | - name: set internal vars for 1.8.0_92 or 1.8.0_91 55 | set_fact: 56 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b14" 57 | when: java_version == 8 and (java_subversion == 92 or java_subversion == 91) 58 | 59 | - name: set internal vars for 1.8.0_77 60 | set_fact: 61 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b03" 62 | when: java_version == 8 and java_subversion == 77 63 | 64 | - name: set internal vars for 1.8.0_74 65 | set_fact: 66 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b02" 67 | when: java_version == 8 and java_subversion == 74 68 | 69 | - name: set internal vars for 1.8.0_73 70 | set_fact: 71 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b02" 72 | when: java_version == 8 and java_subversion == 73 73 | 74 | - name: set internal vars for 1.8.0_72 75 | set_fact: 76 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b15" 77 | when: java_version == 8 and java_subversion == 72 78 | 79 | - name: set internal vars for 1.8.0_66 80 | set_fact: 81 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b17" 82 | when: java_version == 8 and java_subversion == 66 83 | 84 | - name: set internal vars for 1.8.0_65 85 | set_fact: 86 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b17" 87 | when: java_version == 8 and java_subversion == 65 88 | 89 | - name: set internal vars for 1.8.0_60 90 | set_fact: 91 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b27" 92 | when: java_version == 8 and java_subversion == 60 93 | 94 | - name: set internal vars for 1.8.0_51 95 | set_fact: 96 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b16" 97 | when: java_version == 8 and java_subversion == 51 98 | 99 | - name: set internal vars for 1.8.0_45 100 | set_fact: 101 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b14" 102 | when: java_version == 8 and java_subversion == 45 103 | 104 | - name: set internal vars for 1.8.0_31 105 | set_fact: 106 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b13" 107 | when: java_version == 8 and java_subversion == 31 108 | 109 | - name: set internal vars for 1.7.0_80 110 | set_fact: 111 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b15" 112 | when: java_version == 7 and java_subversion == 80 113 | 114 | - name: set internal vars for 1.7.0_75 115 | set_fact: 116 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b13" 117 | when: java_version == 7 and java_subversion == 75 118 | 119 | - name: set internal vars for generic Java version 120 | set_fact: 121 | jdk_version_detail: "{{ java_version }}u{{ java_subversion }}-b{{ java_build }}" 122 | when: jdk_version_detail is not defined and java_build is defined 123 | 124 | 125 | - name: compose filename, if necessary 126 | set_fact: 127 | jdk_tarball_file: "jdk-{{ java_version }}u{{ java_subversion }}-{{ jdk_os }}-{{ jdk_arch }}" 128 | when: jdk_tarball_file is not defined 129 | 130 | - name: compose url for downloading file, if necessary 131 | set_fact: 132 | jdk_tarball_url: "http://download.oracle.com/otn-pub/java/jdk/{{ jdk_version_detail }}/{{ jdk_tarball_file }}" 133 | when: jdk_version_detail is defined 134 | 135 | 136 | # 137 | # JCE variables 138 | # 139 | 140 | - name: set JCE variables for java 7 141 | set_fact: 142 | jce_zip_file: "UnlimitedJCEPolicyJDK{{ java_version }}.zip" 143 | jce_zip_folder: "UnlimitedJCEPolicy" 144 | when: java_version == 7 145 | 146 | - name: set JCE variables for java 8 147 | set_fact: 148 | jce_zip_file: "jce_policy-{{ java_version }}.zip" 149 | jce_zip_folder: "UnlimitedJCEPolicyJDK{{ java_version }}" 150 | when: java_version == 8 151 | 152 | - name: set JCE download file 153 | set_fact: 154 | jce_zip_url: "http://download.oracle.com/otn-pub/java/jce/{{ java_version }}/{{ jce_zip_file }}" 155 | 156 | 157 | # 158 | # directories 159 | # 160 | 161 | - name: set java installation directory on Debian platforms 162 | set_fact: 163 | java_install_dir: /usr/lib/jvm 164 | java_default_link_name: default-java 165 | java_home: /usr/lib/jvm/default-java 166 | when: ansible_os_family == "Debian" 167 | 168 | - name: set java installation directory on Mac OS X 169 | set_fact: 170 | # The Java installation directory on Mac OS X is determined by the package itself. 171 | java_install_dir: /no_such_directory 172 | java_default_link_name: default 173 | when: ansible_os_family == "Darwin" 174 | 175 | - name: set java installation directory on non-Debian platforms 176 | set_fact: 177 | java_install_dir: /usr/java 178 | java_default_link_name: default 179 | java_home: /usr/java/default 180 | when: ansible_os_family != "Debian" and ansible_os_family != "Darwin" 181 | -------------------------------------------------------------------------------- /tasks/use-dmg.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: use-tarball.yml 3 | # install Oracle JDK 1.x on Mac OS X 4 | # 5 | # See: # https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html 6 | # 7 | 8 | - name: mount the downloaded dmg 9 | shell: hdiutil attach "{{ java_download_path }}/{{ jdk_tarball_file }}.dmg" 10 | 11 | - name: install the pkg file from the dmg 12 | become: yes 13 | become_method: sudo 14 | shell: > 15 | installer 16 | -pkg "/Volumes/JDK {{ java_version }} Update {{ java_subversion }}/JDK {{ java_version }} Update {{ java_subversion }}.pkg" 17 | -target / 18 | 19 | - name: unmount the downloaded dmg 20 | shell: hdiutil detach "/Volumes/JDK {{ java_version }} Update {{ java_subversion }}" 21 | -------------------------------------------------------------------------------- /tasks/use-rpm.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: tasks/use-rpm.yml 3 | # install Oracle JDK 1.x on CentOS 4 | # 5 | # Adapted from: http://blog.trifork.com/2013/04/02/ansible-example-playbook-to-setup-jenkins-slave/ 6 | # See also: http://java.dzone.com/articles/installing-oracle-java6-ubuntu 7 | # 8 | 9 | - name: uninstall messy packages to avoid blocking conditions 10 | script: ../files/uninstall-messy-jdk-packages.sh 11 | 12 | - name: delete messy .rpm files to avoid blocking conditions 13 | script: ../files/delete-messy-rpm-files.sh {{ java_download_path }} 14 | 15 | 16 | - name: install JDK via RPM file with yum 17 | yum: 18 | name: "{{ java_download_path }}/{{ jdk_tarball_file }}.rpm" 19 | state: present 20 | when: ansible_pkg_mgr == "yum" 21 | 22 | # Cannot use zypper module: https://github.com/ansible/ansible-modules-extras/issues/2094 23 | # Following https://en.opensuse.org/SDB:Installing_Java 24 | - block: 25 | - name: symlink /usr/sbin/update-alternatives to /usr/sbin/alternatives 26 | file: src=/usr/sbin/update-alternatives dest=/usr/sbin/alternatives state=link 27 | 28 | - name: check if pkg already installed 29 | shell: rpm -ql $(rpm -qp "{{ java_download_path }}/{{ jdk_tarball_file }}.rpm") 30 | register: reg_validate 31 | failed_when: reg_validate.rc != 0 and reg_validate.rc != 1 32 | 33 | - name: install JDK via RPM file with rpm (for zypper) 34 | shell: rpm -ivh --nodeps "{{ java_download_path }}/{{ jdk_tarball_file }}.rpm" 35 | when: reg_validate.rc != 0 36 | #shell: zypper --no-gpg-checks --non-interactive install "{{ java_download_path }}/{{ jdk_tarball_file }}.rpm" 37 | when: ansible_pkg_mgr == "zypper" 38 | 39 | 40 | - name: clean up - uninstall messy packages 41 | script: ../files/uninstall-messy-jdk-packages.sh 42 | 43 | - name: clean up - delete messy .rpm files 44 | script: ../files/delete-messy-rpm-files.sh {{ java_download_path }} 45 | -------------------------------------------------------------------------------- /tasks/use-tarball.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: use-tarball.yml 3 | # install Oracle JDK 1.x on distributions other than the CentOS/RHEL family 4 | # 5 | # See: https://docs.oracle.com/javase/8/docs/technotes/guides/install/linux_jdk.html 6 | # 7 | 8 | - name: mkdir for Java 9 | file: 10 | path: "{{ java_install_dir }}/jdk{{ jdk_version }}" 11 | state: directory 12 | owner: root 13 | group: root 14 | mode: "u=rwx,go=rx" 15 | 16 | - name: install JDK via tarball file 17 | unarchive: 18 | src: "{{ java_download_path }}/{{ jdk_tarball_file }}.tar.gz" 19 | dest: "{{ java_install_dir }}" 20 | owner: root 21 | group: root 22 | mode: "go-w" 23 | copy: no 24 | -------------------------------------------------------------------------------- /templates/java_home.sh.j2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export JAVA_HOME={{ java_install_dir }}/{{ java_default_link_name }} 4 | 5 | -------------------------------------------------------------------------------- /test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: "{{ test_hosts|default('all') }}" 3 | become: yes 4 | become_method: sudo 5 | tasks: 6 | - include: 'tasks/main.yml' 7 | vars_files: 8 | - 'defaults/main.yml' 9 | 10 | vars: 11 | #java_version: 8 12 | java_subversion: 112 13 | java_install_jce: true 14 | -------------------------------------------------------------------------------- /test/Dockerfile-centos6: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:centos6-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | RUN echo "===> Installing the missing "tar" utility for Docker image..." && \ 18 | yum -y install tar 19 | 20 | RUN echo "===> Patching defaults/main.yml to enable java_install_jce..." && \ 21 | sed -i -e 's/^java_install_jce:.*/java_install_jce: true/g' defaults/main.yml 22 | 23 | ENV PLAYBOOK test.yml 24 | RUN ansible-playbook-wrapper -vvv 25 | 26 | 27 | 28 | # 29 | # test phase 30 | # 31 | 32 | CMD ["java", "-version"] 33 | -------------------------------------------------------------------------------- /test/Dockerfile-centos7: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:centos7-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | RUN echo "===> Patching defaults/main.yml to enable java_install_jce..." && \ 18 | sed -i -e 's/^java_install_jce:.*/java_install_jce: true/g' defaults/main.yml 19 | 20 | ENV PLAYBOOK test.yml 21 | RUN ansible-playbook-wrapper 22 | 23 | 24 | 25 | # 26 | # test phase 27 | # 28 | 29 | CMD ["java", "-version"] 30 | -------------------------------------------------------------------------------- /test/Dockerfile-debian7: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:debian7-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | RUN echo "===> Patching defaults/main.yml to enable java_install_jce..." && \ 18 | sed -i -e 's/^java_install_jce:.*/java_install_jce: true/g' defaults/main.yml 19 | 20 | ENV PLAYBOOK test.yml 21 | RUN ansible-playbook-wrapper 22 | 23 | 24 | 25 | # 26 | # test phase 27 | # 28 | 29 | CMD ["java", "-version"] 30 | -------------------------------------------------------------------------------- /test/Dockerfile-debian8: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:debian8-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | RUN echo "===> Patching defaults/main.yml to enable java_install_jce..." && \ 18 | sed -i -e 's/^java_install_jce:.*/java_install_jce: true/g' defaults/main.yml 19 | 20 | ENV PLAYBOOK test.yml 21 | RUN ansible-playbook-wrapper 22 | 23 | 24 | 25 | # 26 | # test phase 27 | # 28 | 29 | CMD ["java", "-version"] 30 | -------------------------------------------------------------------------------- /test/Dockerfile-prefetch-rpm: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:centos7-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | ENV PLAYBOOK prefetch.yml 18 | RUN ansible-playbook-wrapper 19 | 20 | 21 | 22 | # 23 | # output phase 24 | # 25 | 26 | VOLUME [ "/data" ] 27 | CMD cp /tmp/jdk-*.rpm /data/files && \ 28 | cp /tmp/*.zip /data/files 29 | -------------------------------------------------------------------------------- /test/Dockerfile-prefetch-tarball: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:debian8-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | ENV PLAYBOOK prefetch.yml 18 | RUN ansible-playbook-wrapper 19 | 20 | 21 | 22 | # 23 | # output phase 24 | # 25 | 26 | VOLUME [ "/data" ] 27 | CMD cp /tmp/jdk-*.tar.gz /data/files && \ 28 | cp /tmp/*.zip /data/files 29 | -------------------------------------------------------------------------------- /test/Dockerfile-ubuntu12.04: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:ubuntu12.04-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | RUN echo "===> Patching defaults/main.yml to enable java_install_jce..." && \ 18 | sed -i -e 's/^java_install_jce:.*/java_install_jce: true/g' defaults/main.yml 19 | 20 | ENV PLAYBOOK test.yml 21 | RUN ansible-playbook-wrapper 22 | 23 | 24 | 25 | # 26 | # test phase 27 | # 28 | 29 | CMD ["java", "-version"] 30 | -------------------------------------------------------------------------------- /test/Dockerfile-ubuntu14.04: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:ubuntu14.04-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | RUN echo "===> Patching defaults/main.yml to enable java_install_jce..." && \ 18 | sed -i -e 's/^java_install_jce:.*/java_install_jce: true/g' defaults/main.yml 19 | 20 | ENV PLAYBOOK test.yml 21 | RUN ansible-playbook-wrapper 22 | 23 | 24 | 25 | # 26 | # test phase 27 | # 28 | 29 | CMD ["java", "-version"] 30 | -------------------------------------------------------------------------------- /test/travis/before_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -uo pipefail 4 | 5 | case "$TRAVIS_OS_NAME" in 6 | linux) 7 | docker info 8 | docker version 9 | 10 | echo "==> Prefetching .rpm and .tar.gz to '$PWD/files'..." 11 | docker build -f test/Dockerfile-prefetch-rpm -t java_prefetch_rpm . 12 | docker run -v $(pwd):/data java_prefetch_rpm 13 | docker build -f test/Dockerfile-prefetch-tarball -t java_prefetch_tarball . 14 | docker run -v $(pwd):/data java_prefetch_tarball 15 | sed -i -e 's/^\(java_download_from_oracle:\).*$/\1 false/' defaults/main.yml 16 | 17 | echo "==> Building test cases..." 18 | docker build -f test/Dockerfile-ubuntu14.04 -t java_trusty . 19 | docker build -f test/Dockerfile-ubuntu12.04 -t java_precise . 20 | docker build -f test/Dockerfile-debian8 -t java_jessie . 21 | docker build -f test/Dockerfile-debian7 -t java_wheezy . 22 | docker build -f test/Dockerfile-centos7 -t java_centos7 . 23 | docker build -f test/Dockerfile-centos6 -t java_centos6 . 24 | ;; 25 | osx) 26 | echo "==> Installing Ansible using pip on Mac OS X" 27 | sudo pip install ansible 28 | ;; 29 | *) 30 | echo "Unknown value of TRAVIS_OS_NAME: '$TRAVIS_OS_NAME'" >&2 31 | exit 1 32 | esac 33 | -------------------------------------------------------------------------------- /test/travis/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -uo pipefail 4 | 5 | case "$TRAVIS_OS_NAME" in 6 | linux) 7 | docker run -i java_trusty 2> result-ubuntu14.04 8 | docker run -i java_precise 2> result-ubuntu12.04 9 | docker run -i java_jessie 2> result-debian8 10 | docker run -i java_wheezy 2> result-debian7 11 | docker run -i java_centos7 2> result-centos7 12 | docker run -i java_centos6 2> result-centos6 13 | 14 | echo "==> Validating the test results..." 15 | sh -c "[ -s result-ubuntu14.04 ]" 16 | sh -c "[ -s result-ubuntu12.04 ]" 17 | sh -c "[ -s result-debian8 ]" 18 | sh -c "[ -s result-debian7 ]" 19 | sh -c "[ -s result-centos7 ]" 20 | sh -c "[ -s result-centos6 ]" 21 | ;; 22 | osx) 23 | echo "==> Running tests using ansible-playbook on Mac OS X..." 24 | ansible-playbook test.yml --extra-vars test_hosts=localhost 25 | 26 | echo "==> Validating the test results..." 27 | java -version 2> result-macosx 28 | sh -c "[ -s result-macosx ]" 29 | ;; 30 | *) 31 | echo "Unknown value of TRAVIS_OS_NAME: '$TRAVIS_OS_NAME'" >&2 32 | exit 1 33 | esac 34 | --------------------------------------------------------------------------------