Repository: ansiblebit/oracle-java Branch: master Commit: 65a4d01e870b Files: 33 Total size: 39.7 KB Directory structure: gitextract_af2umfnz/ ├── .gitignore ├── .travis.yml ├── .yamllint.yml ├── LICENSE ├── README.md ├── defaults/ │ ├── darwin-macosx.yml │ ├── debian-ubuntu.yml │ ├── debian.yml │ ├── main.yml │ └── redhat.yml ├── handlers/ │ └── main.yml ├── meta/ │ └── main.yml ├── requirements.yml ├── tasks/ │ ├── check_environment.yml │ ├── darwin/ │ │ └── macosx.yml │ ├── debug.yml │ ├── installation/ │ │ ├── debian/ │ │ │ └── main.yml │ │ └── redhat/ │ │ └── main.yml │ └── main.yml ├── tests/ │ ├── Vagrantfile │ ├── ansible.cfg │ ├── boxes.yml │ ├── log/ │ │ └── .gitkeep │ ├── plugins/ │ │ └── callback/ │ │ └── idempotence.py │ ├── requirements.txt │ ├── setup.sh │ ├── tasks/ │ │ └── main.yml │ ├── test.yml │ ├── test_checkmode.sh │ ├── test_idempotence.sh │ ├── travis.sh │ └── vagrant.sh └── tox.ini ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ *.retry **/dependencies/* # Created by https://www.gitignore.io ### Vagrant ### .vagrant/ ### PyCharm ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm *.iml ## Directory-based project format: .idea/ # if you remove the above rule, at least ignore the following: # User-specific stuff: # .idea/workspace.xml # .idea/tasks.xml # .idea/dictionaries # Sensitive or high-churn files: # .idea/dataSources.ids # .idea/dataSources.xml # .idea/sqlDataSources.xml # .idea/dynamic.xml # .idea/uiDesigner.xml # Gradle: # .idea/gradle.xml # .idea/libraries # Mongo Explorer plugin: # .idea/mongoSettings.xml ## File-based project format: *.ipr *.iws ## Plugin-specific files: # IntelliJ out/ # mpeltonen/sbt-idea plugin .idea_modules/ # JIRA plugin atlassian-ide-plugin.xml # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties ### Python ### # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .cache nosetests.xml coverage.xml # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation docs/_build/ # PyBuilder target/ ================================================ FILE: .travis.yml ================================================ language: python sudo: yes matrix: include: - python: 3.6 env: TOXENV=py36-ansible28 - python: 3.6 env: TOXENV=py36-ansible27 - python: 3.6 env: TOXENV=py36-ansible26 - python: 3.6 env: TOXENV=py36-ansible25 - python: 2.7 env: TOXENV=py27-ansible24 - python: 2.7 env: TOXENV=py27-ansible23 - python: 2.7 env: TOXENV=py27-ansible22 - python: 2.7 env: TOXENV=py27-ansible21 - python: 2.7 env: TOXENV=py27-ansible20 install: - pip install tox script: - tox notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ before_cache: - rm -f ${HOME}/.cache/pip/log/debug.log cache: directories: - ${HOME}/.cache/pip ================================================ FILE: .yamllint.yml ================================================ --- # Based on ansible-lint config extends: default rules: braces: {max-spaces-inside: 1, level: error} brackets: {max-spaces-inside: 1, level: error} colons: {max-spaces-after: -1, level: error} commas: {max-spaces-after: -1, level: error} comments: disable comments-indentation: disable document-start: disable empty-lines: {max: 3, level: error} hyphens: {level: error} indentation: disable key-duplicates: enable line-length: disable new-line-at-end-of-file: disable new-lines: {type: unix} trailing-spaces: disable truthy: disable ================================================ FILE: LICENSE ================================================ Copyright (c) 2014, ansiblebit All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of ansiblebit nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================ FILE: README.md ================================================ # ansiblebit.oracle-java [![License](https://img.shields.io/badge/license-New%20BSD-blue.svg?style=flat)](https://raw.githubusercontent.com/ansiblebit/oracle-java/master/LICENSE) [![Build Status](https://travis-ci.org/ansiblebit/oracle-java.svg?branch=master)](https://travis-ci.org/ansiblebit/oracle-java) [![Platform](http://img.shields.io/badge/platform-centos-932279.svg?style=flat)](CentOS) [![Platform](http://img.shields.io/badge/platform-debian-a80030.svg?style=flat)](Debian) [![Platform](http://img.shields.io/badge/platform-redhat-cc0000.svg?style=flat)](RedHat) [![Platform](http://img.shields.io/badge/platform-ubuntu-dd4814.svg?style=flat)](Ubuntu) [![Project Stats](https://www.openhub.net/p/ansiblebit-oracle-java/widgets/project_thin_badge.gif)](https://www.openhub.net/p/ansiblebit-oracle-java/) An [Ansible](http://www.ansible.com) role to setup Oracle Java Development Kit. DISCLAIMER: usage of any version of this role implies you have accepted the [Oracle Binary Code License Agreement for Java SE](http://www.oracle.com/technetwork/java/javase/terms/license/index.html). ## Tests | Family | Distribution | Version | Test Status | |:-:|:-:|:-:|:-:| | Debian | Debian | Jessie | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | Debian | Debian | Stretch | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | Debian | Ubuntu | Precise | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | Debian | Ubuntu | Yakkety | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | Debian | Ubuntu | Xenial | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | Debian | Ubuntu | Trusty | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | Debian | Ubuntu | Vivid | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | Debian | Ubuntu | Wily | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | Debian | Ubuntu | Artful | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | Debian | Ubuntu | Bionic | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | Debian | Ubuntu | Cosmic | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | | RedHat | Centos | 7 | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](x) | ## Requirements - ansible >= 2.x ## Facts - **oracle_java_installed**: fact set by this role that contains a flag that indicates if Java is installed on the host. - **oracle_java_version_installed**: fact set by this role that contains the string of the Java version installed in the system. ## Role Variables - **debug**: flag to make role more verbose. - **oracle_java_set_as_default**: flag to indicate if this play should set Java as default (default: `yes`). - **oracle_java_use_defaults**: flag to indicate you want to use defaults set in the `defaults` directory (default: `yes`). **WARNING**. setting this to `no` will require the user to pass all of the distribution variables. See `* | Java 11` examples in the _Playbooks_ section. ### Debian **WARNING** to override **any** of the following variables (even if it's only one), you'll need to set `oracle_java_use_defaults: no` and override **all** of their values since OS family defaults will no longer be loaded. See `debian | Java 11` example in the _Playbooks_ section. - **oracle_java_apt_repository**: Personal Package Archive (PPA) from where to install Java. - **oracle_java_apt_repository_key**: PPA repository key. - **oracle_java_cache_valid_time**: the amount of time in seconds the apt cache is valid. - **oracle_java_deb_package**: name of debian package. - **oracle_java_debconf_package_default**: name of debconf package to set default. - **oracle_java_home**: the location of the Java home directory. - **oracle_java_state**:** the package state (see Ansible apt module for more information). ### Debian/Ubuntu **WARNING** to override **any** of the following variables (even if it's only one), you'll need to set `oracle_java_use_defaults: no` and override **all** of their values since OS family defaults will no longer be loaded. See `debian | ubuntu | Java 11` example in the _Playbooks_ section. - **oracle_java_apt_repository**: Personal Package Archive (PPA) from where to install Java. - **oracle_java_cache_valid_time**: the amount of time in seconds the apt cache is valid. - **oracle_java_deb_package**: name of debian package. - **oracle_java_debconf_package_default**: name of debconf package to set default. - **oracle_java_home**: the location of the Java home directory. - **oracle_java_license_version**: which Oracle license version you will be accepting. - **oracle_java_state**:** the package state (see Ansible apt module for more information). ### Redhat-only **WARNING** to override **any** of the following variables (even if it's only one), you'll need to set `oracle_java_use_defaults: no` and override **all** of their values since OS family defaults will no longer be loaded. See `redhat | centos 7 | Java 11` example in the _Playbooks_ section. - **oracle_java_dir_source**: directory where to store the RPM files. - **oracle_java_download_timeout**: download timeout, in seconds. - **oracle_java_home**: the location of the Java home directory. - **oracle_java_rpm_filename**: file name used for the download destination. - **oracle_java_rpm_url**: where to download the rpm from. - **oracle_java_rpm_validate_certs**: flag to indicate if you want SSL certificate validation. - **oracle_java_version_string**: the Java version string to verify installation against. ## Playbooks ```yaml # generic - hosts: servers roles: - role: ansiblebit.oracle-java # debian | Java 12 - hosts: servers roles: - role: ansiblebit.oracle-java # debian | Java 11 - hosts: servers roles: - role: ansiblebit.oracle-java oracle_java_deb_package: 'oracle-java11-installer' oracle_java_debconf_package_default: 'oracle-java11-set-default' oracle_java_home: "/usr/lib/jvm/java-11-oracle" ## explicitely passing default parameters - hosts: servers roles: - role: ansiblebit.oracle-java # debian | ubuntu | Java 12 - hosts: servers roles: - role: ansiblebit.oracle-java # debian | ubuntu | Java 11 - hosts: servers roles: - role: ansiblebit.oracle-java oracle_java_deb_package: 'oracle-java11-installer' oracle_java_debconf_package_default: 'oracle-java11-set-default' oracle_java_home: "/usr/lib/jvm/java-11-oracle" # redhat | centos 7 | Java 12 - hosts: servers roles: - role: ansiblebit.oracle-java # redhat | centos 7 | Java 11 - hosts: servers roles: - role: ansiblebit.oracle-java oracle_java_use_defaults: no oracle_java_dir_source: '/usr/local/src' oracle_java_download_timeout: 60 oracle_java_rpm_filename: 'jdk-11.0.3_linux-x64_bin.rpm' oracle_java_home: '/usr/java/default' oracle_java_os_supported: yes oracle_java_rpm_url: 'https://download.oracle.com/otn/java/jdk/11.0.3+12/37f5e150db5247ab9333b11c1dddcd30/jdk-11.0.3_linux-x64_bin.rpm' oracle_java_rpm_validate_certs: yes oracle_java_set_as_default: no oracle_java_version_string: 11.0.3 ``` Use `--skip-tags=debug` if you want to suppress debug information. ```bash ## Test ```bash tox -e py27-ansible26 -- --box centos7-64.vagrant.dev tox -e py27-ansible26 -- --box bionic64.vagrant.dev # manual source .tox/py27-ansible26/bin/activate cd tests vagrant up bionic64.vagrant.dev bash test_idempotence.sh \ --box bionic64.vagrant.dev \ --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory ## look at idempotence test logs less log/bionic64.vagrant.dev_idempotence_py27-ansible26.log ## debug vagrant ssh bionic64.vagrant.dev bash test_checkmode.sh \ --box bionic64.vagrant.dev \ --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory ## look at checkmode test logs less log/bionic64.vagrant.dev_checkmode_py27-ansible26.log vagrant destroy bionic64.vagrant.dev ``` ## Links - [launchpad > Linux Uprising > Oracle Java](https://launchpad.net/~linuxuprising/+archive/ubuntu/java) ================================================ FILE: defaults/darwin-macosx.yml ================================================ --- # file: oracle-java/defaults/darwin-macosx.yml # # Default variables for OSX-based Darwin distributions. # oracle_java_dir_source: "{{ ansible_env.HOME }}/Downloads" oracle_java_dmg_filename: "" oracle_java_dmg_url: "/{{ oracle_java_dmg_filename }}" ================================================ FILE: defaults/debian-ubuntu.yml ================================================ --- # file: oracle-java/defaults/debian-ubuntu.yml # # Default variables for Ubuntu Linux distributions. # oracle_java_apt_repository: 'ppa:linuxuprising/java' oracle_java_cache_valid_time: 3600 oracle_java_deb_package: 'oracle-java12-installer' oracle_java_debconf_package_default: 'oracle-java12-set-default' oracle_java_home: "/usr/lib/jvm/java-12-oracle" oracle_java_license_version: 'shared/accepted-oracle-license-v1-2' oracle_java_state: latest ================================================ FILE: defaults/debian.yml ================================================ --- # file: oracle-java/defaults/debian.yml # # Default variables for Debian-based Linux distributions. # oracle_java_apt_repository: 'deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main' oracle_java_apt_repository_key: 'EA8CACC073C3DB2A' oracle_java_cache_valid_time: 3600 oracle_java_deb_package: 'oracle-java12-installer' oracle_java_debconf_package_default: 'oracle-java12-set-default' oracle_java_home: "/usr/lib/jvm/java-12-oracle" oracle_java_license_version: 'shared/accepted-oracle-license-v1-2' oracle_java_state: latest ================================================ FILE: defaults/main.yml ================================================ --- # file: oracle-java/defaults/main.yml # # defaults file # oracle_java_set_as_default: yes oracle_java_use_defaults: yes ================================================ FILE: defaults/redhat.yml ================================================ --- # file: oracle-java/defaults/redhat.yml # # Default variables for Redhat-based Linux distributions. # oracle_java_dir_source: '/usr/local/src' oracle_java_download_timeout: 60 oracle_java_rpm_filename: 'jdk-12.0.1_linux-x64_bin.rpm' oracle_java_home: '/usr/java/default' oracle_java_rpm_url: 'https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm' oracle_java_rpm_validate_certs: yes oracle_java_version: 12 oracle_java_version_string: 12.0.1 ================================================ FILE: handlers/main.yml ================================================ --- # file: oracle-java/handlers/main.yml # # Handlers file. # ================================================ FILE: meta/main.yml ================================================ --- # file: oracle-java/meta/main.yml # # meta file # galaxy_info: author: Pedro Salgado description: Role to install Oracle Java. company: ansiblebit.org license: BSD min_ansible_version: 2.0 platforms: - name: CentOS versions: - any - 7 - 6 - name: Debian versions: - jessie - wheezy - name: RedHat versions: - any - 7 - 6 - name: Ubuntu versions: - cosmic - bionic - xenial - vivid - trusty - precise galaxy_tags: - development - java - system ================================================ FILE: requirements.yml ================================================ ================================================ FILE: tasks/check_environment.yml ================================================ --- # file: oracle-java/tasks/check_environment.yml # # task to set host facts: # - Java is installed? # - which Java version is installed? # - name: determine if Java is already installed command: which java register: oracle_java_task_installed changed_when: oracle_java_task_installed.rc != 0 failed_when: no # oracle_java_installed.rc == 0 : installed # oracle_java_installed.rc == 1 : not installed - name: set fact oracle_java_installed set_fact: oracle_java_installed={{ not oracle_java_task_installed.changed }} - name: determine which Java version is installed shell: | set -o pipefail | java -version 2>&1 | head -n 1 | awk '{ print $3 }' | awk -F '"' '{ print $2 }' register: oracle_java_task_version when: oracle_java_installed changed_when: False - name: set fact oracle_java_installed_version set_fact: oracle_java_version_installed="{{ oracle_java_task_version.stdout }}" when: oracle_java_task_version is defined and oracle_java_task_version.stdout is defined changed_when: False - debug: var="{{ item }}" when: item is defined and debug | default(false) with_items: - oracle_java_installed - oracle_java_task_installed - oracle_java_task_version - oracle_java_version_installed tags: [ debug ] ================================================ FILE: tasks/darwin/macosx.yml ================================================ --- # file: oracle-java/tasks/darwin/macosx.yml # # Task file to install Oracle Java Development Kit in a system with a OSX based Darwin distribution. # - name: download DMG file get_url: headers: Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F oraclelicense: accept-securebackup-cookie dest: "{{ oracle_java_dir_source }}/{{ oracle_java_dmg_filename }}" url: "{{ oracle_java_dmg_url }}" validate_certs: "{{ oracle_java_dmg_validate_certs }}" timeout: "{{ oracle_java_download_timeout }}" force: no register: oracle_java_task_dmg_download until: oracle_java_task_dmg_download is succeeded tags: - installation # - name: mount DMG image # shell: echo TODO # tags: # - installation # - name: install JDK # shell: echo TODO # tags: # - installation # - name: unmount DMG image # shell: echo TODO # tags: # - installation # - name: set Java version as default # shell: echo TODO # when: oracle_java_set_as_default # register: oracle_java_task_set_default # become: yes - name: in case there were changes, check host environment again include: ../check_environment.yml ================================================ FILE: tasks/debug.yml ================================================ --- # file: oracle-java/tasks/debug.yml # # Task that prints variable debug information. # - debug: var="{{ item }}" when: item is defined with_items: - oracle_java_cache_valid_time - oracle_java_home - oracle_java_installed - oracle_java_apt_repository - oracle_java_apt_repository_key - oracle_java_license_version - oracle_java_set_as_default - oracle_java_state - oracle_java_version_installed - oracle_java_version_string ================================================ FILE: tasks/installation/debian/main.yml ================================================ --- # file: oracle-java/tasks/installation/debian/main.yml # # Task file to install Oracle Java Development Kit in a system with a Debian based Linux distribution. # - name: debian | ensure the apt repository key is present apt_key: id="{{ oracle_java_apt_repository_key }}" keyserver=keyserver.ubuntu.com state=present when: oracle_java_apt_repository_key is defined become: yes - name: debian | ensure the apt repository is present apt_repository: repo="{{ oracle_java_apt_repository }}" update_cache=yes state=present become: yes - name: debian | set license as accepted debconf: name="{{ oracle_java_deb_package }}" question="{{ oracle_java_license_version }}" value='true' vtype='select' become: yes - name: debian | ensure Java is installed apt: name="{{ oracle_java_deb_package }}" state={{ oracle_java_state }} cache_valid_time={{ oracle_java_cache_valid_time }} update_cache=yes register: oracle_java_task_apt_install become: yes - name: debian | set Java version as default apt: name="{{ oracle_java_debconf_package_default }}" state=present register: oracle_java_task_set_default when: oracle_java_set_as_default become: yes ================================================ FILE: tasks/installation/redhat/main.yml ================================================ --- # file: oracle-java/tasks/installation/redhat/main.yml # # Task file to install Oracle Java Development Kit in a system with a Redhat based Linux distribution. # - name: download Java RPM get_url: headers: Cookie: "gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" dest: "{{ oracle_java_dir_source }}/{{ oracle_java_rpm_filename }}" url: "{{ oracle_java_rpm_url }}" validate_certs: "{{ oracle_java_rpm_validate_certs }}" timeout: "{{ oracle_java_download_timeout }}" force: no register: oracle_java_task_rpm_download until: oracle_java_task_rpm_download is succeeded become: yes when: oracle_java_version_installed is not defined or oracle_java_version_installed != oracle_java_version_string - name: install RPM yum: name="{{ oracle_java_dir_source }}/{{ oracle_java_rpm_filename }}" state=present when: not oracle_java_task_rpm_download is skipped become: yes - name: set Java version as default alternatives: name="{{ java.exe }}" link="/usr/bin/{{ java.exe }}" path="{{ java.path }}/{{ java.exe }}" with_items: - { path: "{{ oracle_java_home }}/bin", exe: 'java' } - { path: "{{ oracle_java_home }}/bin", exe: 'keytool' } - { path: "{{ oracle_java_home }}/bin", exe: 'javac' } - { path: "{{ oracle_java_home }}/bin", exe: 'javadoc' } loop_control: loop_var: java become: yes when: ( oracle_java_set_as_default and oracle_java_task_rpm_download is defined and oracle_java_task_rpm_download is changed ) or ( oracle_java_set_as_default and oracle_java_installed is defined and oracle_java_installed and oracle_java_version_installed is defined and oracle_java_version_installed != oracle_java_version_string) register: oracle_java_task_set_default ================================================ FILE: tasks/main.yml ================================================ --- # file: oracle-java/tasks/main.yml # # tasks file # ## include OS family specific variables - name: include OS family/distribution specific variables include_vars: "{{ item }}" with_first_found: - "{{ role_path }}/defaults/{{ ansible_os_family | lower }}-{{ ansible_distribution | lower }}.yml" - "{{ role_path }}/defaults/{{ ansible_os_family | lower }}.yml" when: oracle_java_use_defaults tags: [ installation ] ## run - name: check host environment include: check_environment.yml - include: debug.yml when: debug | default(false) tags: [ debug ] ## include OS family/distribution specific task file - name: include OS family/distribution specific task file include: "{{ item }}" with_first_found: - "installation/{{ ansible_os_family | lower }}/{{ ansible_distribution | lower }}_{{ ansible_distribution_version | lower }}.yml" - "installation/{{ ansible_os_family | lower }}/{{ ansible_distribution | lower }}.yml" - "installation/{{ ansible_os_family | lower }}/main.yml" tags: [ installation ] - name: check host environment include: check_environment.yml ================================================ FILE: tests/Vagrantfile ================================================ #!/usr/bin/env ruby require 'yaml' PLAYBOOK = 'test.yml' CONFIGURATION_FILE = 'boxes.yml' ROLE_NAME = "#{File.expand_path("..").split("/")[-1]}" Vagrant.configure('2') do |config| # overcome 'stdin: is not a tty' errors when trying to provision on vivid64 config.ssh.pty = true config.ssh.shell = 'bash' # puts "[DEBUG] loading box settings from #{CONFIGURATION_FILE}..." vagrant_environment = YAML.load_file(File.expand_path(CONFIGURATION_FILE, File.dirname(__FILE__))) vagrant_environment['vagrant'].each do |box_name, box_settings| if not box_settings['enabled'] # puts "[DEBUG] #{box_name} is not enabled. skipping..." next end # puts "[DEBUG] applying #{box_name} settings..." config.vm.define box_name do |host| host.vm.box = box_settings['box'] unless not box_settings.key? 'box' host.vm.box_version = box_settings['box_version'] unless not box_settings.key? 'box_version' host.vm.network box_settings['network']['name'], ip: box_settings['network']['ip'] unless box_settings.key? 'network' host.vm.synced_folder '.', '/vagrant', disabled: true # puts "[DEBUG] applying virtualbox settings for #{box_name} box..." customize_args = [ "modifyvm", :id ] vagrant_environment['provider']['virtualbox'].collect { |k, v| customize_args |= ["--#{k}", v.to_s] } host.vm.provider 'virtualbox' do |vb| vb.name = "#{ROLE_NAME}_#{box_name}" vb.customize customize_args end # puts "[DEBUG] provision using ansible vagrant playbook..." host.vm.provision 'ansible' do |ansible| ansible.host_vars = { 'xenial64.vagrant.dev' => { 'ansible_python_interpreter' => '/usr/bin/python2.7', 'playbook_python2' => true }, 'yakkety64.vagrant.dev' => { 'ansible_python_interpreter' => '/usr/bin/python2.7', 'playbook_python2' => true }, 'artful64.vagrant.dev' => { 'ansible_python_interpreter' => '/usr/bin/python2.7', 'playbook_python2' => true }, 'bionic64.vagrant.dev' => { 'ansible_python_interpreter' => '/usr/bin/python2.7', 'playbook_python2' => true }, 'cosmic64.vagrant.dev' => { 'ansible_python_interpreter' => '/usr/bin/python2.7', 'playbook_python2' => true }, } ansible.playbook = PLAYBOOK ansible.verbose = 'v' ansible.skip_tags = 'test' ansible.extra_vars = { 'env': 'vagrant', 'vagrant_box': "#{box_name}" } end end end end ================================================ FILE: tests/ansible.cfg ================================================ [defaults] ansible_managed = Ansible managed file, do not edit directly callback_plugins = plugins/callback host_key_checking = False private_key_file = ~/.vagrant.d/insecure_private_key roles_path = ../../:../:dependencies ================================================ FILE: tests/boxes.yml ================================================ --- # file: oracle-java/tests/boxes.yml # provider: virtualbox: memory: 1024 cpus: 1 vagrant: # CentOS centos7-64.vagrant.dev: enabled: true box: centos/7 network: name: private_network ip: 192.168.121.3 # Debian jessie64.vagrant.dev: enabled: true box: debian/jessie64 network: name: private_network ip: 192.168.122.1 stretch64.vagrant.dev: enabled: true box: debian/stretch64 network: name: private_network ip: 192.168.122.3 # Ubuntu precise64.vagrant.dev: enabled: true box: ubuntu/precise64 network: name: private_network ip: 192.168.124.2 trusty64.vagrant.dev: enabled: true box: ubuntu/trusty64 network: name: private_network ip: 192.168.124.4 vivid64.vagrant.dev: enabled: true box: ubuntu/vivid64 network: name: private_network ip: 192.168.124.6 wily64.vagrant.dev: enabled: true box: ubuntu/vivid64 network: name: private_network ip: 192.168.124.8 xenial64.vagrant.dev: enabled: true box: ubuntu/xenial64 network: name: private_network ip: 192.168.124.10 yakkety64.vagrant.dev: enabled: true box: ubuntu/yakkety64 network: name: private_network ip: 192.168.124.12 artful64.vagrant.dev: enabled: true box: ubuntu/artful64 network: name: private_network ip: 192.168.124.10 bionic64.vagrant.dev: enabled: true box: ubuntu/bionic64 network: name: private_network ip: 192.168.124.11 cosmic64.vagrant.dev: enabled: true box: ubuntu/cosmic64 network: name: private_network ip: 192.168.124.12 ================================================ FILE: tests/log/.gitkeep ================================================ ================================================ FILE: tests/plugins/callback/idempotence.py ================================================ # -*- coding: utf-8 -*- from __future__ import (absolute_import, print_function) import sys import os from ansible import constants as C from ansible.constants import mk_boolean try: from ansible.plugins.callback import CallbackBase parent = CallbackBase except ImportError: parent = object VAR_IDEMPOTENCE = u'IDEMPOTENCE' class CallbackModule(parent): """ This callback module performs the idempotency test whenever the 'idempotency' variable is set to True. """ CALLBACK_VERSION = 2.0 CALLBACK_NAME = 'idempotency' def __init__(self): self.playbook = None self.enabled = mk_boolean(os.getenv(VAR_IDEMPOTENCE, 'no')) super(CallbackModule, self).__init__() def playbook_on_stats(self, stats): if self.enabled: if len(stats.dark) > 0: self._display.warning('idempotency test failed: unreachable=%s > 0' % stats.dark) sys.exit(os.EX_SOFTWARE) if len(stats.changed) > 0: self._display.warning('idempotency test failed: changed=%s > 0' % stats.changed) sys.exit(os.EX_SOFTWARE) if len(stats.failures) > 0: self._display.warning('idempotency test failed: failures=%s > 0' % stats.failures) sys.exit(os.EX_SOFTWARE) def v2_playbook_on_stats(self, stats): """Verify that playbook ran without any changes or failures.""" self.playbook_on_stats(stats) ================================================ FILE: tests/requirements.txt ================================================ ansiblebit.launchpad-ppa-webupd8 ================================================ FILE: tests/setup.sh ================================================ #!/usr/bin/env bash # ################# # # Bash script to setup the test environment. # # version: 1.0 # # usage: # # setup.sh # # example: # # bash setup.sh # # changelog: # # v1.0 : 10 June 2016 # - initial version # # author(s): # - Pedro Salgado # # ################# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" test -s ${DIR}/../requirements.yml \ && ansible-galaxy install \ --force \ -r ${DIR}/../requirements.yml \ --roles-path=${DIR}/dependencies \ || true ================================================ FILE: tests/tasks/main.yml ================================================ --- # file: oracle-java/tests/tasks/main.yml # # Test tasks to verify role execution. # - name: is oracle_java_installed fact set? fail: msg="oracle_java_installed fact is not defined!" when: not oracle_java_installed is defined - name: is oracle_java_installed fact true? fail: msg="oracle_java_installed fact is false!" when: not oracle_java_installed - name: is oracle_java_version_installed fact set? fail: msg="oracle_java_installed fact is not defined!" when: not oracle_java_version_installed is defined - name: is oracle_java_version_installed value correct? fail: msg="oracle_java_version_installed value is {{ oracle_java_version_installed }} instead of {{ expected_java_version }}!" when: oracle_java_version_installed != expected_java_version - name: register result_java_version with host installed Java version shell: java -version 2>&1 | head -n 1 | awk '{ print $3 }' | awk -F '"' '{ print $2 }' register: result_java_version changed_when: no - name: is installed Java version on host correct? fail: msg="java -version output was {{ result_java_version.stdout }} instead of {{ expected_java_version }}" when: result_java_version.stdout != expected_java_version - name: ensure keytool and javadoc are present shell: "test -h /usr/bin/{{ item }}" changed_when: no with_items: - keytool - java - javadoc ================================================ FILE: tests/test.yml ================================================ --- # file: oracle-java/tests/test.yml - name: setup python2 hosts: "{{ vagrant_box }}" gather_facts: no tasks: - raw: sudo apt-get update -qq && sudo apt-get install -qq python2.7 when: playbook_python2 is defined and playbook_python2 changed_when: false - name: setup stretch hosts: "{{ vagrant_box }}" tasks: - apt: name=software-properties-common state=present become=yes when: ansible_distribution | lower == 'stretch' - name: tests play hosts: all gather_facts: yes vars: debug: yes test_expected_java_version: '12.0.1' roles: - role: oracle-java - role: tests expected_java_version: "{{ test_expected_java_version }}" tags: [ test ] ================================================ FILE: tests/test_checkmode.sh ================================================ #!/usr/bin/env bash # ################# # # Bash script to run check mode tests. # # version: 1.5 # # usage: # # test_checkmode [options] # # options: # # --box The name of the Vagrant box or host name # --env The name of the test environment # --inventory The Ansible inventory in the form of a file or string "host," # --playbook The path to the Ansible test playbook # # example: # # # on localhost # bash test_checkmode.sh # # # on a Vagrant box # bash test_checkmode.sh \ # --box precise64.vagrant.dev \ # --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory # # # changelog: # # v1.5 : 8 Mar 2016 # - pass vagrant_box variable to playbook # - default inventory changed from localhost to match what Vagrant provisioner generates # v1.4 : 10 Jul 2015 # - added extra variables to force running idempotence tests on vagrant # v1.2 # - added env option # # author(s): # - Pedro Salgado # # ################# # GREEN : SGR code to set text color (foreground) to green. GREEN='\033[0;32m' # RED : SGR code to set text color (foreground) to red. RED='\033[0;31m' # SGR code to set text color (foreground) to no color. NC='\033[0m' # The idempotence pass criteria. PASS_CRITERIA="changed=0.* unreachable=0.* failed=0" # the name of the virtualenv VIRTUALENV_NAME=$(which python | awk -F / 'NF && NF-2 { print ( $(NF-2) ) }') while [[ $# > 1 ]] do key="$1" case $key in --box) # the name of the Vagrant box or host name BOX="$2" shift;; --env) # the test environment ENV="$2" shift;; --inventory) # the Ansible inventory in the form of a file or string "host," INVENTORY="$2" shift;; --playbook) # the path to the Ansible test playbook PLAYBOOK="$2" shift;; *) # unknown option ;; esac shift done # the name of the Vagrant box or host name BOX=${BOX:-localhost} # the Ansible inventory INVENTORY=${INVENTORY:-'.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory'} # the path to the Ansible test playbook PLAYBOOK=${PLAYBOOK:-test.yml} # the logfile to hold the output of the playbook run LOGFILE="log/${BOX}_checkmode_${VIRTUALENV_NAME}.log" EXTRA_ARGS='' if [ $BOX == "localhost" ]; then INVENTORY='localhost,' EXTRA_ARGS="--connection=local -e env=${ENV} -e vagrant_box=localhost --skip-tags=test" else EXTRA_ARGS="--user vagrant -e env=vagrant -e vagrant_box=${BOX} --skip-tags=test" fi echo "[INFO] ${BOX} ${VIRTUALENV_NAME} running checkmode test..." ansible-playbook -vvvv --check --diff -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | \ tee ${LOGFILE} | \ grep "${BOX}" | grep -q "${PASS_CRITERIA}" && \ echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} checkmode : ${GREEN}PASS${NC}\n" || ( \ cat ${LOGFILE} && echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} checkmode : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && \ exit 1) ================================================ FILE: tests/test_idempotence.sh ================================================ #!/usr/bin/env bash # ################# # # Bash script to run idempotence tests. # # version: 1.5 # # usage: # # test_idempotence [options] # # options: # # --box The name of the Vagrant box or host name # --env The name of the test environment # --inventory The Ansible inventory in the form of a file or string "host," # --playbook The path to the Ansible test playbook # # example: # # # on localhost # bash test_idempotence.sh # # # on a Vagrant box # bash test_idempotence.sh \ # --box precise64.vagrant.dev \ # --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory # # # changelog: # # v1.5 : 8 Mar 2016 # - pass vagrant_box variable to playbook # - default inventory changed from localhost to match what Vagrant provisioner generates # v1.4 : 10 Jul 2015 # - added extra variables to force running idempotence tests on vagrant # v1.2 # - added env option # # author(s): # - Pedro Salgado # # ################# # GREEN : SGR code to set text color (foreground) to green. GREEN='\033[0;32m' # RED : SGR code to set text color (foreground) to red. RED='\033[0;31m' # SGR code to set text color (foreground) to no color. NC='\033[0m' # The idempotence pass criteria. PASS_CRITERIA="changed=0.* unreachable=0.* failed=0" # the name of the virtualenv VIRTUALENV_NAME=$(which python | awk -F / 'NF && NF-2 { print ( $(NF-2) ) }') while [[ $# > 1 ]] do key="$1" case $key in --box) # the name of the Vagrant box or host name BOX="$2" shift;; --env) # the test environment ENV="$2" shift;; --inventory) # the Ansible inventory in the form of a file or string "host," INVENTORY="$2" shift;; --playbook) # the path to the Ansible test playbook PLAYBOOK="$2" shift;; *) # unknown option ;; esac shift done # the name of the Vagrant box or host name BOX=${BOX:-localhost} # the Ansible inventory INVENTORY=${INVENTORY:-'.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory'} # the path to the Ansible test playbook PLAYBOOK=${PLAYBOOK:-test.yml} # the logfile to hold the output of the playbook run LOGFILE="log/${BOX}_idempotence_${VIRTUALENV_NAME}.log" EXTRA_ARGS='' if [ $BOX == "localhost" ]; then INVENTORY='localhost,' EXTRA_ARGS="--connection=local -e env=${ENV} -e vagrant_box=localhost" else EXTRA_ARGS="--user vagrant -e env=vagrant -e vagrant_box=${BOX}" fi echo "[INFO] ${BOX} ${VIRTUALENV_NAME} running idempotence test..." IDEMPOTENCE='yes' \ ansible-playbook -vvvv -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | \ tee ${LOGFILE} | \ grep "${BOX}" | grep -q "${PASS_CRITERIA}" && \ echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${GREEN}PASS${NC}\n" || ( \ cat ${LOGFILE} && echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && \ exit 1) ================================================ FILE: tests/travis.sh ================================================ #!/usr/bin/env bash # ################# # # Bash script to run tests in the travis-ci environment. # # version: 1.0 # # usage: # # travis.sh # # example: # # bash travis.sh # # changelog: # # v1.0 : 10 June 2016 # - initial version # # author(s): # - Pedro Salgado # # ################# test $USER != 'travis' && exit 0 set -e ansible-playbook \ -i localhost, \ --connection=local test.yml \ -e vagrant_box=localhost \ -e env=travis \ --skip-tags=test \ $@ \ && bash test_idempotence.sh \ --env travis \ && bash test_checkmode.sh \ --env travis ================================================ FILE: tests/vagrant.sh ================================================ #!/usr/bin/env bash # ################# # # Bash script to run the test suite against the Vagrant environment. # # version: 1.8 # # usage: # # # run tests against all enabled Vagrant boxes # $ bash vagrant.sh # # # run tests against a single Vagrant box # $ bash vagrant.sh --box precise64.vagrant.dev # # # changelog: # # v1.8 : 10 August 2016 # - force provisioning # # v1.6 : 10 Jun 2016 # - exit if USER environment variable is travis # # v1.4 : 10 Jul 2015 # - remove environment variable ANSIBLE_ASK_SUDO_PASS # # author(s): # - Pedro Salgado # # ################# test $USER == 'travis' && exit 0 DIR="$(dirname "$0")" cd $DIR # the path to the Ansible inventory generated by Vagrant INVENTORY=${DIR}/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory while [[ $# > 1 ]] do key="$1" case $key in --box) # the name of the Vagrant box to run tests against BOX="$2" shift;; *) # unknown option ;; esac shift done for VAGRANT_BOX in `grep vagrant.dev boxes.yml | sed 's/://g'` do if [ ! -n "${BOX+1}" ] || [ "${BOX}" = "${VAGRANT_BOX}" ]; then echo "[INFO] preparing ${VAGRANT_BOX}..." vagrant up --provision ${VAGRANT_BOX} 2> /dev/null if [ $? -ne 0 ]; then # box not enabled continue fi bash ${DIR}/test_idempotence.sh --box ${VAGRANT_BOX} --inventory $INVENTORY bash ${DIR}/test_checkmode.sh --box ${VAGRANT_BOX} --inventory $INVENTORY echo "[INFO] destroy ${VAGRANT_BOX}..." vagrant destroy -f ${VAGRANT_BOX} fi done ================================================ FILE: tox.ini ================================================ [tox] envlist = py{36}-ansible{28,27,26,25},py27-{24,23,22,21,20} skipsdist = True [testenv] changedir = tests deps = ansible28: ansible>=2.8,<2.9 ansible27: ansible>=2.7,<2.8 ansible26: ansible>=2.6,<2.7 ansible25: ansible>=2.5,<2.6 ansible24: ansible>=2.4,<2.5 ansible23: ansible>=2.3,<2.4 ansible22: ansible>=2.2,<2.3 ansible21: ansible>=2.1,<2.2 ansible20: ansible>=2.0.0,<2.1 ansible-lint==4.1.0 yamllint==1.15.0 passenv = ANSIBLE_ASK_SUDO_PASS HOME LANG LC_ALL TRAVIS USER commands = yamllint -c ../.yamllint.yml .. ansible-lint --exclude .tox .. bash setup.sh bash travis.sh {posargs} bash vagrant.sh {posargs} whitelist_externals = bash