From bf5873560c7335d5760a7637eca7f87c1d38e312 Mon Sep 17 00:00:00 2001 From: flifloo Date: Mon, 2 May 2022 17:37:21 +0200 Subject: [PATCH] Create playbooks --- ansistrano_tasks/after_update.yml | 17 ++++++++++++++ ansistrano_tasks/configure.yml | 16 +++++++++++++ ansistrano_tasks/dependencies.yml | 15 ++++++++++++ hosts.yml | 9 ++++++++ playbook-app.yml | 38 +++++++++++++++++++++++++++++++ playbook-example.yaml | 11 --------- playbook-server.yml | 17 ++++++++++++++ playbook.yml | 5 ++++ 8 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 ansistrano_tasks/after_update.yml create mode 100644 ansistrano_tasks/configure.yml create mode 100644 ansistrano_tasks/dependencies.yml create mode 100644 hosts.yml create mode 100644 playbook-app.yml delete mode 100644 playbook-example.yaml create mode 100644 playbook-server.yml create mode 100644 playbook.yml diff --git a/ansistrano_tasks/after_update.yml b/ansistrano_tasks/after_update.yml new file mode 100644 index 0000000..8d31d17 --- /dev/null +++ b/ansistrano_tasks/after_update.yml @@ -0,0 +1,17 @@ +--- +- name: "Unzip" + ansible.builtin.unarchive: + src: "{{ ansistrano_release_path.stdout }}/projectsend-{{ release }}.zip" + dest: "{{ ansistrano_release_path.stdout }}" + remote_src: true + +- name: "Remove archive" + file: + path: "{{ ansistrano_release_path.stdout }}/projectsend-{{ release }}.zip" + state: absent + +#- name: "Update dependencies" +# include_tasks: "dependencies.yml" + +- name: "Configure" + include_tasks: "configure.yml" diff --git a/ansistrano_tasks/configure.yml b/ansistrano_tasks/configure.yml new file mode 100644 index 0000000..196c710 --- /dev/null +++ b/ansistrano_tasks/configure.yml @@ -0,0 +1,16 @@ +--- +- name: "Copy sample" + copy: + src: "{{ ansistrano_release_path.stdout }}/includes/sys.config.sample.php" + dest: "{{ ansistrano_release_path.stdout }}/includes/sys.config.php" + remote_src: true + +- name: "Setup DB" + ansible.builtin.lineinfile: + path: "{{ ansistrano_release_path.stdout }}/includes/sys.config.php" + regexp: "{{ item.regex }}" + line: "{{ item.line }}" + loop: + - {regex: "^define\\('DB_NAME', '.*'\\);$", line: "define('DB_NAME', '{{ db_name }}');"} + - {regex: "^define\\('DB_USER', '.*'\\);$", line: "define('DB_USER', '{{ db_user }}');"} + - {regex: "^define\\('DB_PASSWORD', '.*'\\);$", line: "define('DB_PASSWORD', '{{ db_password }}');"} diff --git a/ansistrano_tasks/dependencies.yml b/ansistrano_tasks/dependencies.yml new file mode 100644 index 0000000..f5de051 --- /dev/null +++ b/ansistrano_tasks/dependencies.yml @@ -0,0 +1,15 @@ +--- +- name: "Install PHP dependencies" + community.general.composer: + command: install + working_dir: "{{ ansistrano_release_path.stdout }}" + +- name: "Install JS dependencies" + community.general.npm: + path: "{{ ansistrano_release_path.stdout }}" + +- name: "Compile SCSS" + ansible.builtin.command: + cmd: "./node_modules/gulp/bin/gulp.js" + chdir: "{{ ansistrano_release_path.stdout }}" + #Todo: creates: "" diff --git a/hosts.yml b/hosts.yml new file mode 100644 index 0000000..42a1f9a --- /dev/null +++ b/hosts.yml @@ -0,0 +1,9 @@ +all: + hosts: + ubuntu: + vars: + scope: "prod" + release: "r1335" + db_name: "projectsend_{{ scope }}" + db_user: "projectsend_{{ scope }}" + db_password: "test" diff --git a/playbook-app.yml b/playbook-app.yml new file mode 100644 index 0000000..6cf35fe --- /dev/null +++ b/playbook-app.yml @@ -0,0 +1,38 @@ +- name: "App Install" + hosts: "all" + become: true + become_user: www-data + + vars: + proxy: "http://proxy.univ-lyon1.fr:3128/" + ansistrano_deploy_from: "{{ playbook_dir }}/" # Where my local project is (relative or absolute path) + ansistrano_deploy_to: "/var/www/{{ scope }}/projectsend" # Base path to deploy to. + ansistrano_keep_releases: 2 # Releases to keep after a new deployment. See "Pruning old releases". + + ansistrano_shared_paths: + - upload + + # Shared paths and basedir shared files creation. + # By default the shared paths directories and base directories for shared files are created automatically if not exists. But in some scenarios those paths could be symlinks to another directories in the filesystem, and the deployment process would fails. With these variables you can disable the involved tasks. If you have two or three shared paths, and don't need creation only for some of them, you always could disable the automatic creation and add a custom task in a hook. + ansistrano_ensure_shared_paths_exist: yes + ansistrano_ensure_basedirs_shared_files_exist: yes + + # Deployment strategy - method used to deliver code. Options are copy, download, git, rsync, rsync_direct, svn, or s3. + ansistrano_deploy_via: download + # Copy, download and s3 have an optional step to unarchive the downloaded file which can be used by adding _unarchive. + # The rsync_direct strategy omits a file copy on the target offering a slight speed increase if you are deploying to shared hosts, are experiancing bad file-performance, or serve static assets from the same host you deploy your app to and rsync many files. + # You can check all the options inside tasks/update-code folder! + + ansistrano_allow_anonymous_stats: no + + ansistrano_get_url: "https://github.com/projectsend/projectsend/releases/download/{{ release }}/projectsend-{{ release }}.zip" + + # Hooks: custom tasks if you need them + ansistrano_after_update_code_tasks_file: "{{ playbook_dir }}/ansistrano_tasks/after_update.yml" + environment: + http_proxy: "{{ proxy }}" + https_proxy: "{{ proxy }}" + APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE: DontWarn + + roles: + - ansistrano.deploy diff --git a/playbook-example.yaml b/playbook-example.yaml deleted file mode 100644 index a707e97..0000000 --- a/playbook-example.yaml +++ /dev/null @@ -1,11 +0,0 @@ -- name: Server Install - hosts: "localhost" - - ### Pour eviter les problème de timeout sur le server lors d'installation de key - ### Config à ajouter en début de playbook - vars: - proxy: "http://proxy.univ-lyon1.fr:3128/" - environment: - http_proxy: "{{proxy}}" - https_proxy: "{{proxy}}" - APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE: DontWarn diff --git a/playbook-server.yml b/playbook-server.yml new file mode 100644 index 0000000..3a76097 --- /dev/null +++ b/playbook-server.yml @@ -0,0 +1,17 @@ +- name: "Server Install" + hosts: "all" + become: true + + vars: + proxy: "http://proxy.univ-lyon1.fr:3128/" + environment: + http_proxy: "{{ proxy }}" + https_proxy: "{{ proxy }}" + APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE: DontWarn + + roles: + - apt + - mariadb + - php + - nodejs + - nginx diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..81ab13f --- /dev/null +++ b/playbook.yml @@ -0,0 +1,5 @@ +- name: "Setup server" + import_playbook: playbook-server.yml + +- name: "Setup app" + import_playbook: playbook-app.yml