commit 1e1929c3fdb28c45c502eb60455a0ce9d2a3adb3 Author: Dak Thompson Date: Thu Jul 11 16:03:33 2024 -0500 Initial main commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc3beae --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/host_vars/server2.yml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..a723bc2 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..5372db1 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1720725841180 + + + + + + \ No newline at end of file diff --git a/group_vars/all/vault.yml b/group_vars/all/vault.yml new file mode 100644 index 0000000..1d00017 --- /dev/null +++ b/group_vars/all/vault.yml @@ -0,0 +1,13 @@ +$ANSIBLE_VAULT;1.1;AES256 +61383464396566303430643432623037336434356366383864336564613038353130646134653766 +3863636265343162636362663066373937356263653131320a626236653636313733656337383061 +64393736626434363033613332626162633633663435346432373965333937353564333131313364 +6639643934343036340a643163663431366430323563356131386436313861386634343462343132 +36393765356463373138323139323230396134323239626137656231396362636338326435376636 +32343136313535616537363831353735386264653331313738333161383133366266323938323239 +32303464333839343863633038343739323334313033373761303232383130306163323639326537 +38666336616531643338396662393533636561646534316566623366666366396139306266316139 +32346239323636613761343638623338346361653338363065383466306166373034323436643432 +61393034366665663633663862653333356536636237383964636463336363616530653333333363 +34613633313332356166366331363738373338363361366439313233653038383837323262316333 +35633462376563353232 diff --git a/hosts.yml b/hosts.yml new file mode 100644 index 0000000..4b8ff5f --- /dev/null +++ b/hosts.yml @@ -0,0 +1,9 @@ +--- +all: + hosts: + server1: + ansible_become_pass: "{{ server1_become_pass }}" + server2: + ansible_become_pass: "{{ server2_become_pass }}" + vars: + ansible_user: zoe diff --git a/roles/java/tasks/main.yml b/roles/java/tasks/main.yml new file mode 100644 index 0000000..0410c6d --- /dev/null +++ b/roles/java/tasks/main.yml @@ -0,0 +1,25 @@ +--- +- name: Install zip + become: yes + package: + name: zip + state: latest +- name: Install unzip + become: yes + package: + name: unzip + state: latest +- name: Install SDKMan + become: yes + become_user: "{{ sdkman_user }}" + shell: + chdir: "{{ ansible_env.HOME }}" + cmd: | + curl -s "https://get.sdkman.io" | bash +- name: Install Java + become: yes + become_user: "{{ sdkman_user }}" + shell: + chdir: "{{ ansible_env.HOME }}" + cmd: | + /bin/bash -lc "sdk install java {{ java_version }}-tem" diff --git a/roles/teamcity/files/buildAgent.properties b/roles/teamcity/files/buildAgent.properties new file mode 100644 index 0000000..3d8fbb4 --- /dev/null +++ b/roles/teamcity/files/buildAgent.properties @@ -0,0 +1,52 @@ +## TeamCity build agent configuration file + +###################################### +# Required Agent Properties # +###################################### + +## The address of the TeamCity server. The same as is used to open TeamCity web interface in the browser. +## Example: serverUrl=https://buildserver.mydomain.com:8111 +serverUrl=http://192.168.3.7:8111/ + +## The unique name of the agent used to identify this agent on the TeamCity server +## Use blank name to let server generate it. +## By default, this name would be created from the build agent's host name +name=Default Agent + +## Container directory to create default checkout directories for the build configurations. +## TeamCity agent assumes ownership of the directory and will delete unknown directories inside. +workDir=../work + +## Container directory for the temporary directories. +## TeamCity agent assumes ownership of the directory. The directory may be cleaned between the builds. +tempDir=../temp + +## Container directory for agent state files and caches. +## TeamCity agent assumes ownership of the directory and can delete content inside. +systemDir=../system + + +###################################### +# Optional Agent Properties # +###################################### + +## A token which is used to identify this agent on the TeamCity server for agent authorization purposes. +## It is automatically generated and saved back on the first agent connection to the server. +authorizationToken= + + +###################################### +# Default Build Properties # +###################################### +## All properties starting with "system.name" will be passed to the build script as "name" +## All properties starting with "env.name" will be set as environment variable "name" for the build process +## Note that value should be properly escaped. (use "\\" to represent single backslash ("\")) +## More on file structure: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#load(java.io.InputStream) + +# Build Script Properties + +#system.exampleProperty=example Value + +# Environment Variables + +#env.exampleEnvVar=example Env Value \ No newline at end of file diff --git a/roles/teamcity/files/server.xml b/roles/teamcity/files/server.xml new file mode 100644 index 0000000..bc1c770 --- /dev/null +++ b/roles/teamcity/files/server.xml @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/roles/teamcity/tasks/build_deps.yml b/roles/teamcity/tasks/build_deps.yml new file mode 100644 index 0000000..720895e --- /dev/null +++ b/roles/teamcity/tasks/build_deps.yml @@ -0,0 +1,6 @@ +--- +- name: Install Git + become: yes + package: + name: git + state: latest diff --git a/roles/teamcity/tasks/main.yml b/roles/teamcity/tasks/main.yml new file mode 100644 index 0000000..0e7eca6 --- /dev/null +++ b/roles/teamcity/tasks/main.yml @@ -0,0 +1,8 @@ +--- +- name: Install Postgres + import_tasks: postgres.yml +- name: Install build deps + import_tasks: build_deps.yml +- name: Install TeamCity + import_tasks: teamcity.yml + diff --git a/roles/teamcity/tasks/postgres.yml b/roles/teamcity/tasks/postgres.yml new file mode 100644 index 0000000..d998426 --- /dev/null +++ b/roles/teamcity/tasks/postgres.yml @@ -0,0 +1,50 @@ +--- +- name: Update sudoers + become: yes + community.general.sudoers: + name: zoe-do-as-postgres + state: present + user: zoe + runas: postgres + commands: ALL +- name: Create teamcity PostgreSQL user + become: yes + become_user: postgres + postgresql_user: + name: teamcity + state: present + password: "{{ teamcity_psql_password }}" + role_attr_flags: CREATEDB + environment: + PGOPTIONS: "-c password_encryption=scram-sha-256" +- name: Update pg_hba conf + become: yes + postgresql_pg_hba: + contype: host + dest: /var/lib/pgsql/data/pg_hba.conf + method: scram-sha-256 + address: localhost + users: teamcity + state: present +- name: Reload PostgreSQL + become: yes + systemd: + name: postgresql + state: reloaded +- name: Create teamcity PostgreSQL DB + become: yes + become_user: postgres + postgresql_db: + name: teamcity + owner: teamcity + state: present + template: template0 + encoding: UTF8 + lc_collate: en_US.UTF-8 + lc_ctype: en_US.UTF-8 +- name: Create teamcity schema + become: yes + become_user: postgres + postgresql_schema: + name: teamcity + owner: teamcity diff --git a/roles/teamcity/tasks/teamcity.yml b/roles/teamcity/tasks/teamcity.yml new file mode 100644 index 0000000..c28b1e3 --- /dev/null +++ b/roles/teamcity/tasks/teamcity.yml @@ -0,0 +1,41 @@ +--- +- name: Download TeamCity + become: yes + unarchive: + src: https://download.jetbrains.com/teamcity/TeamCity-{{ teamcity_version }}.tar.gz + dest: /opt/teamcity + remote_src: yes + owner: teamcity + group: teamcity + mode: 0750 +- name: Upload TeamCity server configuration + become: yes + copy: + src: server.xml + dest: "/opt/teamcity/TeamCity/conf/server.xml" + owner: teamcity + group: teamcity + mode: 0750 +- name: Upload TeamCity buildAgent properties + become: yes + copy: + src: buildAgent.properties + dest: "/opt/teamcity/TeamCity/buildAgent/conf/buildAgent.properties" + owner: teamcity + group: teamcity + mode: 0750 +- name: Upload teamcity.service + become: yes + template: + src: teamcity.service + dest: /etc/systemd/system/teamcity.service + owner: root + group: root + mode: 0755 +- name: Restart TeamCity + become: yes + systemd: + enabled: yes + name: teamcity.service + state: restarted + daemon_reload: yes diff --git a/roles/teamcity/templates/teamcity.service b/roles/teamcity/templates/teamcity.service new file mode 100644 index 0000000..232740b --- /dev/null +++ b/roles/teamcity/templates/teamcity.service @@ -0,0 +1,19 @@ +[Unit] +Description=TeamCity: A Build Server +After=syslog.target +After=network.target + +Wants=postgresql.service +After=postgresql.service + +[Service] +User=teamcity +Group=teamcity + +ExecStart=/opt/teamcity/TeamCity/bin/runAll.sh start +ExecStop=/opt/teamcity/TeamCity/bin/runAll.sh stop +Environment=TEAMCITY_DATA_PATH={{ teamcity_data_path }} JAVA_HOME=/opt/teamcity/.sdkman/candidates/java/current +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..71a6c64 --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +ansible-playbook -i hosts.yml site.yml --vault-password-file ~/.vault_pass.txt diff --git a/site.yml b/site.yml new file mode 100644 index 0000000..d3022f0 --- /dev/null +++ b/site.yml @@ -0,0 +1,23 @@ +--- +- name: Setup TeamCity + hosts: server2 + vars: + teamcity_data_path: /opt/teamcity/data + pre_tasks: + - name: Create TeamCity Data dir + become: yes + file: + path: "{{ teamcity_data_path }}" + state: directory + recurse: yes + owner: teamcity + group: teamcity + mode: '750' + roles: + - role: java + vars: + sdkman_user: teamcity + java_version: 17.0.8.1 + - role: teamcity + vars: + teamcity_version: 2023.05.3