diff --git a/roles/deploy-web/tasks/deploy.yml b/roles/deploy-web/tasks/deploy.yml index 36922af..cee6220 100644 --- a/roles/deploy-web/tasks/deploy.yml +++ b/roles/deploy-web/tasks/deploy.yml @@ -1,7 +1,6 @@ ---- # tasks file for deploy-web -- name: git archive {{ item }} +- name: "git archive {{ item }}" local_action: module: git repo: "https://{{ git_username | urlencode }}:{{ git_password | urlencode }}@git.valczeryba.ovh/v4l3n71n/{{ item }}.git" @@ -9,18 +8,20 @@ archive: "/tmp/{{ item }}.tar.gz" force: yes update: yes - with_items: "{{ project_name }}" + with_items: + - "{{ project_name }}" when: "project_name is defined" -- name: Create directory {{ item }} +- name: "Create directory {{ item }}" file: path: "/var/www/{{ item }}" state: directory owner: www-data group: www-data mode: '500' - with_items: "{{ project_name }}" + with_items: + - "{{ project_name }}" when: "project_name is defined" vars: ansible_become: yes @@ -28,14 +29,15 @@ ansible_become_password: "{{ sudo_password }}" -- name: Extract repo {{ item }} +- name: "Extract repo {{ item }}" unarchive: src: "/tmp/{{ item }}.tar.gz" dest: "/var/www/{{ item }}" owner: www-data group: www-data mode: '500' - with_items: "{{ project_name }}" + with_items: + - "{{ project_name }}" when: "project_name is defined" vars: ansible_become: yes diff --git a/roles/deploy-web/tasks/destroy.yml b/roles/deploy-web/tasks/destroy.yml new file mode 100644 index 0000000..1479bfa --- /dev/null +++ b/roles/deploy-web/tasks/destroy.yml @@ -0,0 +1,21 @@ +- name: "Remove all directories" + file: + path: "/var/www/{{ item }}" + state: absent + with_items: + - "{{ project_name }}" + when: "project_name is defined and project is not defined" + vars: + ansible_become: yes + ansible_become_method: sudo + ansible_become_password: "{{ sudo_password }}" + +- name: "Remove single directory" + file: + path: "/var/www/{{ project }}" + state: absent + when: "project is defined" + vars: + ansible_become: yes + ansible_become_method: sudo + ansible_become_password: "{{ sudo_password }}" \ No newline at end of file diff --git a/roles/deploy-web/tasks/main.yml b/roles/deploy-web/tasks/main.yml index d90f8d8..22d0e52 100644 --- a/roles/deploy-web/tasks/main.yml +++ b/roles/deploy-web/tasks/main.yml @@ -1,3 +1,8 @@ -- name: Deploy project_name +- name: Deploy project web import_tasks: deploy.yml - tags: ["deploy"] \ No newline at end of file + tags: ["deploy"] + + +- name: Destrpy project web + import_tasks: destroy.yml + tags: ["destroy"] \ No newline at end of file