From ae0655da7c39010324a776f719544bf5e9034eb6 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 28 Dec 2022 18:08:18 +0100 Subject: [PATCH] add deploy single project --- roles/deploy-web/tasks/deploy.yml | 82 ++++++++++++++++++++++++++---- roles/deploy-web/tasks/destroy.yml | 32 +++++++++--- 2 files changed, 98 insertions(+), 16 deletions(-) diff --git a/roles/deploy-web/tasks/deploy.yml b/roles/deploy-web/tasks/deploy.yml index 48ce25d..0adb461 100644 --- a/roles/deploy-web/tasks/deploy.yml +++ b/roles/deploy-web/tasks/deploy.yml @@ -1,6 +1,6 @@ # tasks file for deploy-web -- name: "git archive {{ item }}" +- name: "all git archive" local_action: module: git repo: "https://{{ git_username | urlencode }}:{{ git_password | urlencode }}@git.valczeryba.ovh/v4l3n71n/{{ item.git_name }}.git" @@ -8,19 +8,19 @@ archive: "/tmp/{{ item.git_name }}.tar.gz" force: yes update: yes - when: "item.git_name is defined" + when: "item.git_name is defined and project_name is not defined and conf_name is not defined" with_items: - "{{ project }}" -- name: "Create directory " +- name: "all create directory " file: path: "/var/www/{{ item.git_name }}" state: directory owner: www-data group: www-data mode: '500' - when: "item.git_name is defined" + when: "item.git_name is defined and project_name is not defined and conf_name is not defined" with_items: - "{{ project }}" vars: @@ -29,14 +29,14 @@ ansible_become_password: "{{ sudo_password }}" -- name: "Extract repo " +- name: "all extract repo " unarchive: src: "/tmp/{{ item.git_name }}.tar.gz" dest: "/var/www/{{ item.git_name }}" owner: www-data group: www-data mode: '500' - when: "item.git_name is defined" + when: "item.git_name is defined and project_name is not defined and conf_name is not defined" with_items: - "{{ project }}" vars: @@ -44,11 +44,50 @@ ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" -- name: "Copy configure nginx" + +- name: "single git archive" + local_action: + module: git + repo: "https://{{ git_username | urlencode }}:{{ git_password | urlencode }}@git.valczeryba.ovh/v4l3n71n/{{ project_name }}.git" + dest: "/home/valentin/src/" + archive: "/tmp/{{ project_name }}.tar.gz" + force: yes + update: yes + when: "project_name is defined" + + +- name: "single create directory " + file: + path: "/var/www/{{ project_name }}" + state: directory + owner: www-data + group: www-data + mode: '500' + when: "project_name is defined" + vars: + ansible_become: yes + ansible_become_method: sudo + ansible_become_password: "{{ sudo_password }}" + + +- name: "single extract repo " + unarchive: + src: "/tmp/{{ project_name }}.tar.gz" + dest: "/var/www/{{ project_name }}" + owner: www-data + group: www-data + mode: '500' + when: "project_name is defined" + vars: + ansible_become: yes + ansible_become_method: sudo + ansible_become_password: "{{ sudo_password }}" + +- name: "all copy configure nginx" copy: src: "{{ item.conf_name }}" dest: "/etc/nginx/sites-available" - when: "item.conf_name is defined" + when: "item.conf_name is defined and project_name is not defined and conf_name is not defined" with_items: - "{{ project }}" vars: @@ -57,12 +96,12 @@ ansible_become_password: "{{ sudo_password }}" -- name: "Create symlink" +- name: "all create symlink" file: src: "/etc/nginx/sites-available/{{ item.conf_name }}" dest: "/etc/nginx/sites-enabled/{{ item.conf_name }}" state: link - when: "item.conf_name is defined" + when: "item.conf_name is defined and project_name is not defined and conf_name is not defined" with_items: - "{{ project }}" vars: @@ -70,6 +109,29 @@ ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" + +- name: "single copy configure nginx" + copy: + src: "{{ conf_name }}" + dest: "/etc/nginx/sites-available" + when: "conf_name is defined" + vars: + ansible_become: yes + ansible_become_method: sudo + ansible_become_password: "{{ sudo_password }}" + + +- name: "single create symlink" + file: + src: "/etc/nginx/sites-available/{{ conf_name }}" + dest: "/etc/nginx/sites-enabled/{{ conf_name }}" + state: link + when: "conf_name is defined" + vars: + ansible_become: yes + ansible_become_method: sudo + ansible_become_password: "{{ sudo_password }}" + - name: restart nginx service: name: nginx diff --git a/roles/deploy-web/tasks/destroy.yml b/roles/deploy-web/tasks/destroy.yml index f5334ed..b8b6a3a 100644 --- a/roles/deploy-web/tasks/destroy.yml +++ b/roles/deploy-web/tasks/destroy.yml @@ -2,7 +2,7 @@ file: path: "/var/www/{{ item.git_name }}" state: absent - when: "item.git_name is defined and project_name is not defined" + when: "item.git_name is defined and project_name is not defined and conf_name is not defined" with_items: - "{{ project }}" vars: @@ -20,11 +20,11 @@ ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" -- name: "Delete symlink" +- name: "Delete all symlink" file: path: "/etc/nginx/sites-enabled/{{ item.conf_name }}" state: absent - when: "item.conf_name is defined" + when: "item.conf_name is defined and project_name is not defined and conf_name is not defined" with_items: - "{{ project }}" vars: @@ -32,11 +32,11 @@ ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" -- name: "remove configure nginx" +- name: "remove all configure nginx" file: path: "/etc/nginx/sites-available/{{ item.conf_name }}" state: absent - when: "item.conf_name is defined" + when: "item.conf_name is defined and project_name is not defined and conf_name is not defined" with_items: - "{{ project }}" vars: @@ -46,6 +46,26 @@ +- name: "Delete single symlink" + file: + path: "/etc/nginx/sites-enabled/{{ conf_name }}" + state: absent + when: "conf_name is defined" + vars: + ansible_become: yes + ansible_become_method: sudo + ansible_become_password: "{{ sudo_password }}" + +- name: "remove single configure nginx" + file: + path: "/etc/nginx/sites-available/{{ conf_name }}" + state: absent + when: "conf_name is defined" + vars: + ansible_become: yes + ansible_become_method: sudo + ansible_become_password: "{{ sudo_password }}" + - name: restart nginx service: @@ -54,4 +74,4 @@ vars: ansible_become: yes ansible_become_method: sudo - ansible_become_password: "{{ sudo_password }}" \ No newline at end of file + ansible_become_password: "{{ sudo_password }}"