-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ansible): create roles for azagent, nodejs,
- Loading branch information
1 parent
77cefc9
commit bb8951e
Showing
8 changed files
with
236 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
- name: Initialize Olde World Cluster - Clients | ||
hosts: '{{ variable_host | default("null") }}' | ||
become: true | ||
become_user: freecodecamp | ||
gather_facts: false | ||
vars: | ||
client_groups: | ||
['chn', 'cnt', 'eng', 'esp', 'ger', 'ita', 'jpn', 'por', 'ukr'] | ||
client_hosts: ['1', '2'] | ||
client_env: '{{ variable_client_env | default("stg") }}' | ||
agent_version: '{{ variable_agent_version | default("3.220.5") }}' | ||
tasks: | ||
# - name: Create deployment groups from list of items | ||
# add_host: | ||
# groups: '{{ client_env }}_oldeworld_clt{{ item[0] }}' | ||
# name: '{{ client_env }}-vm-oldeworld-clt{{ item[0] }}-{{ item[1] }}' | ||
# with_nested: | ||
# - '{{ client_groups }}' | ||
# - '{{ client_hosts }}' | ||
|
||
# - name: Print deployment groups | ||
# debug: | ||
# msg: '{{ groups[client_env + "_oldeworld_clt" + item] }}' | ||
# with_items: '{{ client_groups }}' | ||
- name: Install or Update Node.js | ||
include_role: | ||
name: nodejs | ||
|
||
- name: Uninstall and remove azagent | ||
include_role: | ||
name: azagent | ||
tasks_from: delete-azagent.yml | ||
vars: | ||
agent_deploymentgroup_name: '{{ client_env }}-dp-clt{{ item[0] }}' | ||
agent_machine_name: | ||
'{{ client_env }}-vm-oldeworld-clt-{{ item[0] }}-{{ item[1] }}' | ||
agent_project_name: 'freeCodeCamp' | ||
agent_pat_token: '{{ variable_pat_token }}' | ||
loop: '{{ client_groups | product(client_hosts) | list }}' | ||
when: | ||
inventory_hostname == client_env + "-vm-oldeworld-clt" + item[0] + "-" + | ||
item[1] | ||
|
||
- name: Install azagent | ||
include_role: | ||
name: azagent | ||
tasks_from: install-azagent.yml | ||
vars: | ||
agent_deploymentgroup_name: '{{ client_env }}-dp-clt{{ item[0] }}' | ||
agent_machine_name: | ||
'{{ client_env }}-vm-oldeworld-clt-{{ item[0] }}-{{ item[1] }}' | ||
agent_project_name: 'freeCodeCamp' | ||
agent_pat_token: '{{ variable_pat_token }}' | ||
agent_download_url: | ||
'https://vstsagentpackage.azureedge.net/agent/{{ agent_version | ||
}}/vsts-agent-linux-x64-{{ agent_version }}.tar.gz' | ||
loop: '{{ client_groups | product(client_hosts) | list }}' | ||
when: | ||
inventory_hostname == client_env + "-vm-oldeworld-clt" + item[0] + "-" + | ||
item[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
- name: Initialize Olde World Cluster - Clients | ||
hosts: '{{ variable_host | default("null") }}' | ||
become: true | ||
become_user: freecodecamp | ||
gather_facts: false | ||
tasks: | ||
- name: Install or Update Node.js | ||
include_role: | ||
name: nodejs | ||
|
||
- name: Update azagent environment | ||
include_role: | ||
name: azagent | ||
tasks_from: update-azagent-env.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
azagent_dir: "/home/freecodecamp/azagent" | ||
vstsagent_tar_file: "vstsagent.tar.gz" | ||
azdevops_url: "https://dev.azure.com/freeCodeCamp-org/" | ||
work: "_work" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
- name: Check the installation directory | ||
stat: | ||
path: "{{ azagent_dir }}" | ||
register: azagent_dir_stat | ||
|
||
- name: Stop Azure DevOps agent service | ||
block: | ||
- name: Check azagent status | ||
shell: | ||
executable: /bin/bash | ||
cmd: | | ||
sudo ./svc.sh status | ||
chdir: "{{ azagent_dir }}" | ||
register: azagent_status_running | ||
ignore_errors: True | ||
|
||
- name: Stop azagent | ||
shell: | ||
executable: /bin/bash | ||
cmd: | | ||
sudo ./svc.sh stop | ||
chdir: "{{ azagent_dir }}" | ||
when: azagent_status_running.stdout.find('running') != -1 and azagent_status_running.stderr.find('command not found') == -1 | ||
ignore_errors: True | ||
|
||
- name: Check azagent status | ||
shell: | ||
executable: /bin/bash | ||
cmd: | | ||
sudo ./svc.sh status | ||
chdir: "{{ azagent_dir }}" | ||
register: azagent_status_installed | ||
changed_when: False | ||
ignore_errors: True | ||
|
||
- name: Uninstall azagent | ||
shell: | ||
executable: /bin/bash | ||
cmd: | | ||
sudo ./svc.sh uninstall | ||
chdir: "{{ azagent_dir }}" | ||
when: ( | ||
azagent_status_installed.stdout.find('not installed') != -1 or | ||
azagent_status_installed.stdout.find('dead') != -1 | ||
) and azagent_status_installed.stderr.find('command not found') == -1 | ||
ignore_errors: True | ||
|
||
- name: Remove the agent from the pool | ||
shell: | ||
executable: /bin/bash | ||
cmd: | | ||
./config.sh remove --unattended --auth pat --token '{{ agent_pat_token }}' | ||
chdir: "{{ azagent_dir }}" | ||
register: azagent_remove | ||
when: azagent_dir_stat.stat.exists | ||
|
||
- name: Delete azagent directory | ||
become: true | ||
become_user: root | ||
become_method: sudo | ||
file: | ||
path: "{{ azagent_dir }}" | ||
state: absent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
- name: Create directory for Azure DevOps agent | ||
file: | ||
path: "{{ azagent_dir }}" | ||
state: directory | ||
|
||
- name: Download Azure DevOps agent | ||
get_url: | ||
url: "{{ agent_download_url }}" | ||
dest: "{{ azagent_dir }}/{{ vstsagent_tar_file }}" | ||
mode: '0755' | ||
|
||
- name: Extract Azure DevOps agent tar file | ||
unarchive: | ||
src: "{{ azagent_dir }}/{{ vstsagent_tar_file }}" | ||
dest: "{{ azagent_dir }}" | ||
remote_src: yes | ||
|
||
- name: Configure Azure DevOps agent | ||
shell: | ||
executable: /bin/bash | ||
chdir: "{{ azagent_dir }}" | ||
cmd: | | ||
./config.sh \ | ||
--unattended \ | ||
--acceptteeeula \ | ||
--deploymentgroup \ | ||
--replace \ | ||
--runasservice \ | ||
--deploymentgroupname '{{ agent_deploymentgroup_name }}' \ | ||
--agent '{{ agent_machine_name }}' \ | ||
--url '{{ azdevops_url }}' \ | ||
--work '{{ work }}' \ | ||
--projectname '{{ agent_project_name }}' \ | ||
--auth pat \ | ||
--token '{{ agent_pat_token }}' | ||
- name: Install & Start Azure DevOps Pipeline Agent | ||
shell: | ||
cmd: | | ||
sudo ./svc.sh install | ||
sudo ./svc.sh start | ||
executable: /bin/bash | ||
chdir: "{{ azagent_dir }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
- name: Stop Azure DevOps Pipeline Agent | ||
shell: | ||
cmd: | | ||
sudo ./svc.sh stop | ||
executable: /bin/bash | ||
chdir: '{{ azagent_dir }}' | ||
|
||
- name: Update Env & Start Azure DevOps Pipeline Agent | ||
shell: | ||
cmd: | | ||
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] | ||
printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" | ||
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" | ||
nvm version && echo PATH=$PATH && echo NVM_BIN=$NVM_BIN | ||
./env.sh | ||
sudo ./svc.sh start | ||
executable: /bin/bash | ||
chdir: '{{ azagent_dir }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
- name: Update nvm to the latest version | ||
shell: | | ||
curl --silent "https://api.github.com/repos/nvm-sh/nvm/releases/latest" | | ||
grep '"tag_name":' | | ||
sed -E 's/.*"([^"]+)".*/\1/' | | ||
xargs -I % curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/%/install.sh | | ||
bash | ||
args: | ||
executable: /bin/bash | ||
|
||
- name: Update Node.js to the latest version | ||
shell: | | ||
source ~/.nvm/nvm.sh | ||
if [[ $(nvm version) == 'none' ]] ; then | ||
nvm install --lts --latest-npm --default | ||
else | ||
nvm install --lts --latest-npm --default --reinstall-packages-from=node | ||
fi | ||
node --version | xargs npx -y cowsay 'hello from node' | ||
args: | ||
executable: /bin/bash |