Skip to content

Commit

Permalink
Merge pull request #2 from stone-payments/feature/debian-rhel
Browse files Browse the repository at this point in the history
Debian support
  • Loading branch information
douglasquintanilha authored Mar 25, 2019
2 parents b2fab19 + 995e860 commit 66cf4b9
Show file tree
Hide file tree
Showing 13 changed files with 395 additions and 189 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ VSTS-Agent



A role to install and configure the VSTS-agent (Microsoft Visual Studio Team Services Build and Release Agent) for RedHat Enterprise 7.2+
A role to install and configure the VSTS-agent (Microsoft Visual Studio Team Services Build and Release Agent) for RedHat Enterprise 7.2+ and Debian OS Family



Requirements
------------

python-pip to install a newer version of pexpect. Also rh-git29 is installed from software-collections, as VSTS requires a newer version of git.
python-pip to install a newer version of pexpect and libcurl4-gnutls-dev for Debian OS Family. Also rh-git29 is installed from software-collections, as VSTS requires a newer version of git.

Role Variables
--------------
Expand Down
22 changes: 11 additions & 11 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ vsts_github_api: "https://api.github.com/repos/Microsoft/vsts-agent/releases/lat

# If vsts_agent_fullurl is set this specific version will be downloaded instead of latest
# https://vstsagentpackage.azureedge.net/agent/2.129.0/vsts-agent-linux-x64-2.129.0.tar.gz
vsts_agent_version: "2.129.0"
vsts_agent_version: "2.146.0"
vsts_agent_baseurl: "https://vstsagentpackage.azureedge.net/agent"
vsts_agent_file: "vsts-agent-linux-x64-{{vsts_agent_version}}.tar.gz"
vsts_agent_fullurl: "{{vsts_agent_baseurl}}/{{vsts_agent_version}}/{{vsts_agent_file}}"
#vsts_agent_user: "deploy"
vsts_agent_file: "vsts-agent-linux-x64-{{ vsts_agent_version }}.tar.gz"
vsts_agent_fullurl: "{{ vsts_agent_baseurl }}/{{ vsts_agent_version }}/{{ vsts_agent_file }}"
vsts_agent_user: "vstsuser"

vsts_accountname: "ENTERYOURACCOUNTNAME"
#ENTERYOURPOOLNAME
vsts_poolname: ""
# To use Deployment Group
vsts_deploymentgroupname: ""
vsts_proxyurl: ""

vsts_server_url: "https://{{vsts_accountname}}.visualstudio.com/"
vsts_agent_name: "{{ansible_hostname}}"
vsts_agentfolder: "/home/{{vsts_agent_user}}/agent/"
vsts_workfolder: "/home/{{vsts_agent_user}}/work/"
vsts_server_url: "https://{{ vsts_accountname }}.visualstudio.com/"
vsts_agent_name: "{{ ansible_hostname }}"
vsts_agentfolder: "/home/{{ vsts_agent_user }}/agent/"
vsts_workfolder: "/home/{{ vsts_agent_user }}/work/"

vsts_remove: false

runsvc_regex_fileline:
- { regex: '^source /opt/rh/rh-git29/enable', line: 'source /opt/rh/rh-git29/enable'}
vsts_reinstall: false
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
- name: Register base install command as fact in variable install_command
set_fact:
install_command: "./config.sh --unattended --acceptteeeula --url {{vsts_server_url}} --auth PAT --token {{vsts_accesstoken}} --agent {{vsts_agent_name}} --work {{vsts_workfolder}} --replace"

- name: Add agent pool to install command (default queue-agent)
set_fact:
install_command: "{{ install_command }} --pool {{ vsts_poolname }}"
when: vsts_poolname|default("") != ""

- name: Add proxy-url to install command
set_fact:
install_command: "{{ install_command }} --proxyurl {{ vsts_proxyurl }}"
when: vsts_proxyurl|default("") != ""

- name: Add deployment group info to install command (deployment group agent)
set_fact:
install_command: "{{ install_command }} --projectname {{ vsts_projectname}} --deploymentgroup --deploymentgroupname {{ vsts_deploymentgroupname}} "
when:
- vsts_deploymentgroupname|default("") != ""
- vsts_projectname|default("") != ""

- name: Fail for conflicting options for default agent x deployment agent
fail:
msg: "The vsts_poolname({{ vsts_poolname }}) and vsts_deploymentgroupname({{ vsts_deploymentgroupname }}) vars are present at same time, choose one of them to install the default queue/build agent or the deployment group agent."
when:
- vsts_poolname|default("") != ""
- vsts_deploymentgroupname|default("") != ""

- name: Fail for missing parameters in install command
fail:
msg: "Neither the vsts_poolname({{ AGENT_POOL }}) or the vsts_deploymentgroupname({{ vsts_deploymentgroupname }}) vars are present, choose one of them to install the default queue/build agent or the deployment group agent."
when:
- vsts_poolname|default("") == ""
- vsts_deploymentgroupname|default("") == ""

- name: Configure vsts-agent
command: "{{ install_command }}"
args:
chdir: "{{vsts_agentfolder}}"
creates: "{{vsts_agentfolder}}/.agent"
- name: Register base install command as fact in variable install_command
set_fact:
install_command: "./config.sh --unattended --acceptteeeula --url {{vsts_server_url}} --auth PAT --token {{vsts_accesstoken}} --agent {{vsts_agent_name}} --work {{vsts_workfolder}} --replace"

- name: Add agent pool to install command (default queue-agent)
set_fact:
install_command: "{{ install_command }} --pool {{ vsts_poolname }}"
when: vsts_poolname|default("") != ""

- name: Add proxy-url to install command
set_fact:
install_command: "{{ install_command }} --proxyurl {{ vsts_proxyurl }}"
when: vsts_proxyurl|default("") != ""

- name: Add deployment group info to install command (deployment group agent)
set_fact:
install_command: "{{ install_command }} --projectname {{ vsts_projectname}} --deploymentgroup --deploymentgroupname {{ vsts_deploymentgroupname}} "
when:
- vsts_deploymentgroupname|default("") != ""
- vsts_projectname|default("") != ""

- name: Fail for conflicting options for default agent x deployment agent
fail:
msg: "The vsts_poolname({{ vsts_poolname }}) and vsts_deploymentgroupname({{ vsts_deploymentgroupname }}) vars are present at same time, choose one of them to install the default queue/build agent or the deployment group agent."
when:
- vsts_poolname|default("") != ""
- vsts_deploymentgroupname|default("") != ""

- name: Fail for missing parameters in install command
fail:
msg: "Neither the vsts_poolname({{ AGENT_POOL }}) or the vsts_deploymentgroupname({{ vsts_deploymentgroupname }}) vars are present, choose one of them to install the default queue/build agent or the deployment group agent."
when:
- vsts_poolname|default("") == ""
- vsts_deploymentgroupname|default("") == ""

- name: Configure vsts-agent
command: "{{ install_command }}"
args:
chdir: "{{vsts_agentfolder}}"
creates: "{{vsts_agentfolder}}/.agent"
become_user: "{{vsts_agent_user}}"
36 changes: 36 additions & 0 deletions tasks/debian/get_agent_files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: create "{{ vsts_agent_user }}" user for running the app
user:
name: "{{ vsts_agent_user }}"
groups: admin

- name: Create directories
file:
state: directory
path: "{{item}}"
owner: "{{vsts_agent_user}}"
group: "{{vsts_agent_user}}"
mode: 0755
with_items:
- "{{vsts_agentfolder}}"
- "{{vsts_workfolder}}"

- name: Fetch latest downloadurl if variable vsts_server_url is not defined
shell: "curl -s https://api.github.com/repos/Microsoft/vsts-agent/releases/latest | jq -r .assets[].browser_download_url | grep rhel"
delegate_to: localhost
register: githubapi_downloadurl_output
when: vsts_agent_fullurl is not defined

- name: Register githubapi_downloadurl_output as fact in variable vsts_agent_fullurl
set_fact:
vsts_agent_fullurl: "{{ githubapi_downloadurl_output.stdout_lines[0] }}"
when: vsts_agent_fullurl is not defined

- name: Download and unarchive
unarchive:
src: "{{vsts_agent_fullurl}}"
dest: "{{vsts_agentfolder}}"
remote_src: yes
owner: "{{vsts_agent_user}}"
group: "{{vsts_agent_user}}"
creates: "{{vsts_agentfolder}}/config.sh"
47 changes: 47 additions & 0 deletions tasks/debian/install_vsts_agent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
- name: Install required software for vsts-agent
apt:
name: "{{ item }}"
state: present
with_items:
- python-pip
- python-pexpect
- libcurl4-gnutls-dev
become: true

- name: Pip install pexpect (we need a new-enough version that isn't packaged in ubuntu and debian
pip:
name: "{{ item }}"
state: present
with_items:
- pexpect

- name: Installation dependencies
command: "./bin/installdependencies.sh"
args:
chdir: "{{ vsts_agentfolder }}"
creates: "/etc/systemd/system/vsts.agent.{{ vsts_accountname }}.{{ vsts_agent_name }}.service"
become: true
when: dryrun is not defined

- name: Include configure vsts-agent tasks
include_tasks: configure_vsts_agent.yml
when: dryrun is not defined

- name: Initial installation of systemd service files and generation of runsvc.sh
command: "./svc.sh install {{ vsts_agent_user }}"
args:
chdir: "{{ vsts_agentfolder }}"
creates: "/etc/systemd/system/vsts.agent.{{ vsts_accountname }}.{{ vsts_agent_name }}.service"
become: true
when: dryrun is not defined

- name: Enable and start vsts-agent service
service:
name: "vsts.agent.{{ vsts_accountname }}.{{ vsts_agent_name }}"
enabled: yes
state: started
become: true
when: dryrun is not defined
tags:
- service
24 changes: 24 additions & 0 deletions tasks/debian/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: Check if vsts agent service already installed
stat: path="/etc/systemd/system/vsts.agent.{{ vsts_accountname }}.{{ vsts_agent_name }}.service"
register: vsts_service_result
failed_when: vsts_service_result is not defined
ignore_errors: yes

- name: Include uninstall agent tasks
include_tasks: uninstall_vsts_agent.yml
when:
- vsts_service_result.stat.exists
- vsts_remove or vsts_reinstall

- name: Include get agent files tasks
include_tasks: get_agent_files.yml
when:
- not vsts_service_result.stat.exists or vsts_reinstall
- not vsts_remove

- name: Include install agent tasks
include_tasks: install_vsts_agent.yml
when:
- not vsts_service_result.stat.exists or vsts_reinstall
- not vsts_remove
34 changes: 34 additions & 0 deletions tasks/debian/uninstall_vsts_agent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Unconfigure vsts-agent - remove service
command: "./svc.sh uninstall"
args:
chdir: "{{vsts_agentfolder}}"
removes: "/etc/systemd/system/vsts.agent.{{ vsts_accountname }}.{{ vsts_agent_name }}.service"
when: vsts_remove|bool
become: true
tags:
- service
- unconfig

- name: Unconfigure vsts-agent
command: "./config.sh remove --unattended --auth PAT --token {{vsts_accesstoken}}"
args:
chdir: "{{vsts_agentfolder}}"
become_user: "{{vsts_agent_user}}"
when: vsts_remove|bool
tags:
- unconfig

# - name: remove "{{ vsts_agent_user }}" user for running the app
# user:
# name: "{{ vsts_agent_user }}"
# state: absent
# remove: yes

# - name: delete directories
# file:
# state: absent
# path: "{{item}}"
# with_items:
# - "{{vsts_agentfolder}}"
# - "{{vsts_workfolder}}"
Loading

0 comments on commit 66cf4b9

Please sign in to comment.