commit fcb0d93080e26d47d601c7e477eb90bf07b2e855 Author: lhahn Date: Sun Aug 20 10:31:17 2023 +0200 Git initial commit diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..2071b23 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..860136e --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# cloud-nexus + +Ansible role to provide Sonatype Nexus as artifact storage. \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100755 index 0000000..bfe034a --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,16 @@ +--- +cloud_apps: /opt +cloud_storage: /opt/storage +cloud_stage: prod +cloud_update: false + +java_home: "{{ cloud_apps }}/java-jdk/java" + +nexus_source: https://download.sonatype.com/nexus/3 +nexus_version: 3.37.3-02 + +nexus_java_home: "{{ java_home }}" + +nexus_data_location: "{{ cloud_storage }}/sonatype-nexus-data" +nexus_http_port: 8081 +nexus_http_host: 0.0.0.0 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100755 index 0000000..d83807b --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart nexus + systemd: + name: nexus + state: restarted + diff --git a/meta/main.yml b/meta/main.yml new file mode 100755 index 0000000..fcc562a --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,17 @@ +--- +galaxy_info: + role_name: nexus + namespace: hahn-cloud + author: Lars Hahn + company: OpenDevChain + license: MIT + description: Role to setup Sonatype Nexus Repository 3.X + min_ansible_version: 2.7 + platforms: + - name: Debian + versions: + - 11 + galaxy_tags: + - nexus +dependencies: + - java diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100755 index 0000000..c607479 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,99 @@ +--- +- name: setup nexus group + group: + name: "{{ nexus_usr }}" + state: "present" + +- name: setup nexus user + user: + name: "{{ nexus_usr }}" + group: "{{ nexus_grp }}" + groups: + - "{{ nexus_grp }}" + comment: Virtual Sonytype Nesus User + shell: /bin/bash + state: present + system: yes + +- name: setup nexus directories + file: + state: directory + path: "{{ item }}" + owner: "{{ nexus_usr }}" + group: "{{ nexus_grp }}" + mode: 0750 + loop: + - "{{ nexus_home }}" + - "{{ nesux_dir }}" + +- name: download nexus + unarchive: + src: "{{ nexus_source }}/nexus-{{ nexus_version }}-unix.tar.gz" + dest: "{{ nesux_dir }}" + remote_src: yes + owner: "{{ nexus_usr }}" + group: "{{ nexus_grp }}" + mode: 0750 + creates: "{{ nexus_inst }}" + register: nexus_install + +- block: + - name: move nexus home appropriately + copy: + src: "{{ nesux_dir }}/sonatype-work/nexus3" + dest: "{{ nexus_home }}" + owner: "{{ nexus_usr }}" + group: "{{ nexus_grp }}" + mode: 0750 + - name: remove old home directory + file: + path: "{{ nesux_dir }}/sonatype-work" + state: absent + when: nexus_install.changed + +- name: link installed nexus homedir + file: + state: link + src: "{{ nexus_inst }}" + dest: "{{ nexus_link }}" + owner: "{{ nexus_usr }}" + group: "{{ nexus_grp }}" + +- name: setup nexus config directory + file: + state: directory + path: "{{ nexus_home }}/nexus3/etc" + owner: "{{ nexus_usr }}" + group: "{{ nexus_grp }}" + mode: 0750 + +- name: setup nexus vmoptions + template: + src: opt/sonatype-nexus/nexus/bin/nexus.vmoptions.j2 + dest: "{{nexus_inst }}/bin/nexus.vmoptions" + owner: "{{ nexus_usr }}" + group: "{{ nexus_grp }}" + mode: 0750 + notify: restart nexus + +- name: setup nexus properties + template: + src: opt/sonatype-nexus-data/nexus-config/nexus.properties.j2 + dest: "{{ nexus_home }}/nexus3/etc/nexus.properties" + owner: "{{ nexus_usr }}" + group: "{{ nexus_grp }}" + mode: 0750 + notify: restart nexus + +- name: setup nexus systemd unit + template: + src: etc/systemd/system/nexus.service.j2 + dest: /etc/systemd/system/nexus.service + notify: restart nexus + +- name: enable nexus systemd unit + systemd: + name: nexus + enabled: yes + daemon_reload: yes + state: started diff --git a/templates/etc/systemd/system/nexus.service.j2 b/templates/etc/systemd/system/nexus.service.j2 new file mode 100755 index 0000000..7ea689e --- /dev/null +++ b/templates/etc/systemd/system/nexus.service.j2 @@ -0,0 +1,16 @@ +[Unit] +Description=nexus service +After=network.target + +[Service] +Type=forking +LimitNOFILE=65536 +Environment="JAVA_HOME={{ nexus_java_home }}" +ExecStart={{ nexus_link }}/bin/nexus start +ExecStop={{ nexus_link }}/bin/nexus stop +User={{ nexus_usr }} +Restart=on-abort +TimeoutSec=600 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/templates/opt/sonatype-nexus-data/nexus-config/nexus.properties.j2 b/templates/opt/sonatype-nexus-data/nexus-config/nexus.properties.j2 new file mode 100755 index 0000000..6c998ce --- /dev/null +++ b/templates/opt/sonatype-nexus-data/nexus-config/nexus.properties.j2 @@ -0,0 +1,12 @@ +# Jetty section +application-port={{ nexus_http_port }} +application-host={{ nexus_http_host }} +# nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml +nexus-context-path=/ + +# Nexus section +# nexus-edition=nexus-pro-edition +# nexus-features=\ +# nexus-pro-feature + +# nexus.hazelcast.discovery.isEnabled=true diff --git a/templates/opt/sonatype-nexus/nexus/bin/nexus.vmoptions.j2 b/templates/opt/sonatype-nexus/nexus/bin/nexus.vmoptions.j2 new file mode 100755 index 0000000..8b704ad --- /dev/null +++ b/templates/opt/sonatype-nexus/nexus/bin/nexus.vmoptions.j2 @@ -0,0 +1,40 @@ +-Xms{{ nexus_javaheap_min | default('2703m') }} +-Xmx{{ nexus_javaheap_max | default('2703m') }} +-XX:MaxDirectMemorySize={{ nexus_javaheap_directmax | default('2703m') }} +-XX:+UnlockDiagnosticVMOptions +-XX:+LogVMOutput +-XX:LogFile={{ nexus_home }}/nexus3/log/jvm.log +-XX:-OmitStackTraceInFastThrow +-Djava.net.preferIPv4Stack=true +-Dkaraf.home=. +-Dkaraf.base=. +-Dkaraf.etc=etc/karaf +-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties +-Dkaraf.data={{ nexus_home }}/nexus3 +-Dkaraf.log={{ nexus_home }}/nexus3/log +-Djava.io.tmpdir={{ nexus_home }}/nexus3/tmp +-Dkaraf.startLocalConsole=false +-Djdk.tls.ephemeralDHKeySize=2048 +# +# additional vmoptions needed for Java9+ +# +# --add-reads=java.xml=java.logging +# --add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED +# --patch-module java.base=${KARAF_HOME}/lib/endorsed/org.apache.karaf.specs.locator-4.3.2.jar +# --patch-module java.xml=${KARAF_HOME}/lib/endorsed/org.apache.karaf.specs.java.xml-4.3.2.jar +# --add-opens java.base/java.security=ALL-UNNAMED +# --add-opens java.base/java.net=ALL-UNNAMED +# --add-opens java.base/java.lang=ALL-UNNAMED +# --add-opens java.base/java.util=ALL-UNNAMED +# --add-opens java.naming/javax.naming.spi=ALL-UNNAMED +# --add-opens java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED +# --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED +# --add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED +# --add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED +# --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED +# --add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED +# --add-exports java.security.sasl/com.sun.security.sasl=ALL-UNNAMED +# +# comment out this vmoption when using Java9+ +# +-Djava.endorsed.dirs=lib/endorsed \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100755 index 0000000..3c42d8e --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,8 @@ +--- +nexus_usr: sonanexus +nexus_grp: "{{ nexus_usr }}" + +nesux_dir: "{{ cloud_apps }}/sonatype-nexus" +nexus_inst: "{{ nesux_dir }}/nexus-{{ nexus_version }}" +nexus_home: "{{ nexus_data_location }}" +nexus_link: "{{ nesux_dir }}/nexus" \ No newline at end of file