diff --git a/defaults/main.yml b/defaults/main.yml index f17db7c..3ddd13e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,5 +2,5 @@ # defaults file for roles/compose_project service: dummy compose_dir: /home/core/compose -state: present # or absent -restart: smart # or always or never +state: present # or running, build, absent +execute: smart # or always or never diff --git a/tasks/build.yml b/tasks/build.yml new file mode 100644 index 0000000..e8e50a2 --- /dev/null +++ b/tasks/build.yml @@ -0,0 +1,13 @@ +--- + +- include_tasks: present.yml + +- name: Build Service + community.docker.docker_compose: + project_src: "{{ service_dir | mandatory }}" + state: present + restarted: true + recreate: smart + build: true + remove_orphans: true + when: (compose_files.changed and execute == "smart") or execute == "always" diff --git a/tasks/main.yml b/tasks/main.yml index cceaa6a..85b1532 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -9,7 +9,13 @@ msg: "Working on {{ service }}{% if service_name is defined %}-{{ service_name }}{% endif %}" verbosity: 0 -- include_tasks: create.yml +- include_tasks: running.yml + when: state == "running" + +- include_tasks: build.yml + when: state == "build" + +- include_tasks: present.yml when: state == "present" - include_tasks: remove.yml diff --git a/tasks/create.yml b/tasks/present.yml similarity index 83% rename from tasks/create.yml rename to tasks/present.yml index 677cce7..488d88e 100644 --- a/tasks/create.yml +++ b/tasks/present.yml @@ -56,13 +56,3 @@ path: "{{ temp_file.path }}" state: absent changed_when: false - -- name: Restart Service - community.docker.docker_compose: - project_src: "{{ service_dir | mandatory }}" - state: present - restarted: true - recreate: smart - build: true - remove_orphans: true - when: (compose_files.changed and restart == "smart") or restart == "always" diff --git a/tasks/running.yml b/tasks/running.yml new file mode 100644 index 0000000..7057e3f --- /dev/null +++ b/tasks/running.yml @@ -0,0 +1,14 @@ +--- + +- include_tasks: present.yml + +- name: Restart Service + community.docker.docker_compose: + project_src: "{{ service_dir | mandatory }}" + pull: true + state: present + restarted: true + recreate: smart + build: false + remove_orphans: true + when: (compose_files.changed and execute == "smart") or execute == "always"