diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a72cee --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Eclipse generated files and folders +.project +.settings diff --git a/.travis.yml b/.travis.yml index 96709cb..62bef39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,24 +11,20 @@ before_install: install: # Install Ansible. - - pip install ansible==1.6.3 + - pip install ansible script: - "cd tests" - # Check the role/playbook's syntax. - "ansible-playbook -i inventory $SITE --syntax-check" - # Run the role/playbook with ansible-playbook. - - "ansible-playbook -i inventory $SITE --connection=local --sudo" - + - "ansible-playbook -i inventory $SITE --connection=local" # Run the role/playbook again, checking to make sure it's idempotent. - > - ansible-playbook -i inventory $SITE --connection=local --sudo + ansible-playbook -i inventory $SITE --connection=local | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) - # Make sure Java is installed. - > which java diff --git a/tasks/Debian.yml b/tasks/Debian.yml index 5bdf44e..7f58d8b 100644 --- a/tasks/Debian.yml +++ b/tasks/Debian.yml @@ -1,29 +1,42 @@ --- -- include_vars: Ubuntu.yml +- name: Debian | OS variables + include_vars: + file: Ubuntu.yml -- name: Install python-apt - apt: pkg=python-apt +- name: Debian | Install python-apt + apt: + pkg: python-apt -- include: webupd8_for_debian.yml +- import_tasks: webupd8_for_debian.yml when: "ansible_distribution != 'Ubuntu'" -- include: webupd8_for_ubuntu.yml +- import_tasks: webupd8_for_ubuntu.yml when: ansible_distribution == 'Ubuntu' -- name: Accept Oracle License - debconf: name={{ item }} question='shared/accepted-oracle-license-v1-1' value='true' vtype='select' +- name: Debian | Update repository + apt: + update_cache: true + +- name: Debian | Accept Oracle License + debconf: + name: "{{ item }}" + question: 'shared/accepted-oracle-license-v1-1' + value: 'true' + vtype: 'select' with_items: - oracle-java6-installer - oracle-java7-installer - oracle-java8-installer when: java_needs_oracle -- name: Install Java packages - apt: pkg={{ item }} state=latest - with_items: "{{ java_packages }}" +- name: Debian | Install Java packages + apt: + pkg: "{{ java_packages }}" + state: latest -- name: Remove unwanted Java packages - apt: pkg={{ item }} state=absent - with_items: "{{ java_packages_to_remove }}" +- name: Debian | Remove unwanted Java packages + apt: + pkg: "{{ java_packages_to_remove|default([]) }}" + state: absent when: java_cleanup diff --git a/tasks/RedHat.yml b/tasks/RedHat.yml index 4c4ff99..5ec756d 100644 --- a/tasks/RedHat.yml +++ b/tasks/RedHat.yml @@ -1,6 +1,6 @@ --- - - name: Install Java packages - yum: name={{ item }} state=latest + yum: + name: "{{ item }}" + state: latest with_items: "{{ java_packages }}" - when: ansible_os_family == 'RedHat' diff --git a/tasks/main.yml b/tasks/main.yml index d621013..3a04b00 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,3 +1,6 @@ --- -- include: Debian.yml +- import_tasks: Debian.yml when: ansible_os_family == 'Debian' + +- import_tasks: RedHat.yml + when: ansible_os_family == 'RedHat' \ No newline at end of file diff --git a/tasks/webupd8.yml b/tasks/webupd8.yml deleted file mode 100644 index cd21505..0000000 --- a/tasks/webupd8.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- - diff --git a/tasks/webupd8_for_debian.yml b/tasks/webupd8_for_debian.yml index 2eca8c1..63ad480 100644 --- a/tasks/webupd8_for_debian.yml +++ b/tasks/webupd8_for_debian.yml @@ -1,16 +1,25 @@ --- -- name: Install WebUpd8 apt key - apt_key: id=EEA14886 keyserver='keyserver.ubuntu.com' state=present +- name: Debian | Install WebUpd8 apt key + apt_key: + id: EEA14886 + keyserver: 'keyserver.ubuntu.com' + state: present register: webupd8key until: webupd8key|success retries: 5 delay: 10 -- name: Install WebUpd8 Team Java PPA (for Oracle Java) - apt_repository: repo='deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main' state=present mode=0644 +- name: Debian | Install WebUpd8 Team Java PPA (for Oracle Java) + apt_repository: + repo: 'deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main' + state: present + mode: "0644" when: java_needs_oracle -- name: Remove WebUpd8 Team Java PPA (for Oracle Java) - apt_repository: repo='deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main' state=present mode=0644 +- name: Debian | Remove WebUpd8 Team Java PPA (for Oracle Java) + apt_repository: + repo: 'deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main' + state: present + mode: "0644" when: java_cleanup and not java_needs_oracle diff --git a/tasks/webupd8_for_ubuntu.yml b/tasks/webupd8_for_ubuntu.yml index 703d9d7..287a341 100644 --- a/tasks/webupd8_for_ubuntu.yml +++ b/tasks/webupd8_for_ubuntu.yml @@ -1,12 +1,18 @@ --- -- name: Install WebUpd8 Team Java PPA (for Oracle Java) - apt_repository: repo='ppa:webupd8team/java' state=present mode=0644 +- name: Ubuntu | Install WebUpd8 Team Java PPA (for Oracle Java) + apt_repository: + repo: 'ppa:webupd8team/java' + state: present + mode: "0644" when: java_needs_oracle register: webupd8ppa - until: webupd8ppa|success + until: webupd8ppa is success retries: 5 delay: 10 -- name: Remove WebUpd8 Team Java PPA (for Oracle Java) - apt_repository: repo='ppa:webupd8team/java' state=present mode=0644 +- name: Ubuntu | Remove WebUpd8 Team Java PPA (for Oracle Java) + apt_repository: + repo: 'ppa:webupd8team/java' + state: present + mode: "0644" when: java_cleanup and not java_needs_oracle diff --git a/tests/group_vars/test b/tests/group_vars/test index bb328d6..48b38de 100644 --- a/tests/group_vars/test +++ b/tests/group_vars/test @@ -1,5 +1,5 @@ --- java_packages: - - oracle-java8-set-default - - oracle-java8-installer - - openjdk-6-jdk + # - oracle-java8-set-default + # - oracle-java8-installer + - openjdk-11-jdk diff --git a/tests/test.yml b/tests/test.yml index b2e8ddf..e320335 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,5 +1,5 @@ --- - hosts: test - remote_user: root + become: true roles: - ansible-java-role diff --git a/vars/main.yml b/vars/main.yml index 87515b8..5bdf2c8 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ --- -java_needs_oracle: "{{ java_packages | join | search('oracle') }}" +java_needs_oracle: "{{ java_packages | join is search('oracle') }}"