imfreedom/teamcity-ansible
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 + teamcity_build_agent_zip_url: "{{teamcity_server}}update/buildAgent.zip" +- name: set internal var for teamcity_agent_home + teamcity_agent_home: "{{teamcity_home}}tc/" +- name: "create directory {{teamcity_agent_home}}" + name: "{{teamcity_agent_home}}" + owner: "{{teamcity_user}}" + group: "{{teamcity_group}}" +- name: download and extract buildAgent.zip + src: "{{teamcity_build_agent_zip_url}}" + dest: "{{teamcity_agent_home}}" + owner: "{{teamcity_user}}" + group: "{{teamcity_group}}" +- name: check for agent configuration + 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 + teamcity_authorization_token: "{{_build_agent_token.stdout}}" + when: _build_agent_token.changed + dest: "{{teamcity_agent_home}}conf/buildAgent.properties" + serverUrl={{teamcity_server}} + name={{ansible_hostname}} + authorizationToken={{teamcity_authorization_token}} + {% for item in teamcity_properties %}{{item}} + 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 + - openjdk-11-jre-headless --- /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 +- name: install init script + dest: /usr/local/etc/rc.d/teamcity-agent + # PROVIDE: 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}" --- 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
- teamcity_build_agent_zip_url: "{{teamcity_server}}update/buildAgent.zip"
-- name: set internal var for teamcity_agent_home
- teamcity_agent_home: "{{teamcity_home}}tc/"
-- name: install dependencies (Debian)
- when: ansible_facts['os_family'] == "Debian"
-- name: install dependencies (FreeBSD)
- when: ansible_system == "FreeBSD"
-- name: "create group: {{teamcity_group}}"
- name: "{{teamcity_group}}"
-- name: "create user: {{teamcity_user}}"
- name: "{{teamcity_user}}"
- group: "{{teamcity_group}}"
- groups: "{{teamcity_groups}}"
- home: "{{teamcity_home}}"
-- name: "create directory {{teamcity_agent_home}}"
- name: "{{teamcity_agent_home}}"
- owner: "{{teamcity_user}}"
- group: "{{teamcity_group}}"
-- name: download and extract buildAgent.zip
- src: "{{teamcity_build_agent_zip_url}}"
- dest: "{{teamcity_agent_home}}"
- owner: "{{teamcity_user}}"
- group: "{{teamcity_group}}"
-- name: check for agent configuration
- 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
- teamcity_authorization_token: "{{_build_agent_token.stdout}}"
- when: _build_agent_token.changed
- dest: "{{teamcity_agent_home}}conf/buildAgent.properties"
- serverUrl={{teamcity_server}}
- name={{ansible_hostname}}
- authorizationToken={{teamcity_authorization_token}}
- {% for item in teamcity_properties %}{{item}}
- owner: "{{teamcity_user}}"
- group: "{{teamcity_group}}"
-- name: install init script
- dest: /usr/local/etc/rc.d/teamcity-agent
- # PROVIDE: 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}"
- when: ansible_system == "FreeBSD"
-- name: reetart agent (init)
- when: ansible_system == "FreeBSD"
-- name: check for systemd unit
- path: /etc/systemd/system/teamcity-agent.service
+- include_tasks: debian.yml + when: ansible_facts['os_family'] == "Debian" +- include_tasks: systemd.yml when: ansible_system == "Linux"
-- name: stop agent (systemd)
- when: ansible_system == "Linux" and systemd_unit.stat.exists
-- name: install systemd unit
- dest: /etc/systemd/system/teamcity-agent.service
- Description=TeamCity Build Agent
- Group={{teamcity_group}}
- ExecStart={{teamcity_agent_home}}bin/agent.sh start
- ExecStop={{teamcity_agent_home}}bin/agent.sh stop
- SuccessExitStatus=0 143
- WantedBy=multi-user.target
- when: ansible_system == "Linux"
-- name: start agent (systemd)
- 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 + path: /etc/systemd/system/teamcity-agent.service +- name: stop agent (systemd) + when: systemd_unit.stat.exists +- name: install systemd unit + dest: /etc/systemd/system/teamcity-agent.service + Description=TeamCity Build Agent + Group={{teamcity_group}} + ExecStart={{teamcity_agent_home}}bin/agent.sh start + ExecStop={{teamcity_agent_home}}bin/agent.sh stop + SuccessExitStatus=0 143 + WantedBy=multi-user.target --- /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}}" + name: "{{teamcity_group}}" +- name: "create user: {{teamcity_user}}" + name: "{{teamcity_user}}" + group: "{{teamcity_group}}" + groups: "{{teamcity_groups}}" + home: "{{teamcity_home}}"