From 5cf47ce64eff1da4086e41782bb6bfb67a001b7d Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 4 Aug 2023 11:52:07 +0200 Subject: import workspace role --- roles/workspace/defaults/main.yml | 4 ++++ roles/workspace/tasks/main.yml | 33 +++++++++++++++++++++++++++++++++ roles/workspace/tasks/project.yml | 22 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 roles/workspace/defaults/main.yml create mode 100644 roles/workspace/tasks/main.yml create mode 100644 roles/workspace/tasks/project.yml (limited to 'roles/workspace') diff --git a/roles/workspace/defaults/main.yml b/roles/workspace/defaults/main.yml new file mode 100644 index 0000000..b517f2c --- /dev/null +++ b/roles/workspace/defaults/main.yml @@ -0,0 +1,4 @@ +git_name: Egor Tensin +git_email: Egor.Tensin@gmail.com + +workspace_dir: /srv/workspace diff --git a/roles/workspace/tasks/main.yml b/roles/workspace/tasks/main.yml new file mode 100644 index 0000000..a554ac0 --- /dev/null +++ b/roles/workspace/tasks/main.yml @@ -0,0 +1,33 @@ +- name: Workspace directory + become: true + ansible.builtin.file: + path: '{{ workspace_dir }}' + state: directory + owner: '{{ ansible_user }}' + group: '{{ ansible_user }}' + mode: '0750' + +- name: Install dependencies + become: true + ansible.builtin.apt: + name: + - git + - vim + +- name: Configure git + block: + - name: Set user.name + community.general.git_config: + scope: global + name: user.name + value: '{{ git_name }}' + + - name: Set user.email + community.general.git_config: + scope: global + name: user.email + value: '{{ git_email }}' + +- name: Update projects + ansible.builtin.include_tasks: project.yml + loop: '{{ workspace_projects }}' diff --git a/roles/workspace/tasks/project.yml b/roles/workspace/tasks/project.yml new file mode 100644 index 0000000..4a81f78 --- /dev/null +++ b/roles/workspace/tasks/project.yml @@ -0,0 +1,22 @@ +- name: Set project URL + ansible.builtin.set_fact: + project_url: '{{ item.url | default(item) }}' + +- name: Set project name + ansible.builtin.set_fact: + project_name: "{{ item.name | default(project_url | urlsplit('path') | basename | regex_replace('\\.git$', '')) }}" + +- name: 'Update repository: {{ project_name }}' + ansible.builtin.git: + accept_hostkey: true + dest: '{{ workspace_dir }}/{{ project_name }}' + repo: '{{ project_url }}' + +- name: 'Rebuild containers: {{ project_name }}' + become: true + ansible.builtin.shell: + docker-compose pull && + docker-compose build --force-rm --pull -q && + docker-compose up --remove-orphans -d + args: + chdir: '{{ workspace_dir }}/{{ project_name }}' -- cgit v1.2.3