commit 954abfd958d7d2da16992160c47e25f81e7070d4 Author: Lennard Brinkhaus Date: Sat Dec 17 00:44:13 2022 +0100 first version of role diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9f24421 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +# EditorConfig: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Defaults for all editor files +[*] +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +# Files with a smaller indent +[*.yml] +indent_size = 2 + +# Jinja2 template files +[*.j2] +end_of_line = lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec2d6d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +local-configure.yml +.vagrant/ +docs/_build/ +roles/plone.plone_server +roles/jnv.unattended-upgrades +roles/tersmitten.fail2ban +roles/ANXS.hostname +roles/ANXS.apt +._* +bin/ +lib/ +include/ +local/ +tests.out +*.retry +*.log +vbox_host.cfg +.DS_Store +*.py[co] +.idea/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..17c134e --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +roles_path: ./../ diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..8b96cc3 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,9 @@ +--- +corretto_version_check: true +corretto_version: "19" +corretto_platform: "x64" +corretto_home: "/var/lib/corretto/{{ corretto_version }}" +corretto_delete_old: true +corretto_dl_link: "https://corretto.aws/downloads/latest/amazon-corretto-{{ corretto_version }}-{{ corretto_platform }}-linux-jdk.tar.gz" +corretto_dl_checksum_link: "https://corretto.aws/downloads/latest_sha256/amazon-corretto-{{ corretto_version }}-{{ corretto_platform }}-linux-jdk.tar.gz" +corretto_symlink_dest: "/usr/local/bin" diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..8000ba3 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,34 @@ +galaxy_info: + author: Lennard Brinkhaus + description: Install and manage Amazon Corretto + company: DragSE + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: + - name: Debian + versions: + - all + - name: Ubuntu + versions: + - all + + galaxy_tags: + - golang + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..1215669 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,86 @@ +--- +- block: + - name: Download Amazon Corretto + become: yes + get_url: + url: "{{ corretto_dl_link }}" + dest: "/tmp/corretto{{ corretto_version }}.tar.gz" + register: corretto_tar + + - name: Download Amazon Corretto checksum + become: yes + get_url: + url: "{{ corretto_dl_checksum_link }}" + dest: "/tmp/corretto{{ corretto_version }}.tar.gz.sha256" + + - name: Calculate SHA256 checksum of Corretto tar file + become: yes + command: "sha256sum /tmp/corretto{{ corretto_version }}.tar.gz" + register: corretto_checksum + + - name: get remote file contents + command: "cat '/tmp/corretto{{ corretto_version }}.tar.gz.sha256'" + register: checksum_from_file + + - name: "Set in sha256sum format" + set_fact: + checksum_format: "{{ checksum_from_file.stdout }} /tmp/corretto{{ corretto_version }}.tar.gz" + + - name: Compare Corretto checksum with official checksum + assert: + that: + - corretto_checksum.stdout == checksum_format + + - name: "Create data directory" + file: + path: "{{ corretto_home }}" + state: directory + owner: "root" + group: "root" + mode: 'u=rwX,g=rX,o=' + recurse: true + + - name: Unpack golang binary + unarchive: + remote_src: yes + src: "/tmp/corretto{{ corretto_version }}.tar.gz" + dest: "{{ corretto_home }}" + mode: 0755 + owner: root + group: root + list_files: true + register: unpacked + + - block: + - name: Copy files to new location + copy: + remote_src: True + src: "{{ corretto_home }}/{{ unpacked.files[0] }}" + dest: "{{ corretto_home }}/corretto/" + + - name: Remove old files + file: + path: "{{ corretto_home }}/{{ unpacked.files[0] }}" + state: absent + + - block: + - name: Load files for Symlink + find: + paths: "{{ corretto_home }}/corretto/bin" + register: symlink_files + + - name: Create Java symlink + file: + src: "{{ item.path }}" + dest: "{{ corretto_symlink_dest }}/{{ item.path.split(\"/\") | last }}" + state: link + loop: "{{ symlink_files.files }}" + + - block: + - name: Delete all files + file: + path: "/var/lib/corretto/{{ corretto_active_version }}" + state: "absent" + + when: corretto_delete_old|bool + when: (not corretto_version_check|bool) or (corretto_active_version != corretto_version) diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..d3838f3 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,16 @@ +--- + +- name: "Check java version" + ansible.builtin.shell: "java --version |cut -d' ' -f 2 | cut -d'.' -f 1 | head -1" + args: + executable: /bin/bash + register: corretto_active_version_sout + changed_when: false + failed_when: false + when: corretto_version_check|bool + +- name: "Set active version" + set_fact: + corretto_active_version: "{{ corretto_active_version_sout.stdout }}" + +- include_tasks: install.yml diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..ac96836 --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +192.168.1.142 diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..8e7b464 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: all + remote_user: root + roles: + - role-amazon-corretto diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..e69de29