aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roles/my_workspace/tasks
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-08-20 18:38:17 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-08-20 21:43:59 +0200
commit97b930c6edc7973497f469ae859fa2258cbea4d6 (patch)
tree822382f2275cc25cb7d6d280cc37a17d0c7e1214 /roles/my_workspace/tasks
parentv0.0.16 (diff)
downloadinfra-ansible-97b930c6edc7973497f469ae859fa2258cbea4d6.tar.gz
infra-ansible-97b930c6edc7973497f469ae859fa2258cbea4d6.zip
use variables instead facts mostly everywhere
set_fact is stupid; they persist through multiple role executions; for example, you cannot do this: set_fact: foo: '{{ foo | default("bar") }}' If somebody calls the role and defines foo, it will always be set to that value forever, even for subsequent role calls.
Diffstat (limited to '')
-rw-r--r--roles/my_workspace/tasks/main.yml2
-rw-r--r--roles/my_workspace/tasks/project.yml78
2 files changed, 38 insertions, 42 deletions
diff --git a/roles/my_workspace/tasks/main.yml b/roles/my_workspace/tasks/main.yml
index 0acec47..6bbb308 100644
--- a/roles/my_workspace/tasks/main.yml
+++ b/roles/my_workspace/tasks/main.yml
@@ -31,3 +31,5 @@
- name: Update projects
ansible.builtin.include_tasks: project.yml
loop: '{{ workspace_projects }}'
+ loop_control:
+ loop_var: project
diff --git a/roles/my_workspace/tasks/project.yml b/roles/my_workspace/tasks/project.yml
index 813de46..d6bf857 100644
--- a/roles/my_workspace/tasks/project.yml
+++ b/roles/my_workspace/tasks/project.yml
@@ -1,47 +1,41 @@
-- 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: Set project directory
- ansible.builtin.set_fact:
+- name: Set up project
+ vars:
+ project_url: '{{ project.url | default(project) }}'
+ project_name: "{{ project.name | default(project_url | urlsplit('path') | basename | regex_replace('\\.git$', '')) }}"
project_dir: '{{ workspace_dir }}/{{ project_name }}'
+ block:
+ - name: 'Update repository: {{ project_name }}'
+ ansible.builtin.git:
+ accept_hostkey: true
+ dest: '{{ project_dir }}'
+ repo: '{{ project_url }}'
-- name: 'Update repository: {{ project_name }}'
- ansible.builtin.git:
- accept_hostkey: true
- dest: '{{ project_dir }}'
- repo: '{{ project_url }}'
-
-- name: Check for Makefile
- ansible.builtin.file:
- path: '{{ project_dir }}/Makefile'
- state: file
- register: makefile_check
- ignore_errors: true
+ - name: Check for Makefile
+ ansible.builtin.file:
+ path: '{{ project_dir }}/Makefile'
+ state: file
+ register: makefile_check
+ ignore_errors: true
-- name: Check for docker-compose.yml
- ansible.builtin.file:
- path: '{{ project_dir }}/docker-compose.yml'
- state: file
- register: docker_compose_check
- ignore_errors: true
+ - name: Check for docker-compose.yml
+ ansible.builtin.file:
+ path: '{{ project_dir }}/docker-compose.yml'
+ state: file
+ register: docker_compose_check
+ ignore_errors: true
-- name: Run make
- become: true
- community.general.make:
- chdir: '{{ project_dir }}'
- when: makefile_check is succeeded
+ - name: Run make
+ become: true
+ community.general.make:
+ chdir: '{{ project_dir }}'
+ when: makefile_check is succeeded
-- name: Run docker-compose
- become: true
- community.docker.docker_compose:
- build: true
- debug: true
- project_src: '{{ project_dir }}'
- pull: true
- remove_orphans: true
- when: makefile_check is not succeeded and docker_compose_check is succeeded
+ - name: Run docker-compose
+ become: true
+ community.docker.docker_compose:
+ build: true
+ debug: true
+ project_src: '{{ project_dir }}'
+ pull: true
+ remove_orphans: true
+ when: makefile_check is not succeeded and docker_compose_check is succeeded