imfreedom/teamcity-ansible

Parents 4921ec257d96
Children 33043da9fe57
split the teamcity role into multiple files to make it easier to manage
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/teamcity/tasks/agent.yml Sun Nov 10 04:21:30 2019 -0600
@@ -0,0 +1,53 @@
+---
+- name: set internal var for buildAgent.zip url
+ set_fact:
+ teamcity_build_agent_zip_url: "{{teamcity_server}}update/buildAgent.zip"
+- name: set internal var for teamcity_agent_home
+ set_fact:
+ teamcity_agent_home: "{{teamcity_home}}tc/"
+
+- name: "create directory {{teamcity_agent_home}}"
+ file:
+ name: "{{teamcity_agent_home}}"
+ state: directory
+ owner: "{{teamcity_user}}"
+ group: "{{teamcity_group}}"
+
+- name: download and extract buildAgent.zip
+ unarchive:
+ remote_src: yes
+ src: "{{teamcity_build_agent_zip_url}}"
+ dest: "{{teamcity_agent_home}}"
+ owner: "{{teamcity_user}}"
+ group: "{{teamcity_group}}"
+
+- name: check for agent configuration
+ stat:
+ path: "{{teamcity_agent_home}}conf/buildAgent.properties"
+ register: build_agent_properties
+
+- name: save authorizationToken
+ shell: "grep authorizationToken= {{teamcity_agent_home}}conf/buildAgent.properties | cut -d= -f2-"
+ register: _build_agent_token
+ when: build_agent_properties.stat.exists
+
+- name: set authorization token
+ set_fact:
+ teamcity_authorization_token: "{{_build_agent_token.stdout}}"
+ when: _build_agent_token.changed
+
+- name: configure agent
+ copy:
+ dest: "{{teamcity_agent_home}}conf/buildAgent.properties"
+ content: |
+ serverUrl={{teamcity_server}}
+ name={{ansible_hostname}}
+ workDir=../work
+ tempDir=../temp
+ systemDir=../system
+ authorizationToken={{teamcity_authorization_token}}
+ {% for item in teamcity_properties %}{{item}}
+ {% endfor %}
+ owner: "{{teamcity_user}}"
+ group: "{{teamcity_group}}"
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/teamcity/tasks/debian.yml Sun Nov 10 04:21:30 2019 -0600
@@ -0,0 +1,8 @@
+---
+- name: install dependencies
+ apt:
+ name:
+ - unzip
+ - openjdk-11-jre-headless
+ state: present
+ force_apt_get: true
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/teamcity/tasks/freebsd.yml Sun Nov 10 04:21:30 2019 -0600
@@ -0,0 +1,48 @@
+---
+- name: install dependencies
+ pkgng:
+ name: unzip,openjdk11
+ state: present
+
+- name: install init script
+ copy:
+ dest: /usr/local/etc/rc.d/teamcity-agent
+ content: |
+ #!/bin/sh
+
+ # PROVIDE: teamcity-agent
+ # REQUIRE: DAEMON
+
+ . /etc/rc.subr
+
+ name="teamcity_agent"
+ rcvar="teamcity_agent_enable"
+
+ start_cmd=teamcity_agent_start_cmd
+ stop_cmd=teamcity_agent_stop_cmd
+
+ teamcity_agent_user="{{teamcity_user}}"
+ teamcity_agent_group="{{teamcity_group}}"
+
+ teamcity_agent_start_cmd() {
+ checkyesno teamcity_agent_enable && {{teamcity_agent_home}}bin/agent.sh start
+ }
+
+ teamcity_agent_stop_cmd() {
+ checkyesno teamcity_agent_enable && {{teamcity_agent_home}}bin/agent.sh stop
+ }
+
+ PATH="$PATH:/usr/local/bin"
+
+ pidfile="{{teamcity_agent_home}}logs/buildAgent.pid"
+
+ load_rc_config "${name}"
+ run_rc_command "$1"
+ mode: '0555'
+
+- name: restart agent
+ service:
+ name: teamcity-agent
+ state: restarted
+ enabled: yes
+
--- a/roles/teamcity/tasks/main.yml Sun Nov 10 04:09:09 2019 -0600
+++ b/roles/teamcity/tasks/main.yml Sun Nov 10 04:21:30 2019 -0600
@@ -4,174 +4,13 @@
fail: msg="ERROR - required variable 'teamcity_server' missing"
when: teamcity_server is not defined
-- name: set internal var for buildAgent.zip url
- set_fact:
- teamcity_build_agent_zip_url: "{{teamcity_server}}update/buildAgent.zip"
-- name: set internal var for teamcity_agent_home
- set_fact:
- teamcity_agent_home: "{{teamcity_home}}tc/"
-
-- name: install dependencies (Debian)
- apt:
- name:
- - unzip
- state: present
- force_apt_get: true
- when: ansible_facts['os_family'] == "Debian"
-
-- name: install dependencies (FreeBSD)
- pkgng:
- name: unzip,openjdk11
- state: present
- when: ansible_system == "FreeBSD"
-
-- name: "create group: {{teamcity_group}}"
- group:
- name: "{{teamcity_group}}"
- system: yes
-
-- name: "create user: {{teamcity_user}}"
- user:
- name: "{{teamcity_user}}"
- shell: /bin/false
- group: "{{teamcity_group}}"
- groups: "{{teamcity_groups}}"
- system: yes
- createhome: yes
- home: "{{teamcity_home}}"
-
-- name: "create directory {{teamcity_agent_home}}"
- file:
- name: "{{teamcity_agent_home}}"
- state: directory
- owner: "{{teamcity_user}}"
- group: "{{teamcity_group}}"
-
-- name: download and extract buildAgent.zip
- unarchive:
- remote_src: yes
- src: "{{teamcity_build_agent_zip_url}}"
- dest: "{{teamcity_agent_home}}"
- owner: "{{teamcity_user}}"
- group: "{{teamcity_group}}"
-
-- name: check for agent configuration
- stat:
- path: "{{teamcity_agent_home}}conf/buildAgent.properties"
- register: build_agent_properties
-
-- name: save authorizationToken
- shell: "grep authorizationToken= {{teamcity_agent_home}}conf/buildAgent.properties | cut -d= -f2-"
- register: _build_agent_token
- when: build_agent_properties.stat.exists
+- include_tasks: user.yml
+- include_tasks: agent.yml
-- name: set authorization token
- set_fact:
- teamcity_authorization_token: "{{_build_agent_token.stdout}}"
- when: _build_agent_token.changed
-
-- name: configure agent
- copy:
- dest: "{{teamcity_agent_home}}conf/buildAgent.properties"
- content: |
- serverUrl={{teamcity_server}}
- name={{ansible_hostname}}
- workDir=../work
- tempDir=../temp
- systemDir=../system
- authorizationToken={{teamcity_authorization_token}}
- {% for item in teamcity_properties %}{{item}}
- {% endfor %}
- owner: "{{teamcity_user}}"
- group: "{{teamcity_group}}"
-
-- name: install init script
- copy:
- dest: /usr/local/etc/rc.d/teamcity-agent
- content: |
- #!/bin/sh
-
- # PROVIDE: teamcity-agent
- # REQUIRE: DAEMON
-
- . /etc/rc.subr
-
- name="teamcity_agent"
- rcvar="teamcity_agent_enable"
-
- start_cmd=teamcity_agent_start_cmd
- stop_cmd=teamcity_agent_stop_cmd
-
- teamcity_agent_user="{{teamcity_user}}"
- teamcity_agent_group="{{teamcity_group}}"
-
- teamcity_agent_start_cmd() {
- checkyesno teamcity_agent_enable && {{teamcity_agent_home}}bin/agent.sh start
- }
-
- teamcity_agent_stop_cmd() {
- checkyesno teamcity_agent_enable && {{teamcity_agent_home}}bin/agent.sh stop
- }
-
- PATH="$PATH:/usr/local/bin"
-
- pidfile="{{teamcity_agent_home}}logs/buildAgent.pid"
-
- load_rc_config "${name}"
- run_rc_command "$1"
- mode: '0555'
- when: ansible_system == "FreeBSD"
-
-- name: reetart agent (init)
- service:
- name: teamcity-agent
- state: restarted
- enabled: yes
- when: ansible_system == "FreeBSD"
-
-
-- name: check for systemd unit
- stat:
- path: /etc/systemd/system/teamcity-agent.service
- register: systemd_unit
+- include_tasks: debian.yml
+ when: ansible_facts['os_family'] == "Debian"
+- include_tasks: systemd.yml
when: ansible_system == "Linux"
-- name: stop agent (systemd)
- systemd:
- name: teamcity-agent
- state: stopped
- ignore_errors: yes
- when: ansible_system == "Linux" and systemd_unit.stat.exists
-
-- name: install systemd unit
- copy:
- dest: /etc/systemd/system/teamcity-agent.service
- content: |
- [Unit]
- Description=TeamCity Build Agent
- After=network.target
-
- [Service]
- Type=oneshot
-
- User={{teamcity_user}}
- Group={{teamcity_group}}
-
- ExecStart={{teamcity_agent_home}}bin/agent.sh start
- ExecStop={{teamcity_agent_home}}bin/agent.sh stop
-
- RemainAfterExit=yes
-
- SuccessExitStatus=0 143
-
- [Install]
- WantedBy=multi-user.target
- when: ansible_system == "Linux"
-
-- name: start agent (systemd)
- systemd:
- name: teamcity-agent
- state: started
- daemon_reload: yes
- when: ansible_system == "Linux"
-
+- include_tasks: freebsd.yml
+ when: ansible_system == "FreeBSD"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/teamcity/tasks/systemd.yml Sun Nov 10 04:21:30 2019 -0600
@@ -0,0 +1,42 @@
+---
+- name: check for systemd unit
+ stat:
+ path: /etc/systemd/system/teamcity-agent.service
+ register: systemd_unit
+
+- name: stop agent (systemd)
+ systemd:
+ name: teamcity-agent
+ state: stopped
+ ignore_errors: yes
+ when: systemd_unit.stat.exists
+
+- name: install systemd unit
+ copy:
+ dest: /etc/systemd/system/teamcity-agent.service
+ content: |
+ [Unit]
+ Description=TeamCity Build Agent
+ After=network.target
+
+ [Service]
+ Type=oneshot
+
+ User={{teamcity_user}}
+ Group={{teamcity_group}}
+
+ ExecStart={{teamcity_agent_home}}bin/agent.sh start
+ ExecStop={{teamcity_agent_home}}bin/agent.sh stop
+
+ RemainAfterExit=yes
+
+ SuccessExitStatus=0 143
+
+ [Install]
+ WantedBy=multi-user.target
+
+- name: start agent
+ systemd:
+ name: teamcity-agent
+ state: started
+ daemon_reload: yes
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/teamcity/tasks/user.yml Sun Nov 10 04:21:30 2019 -0600
@@ -0,0 +1,16 @@
+---
+- name: "create group: {{teamcity_group}}"
+ group:
+ name: "{{teamcity_group}}"
+ system: yes
+
+- name: "create user: {{teamcity_user}}"
+ user:
+ name: "{{teamcity_user}}"
+ shell: /bin/false
+ group: "{{teamcity_group}}"
+ groups: "{{teamcity_groups}}"
+ system: yes
+ createhome: yes
+ home: "{{teamcity_home}}"
+