From f7dd5848f817bb42cb06eadc5444ec390aa813ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Thu, 22 Feb 2018 11:53:19 +0100 Subject: Migrating single tasks file to a galaxy role --- tasks/addon.yml | 9 +++++++++ tasks/deploy.yml | 30 ++++++++++++++++++++++++++++++ tasks/environment.yml | 11 +++++++++++ tasks/login.yml | 15 +++++++++++++++ tasks/main.yml | 32 ++++++++++++++++++++++++++++++++ tasks/setup.yml | 25 +++++++++++++++++++++++++ 6 files changed, 122 insertions(+) create mode 100644 tasks/addon.yml create mode 100644 tasks/deploy.yml create mode 100644 tasks/environment.yml create mode 100644 tasks/login.yml create mode 100644 tasks/main.yml create mode 100644 tasks/setup.yml (limited to 'tasks') diff --git a/tasks/addon.yml b/tasks/addon.yml new file mode 100644 index 0000000..cde7a1a --- /dev/null +++ b/tasks/addon.yml @@ -0,0 +1,9 @@ +- name: Gather addon information for {{ addon.name }} + shell: "clever env | grep {{ addon.env_prefix }} | sed -e 's/{{ addon.env_prefix }}_//' -e 's/=/: \"/' -e 's/$/\"/' > .clever-cloud/{{ addon.name }}_env.yml" + environment: + CONFIGURATION_FILE: "{{ clever_login_file }}" + +- name: Include addon var for {{ addon.name }} + include_vars: + file: "{{ addon.name }}_env.yml" + name: "{{ addon.name }}" diff --git a/tasks/deploy.yml b/tasks/deploy.yml new file mode 100644 index 0000000..8b98d8c --- /dev/null +++ b/tasks/deploy.yml @@ -0,0 +1,30 @@ +- name: Configure Drain + when: syslog_server is defined + command: clever-set-drain.sh + environment: + SYSLOG_UDP_SERVER: "{{ syslog_server }}" + CONFIGURATION_FILE: "{{ clever_login_file }}" + +- name: Configure Domain + when: domain is defined + command: clever-set-domain.sh + environment: + DOMAIN: "{{ domain }}" + CONFIGURATION_FILE: "{{ clever_login_file }}" + +- name: Push Environment + shell: "clever env import < {{ clever_app_confdir }}/env" + environment: + CONFIGURATION_FILE: "{{ clever_login_file }}" + +#TODO: Improve ssh-key validation +- name: Accept Clever-Cloud servers + shell: "ssh-keyscan -H push-par-clevercloud-customers.services.clever-cloud.com >> ~/.ssh/known_hosts" + +- name: Push to Clever-Cloud to trigger deployment + command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master" + +- name: Wait until deployment completion + command: clever-wait-deploy.sh + environment: + CONFIGURATION_FILE: "{{ clever_login_file }}" diff --git a/tasks/environment.yml b/tasks/environment.yml new file mode 100644 index 0000000..3d1ddbf --- /dev/null +++ b/tasks/environment.yml @@ -0,0 +1,11 @@ +- name: Create environment file + template: + src: env.j2 + dest: "{{ clever_app_confdir }}/env" + no_log: true + +- name: Create add_ons variable file + include_tasks: addon.yml + vars: + addon: "{{ item }}" + with_items: "{{ clever_addons }}" diff --git a/tasks/login.yml b/tasks/login.yml new file mode 100644 index 0000000..0eb310f --- /dev/null +++ b/tasks/login.yml @@ -0,0 +1,15 @@ +- name: Create .clever-cloud directory + file: + path: "{{ clever_app_confdir }}" + state: directory + +- name: Fill the login file + template: + src: cleverlogin.j2 + dest: "{{ clever_login_file }}" + no_log: true + +- name: Link app + shell: clever link {{ clever_app }} + environment: + CONFIGURATION_FILE: "{{ clever_login_file }}" diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..539e591 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,32 @@ +--- +# tasks file for clever +- name: Setup environment for clever + include_tasks: setup.yml + tags: + - clever + - clever-setup + +- name: Login to clever + include_tasks: login.yml + tags: + - clever + - clever-login + +- name: Manage environment + include_tasks: environment.yml + tags: + - clever + - clever-env + +- name: Include specific role + include_role: "{{ clever_app_role }}" + when: clever_app_role + tags: + - clever + - clever-specific-role + +- name: Deploy app + include_tasks: deploy.yml + tags: + - clever + - clever-deploy diff --git a/tasks/setup.yml b/tasks/setup.yml new file mode 100644 index 0000000..49e91ca --- /dev/null +++ b/tasks/setup.yml @@ -0,0 +1,25 @@ +- name: Check if clever command is available in path and version + command: clever --version + register: clever_returned_version + ignore_error: true + +- name: Ensure user path exists + file: + path: "{{ ansible_env.HOME }}/{{ clever_user_path }}" + state: directory + +- name: Download and install clever cli tools if necessary + unarchive: + remote_src: yes + src: https://clever-tools.cellar.services.clever-cloud.com/releases/{{ clever_cli_version }}/clever-tools-{{ clever_cli_version }}_linux.tar.gz + dest: "{{ ansible_env.HOME }}/{{ clever_user_path }}" + when: clever_returned_version|failed or clever_returned_version.stdout != clever_cli_version + +- name: Install helper scripts + copy: + src: "{{ item }}" + dest: "{{ ansible_env.HOME }}/{{ clever_user_path }}/{{ item }}" + with_items: + - clever-set-domain.sh + - clever-set-drain.sh + - clever-wait-deploy.sh -- cgit v1.2.3 From 8692bc2704f2a38890c93577e8f6743e611d5308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Thu, 22 Feb 2018 14:01:02 +0100 Subject: add travis file --- tasks/addon.yml | 4 ++-- tasks/environment.yml | 2 +- tasks/main.yml | 6 +++--- tasks/setup.yml | 5 ++++- 4 files changed, 10 insertions(+), 7 deletions(-) (limited to 'tasks') diff --git a/tasks/addon.yml b/tasks/addon.yml index cde7a1a..f6a4d14 100644 --- a/tasks/addon.yml +++ b/tasks/addon.yml @@ -1,9 +1,9 @@ - name: Gather addon information for {{ addon.name }} - shell: "clever env | grep {{ addon.env_prefix }} | sed -e 's/{{ addon.env_prefix }}_//' -e 's/=/: \"/' -e 's/$/\"/' > .clever-cloud/{{ addon.name }}_env.yml" + shell: "clever env | grep {{ addon.env_prefix }} | sed -e 's/{{ addon.env_prefix }}_//' -e 's/=/: \"/' -e 's/$/\"/' > {{ clever_app_confdir }}/{{ addon.name }}_env.yml" environment: CONFIGURATION_FILE: "{{ clever_login_file }}" - name: Include addon var for {{ addon.name }} include_vars: - file: "{{ addon.name }}_env.yml" + file: "{{ clever_app_confdir }}/{{ addon.name }}_env.yml" name: "{{ addon.name }}" diff --git a/tasks/environment.yml b/tasks/environment.yml index 3d1ddbf..1508ad4 100644 --- a/tasks/environment.yml +++ b/tasks/environment.yml @@ -4,7 +4,7 @@ dest: "{{ clever_app_confdir }}/env" no_log: true -- name: Create add_ons variable file +- name: Create addons variable file include_tasks: addon.yml vars: addon: "{{ item }}" diff --git a/tasks/main.yml b/tasks/main.yml index 539e591..fa23f6c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -18,9 +18,9 @@ - clever - clever-env -- name: Include specific role - include_role: "{{ clever_app_role }}" - when: clever_app_role +- name: Include specific tasks + include_tasks: "{{ clever_app_tasks }}" + when: clever_app_tasks is defined tags: - clever - clever-specific-role diff --git a/tasks/setup.yml b/tasks/setup.yml index 49e91ca..ac9fdcb 100644 --- a/tasks/setup.yml +++ b/tasks/setup.yml @@ -1,7 +1,7 @@ - name: Check if clever command is available in path and version command: clever --version register: clever_returned_version - ignore_error: true + ignore_errors: true - name: Ensure user path exists file: @@ -11,6 +11,8 @@ - name: Download and install clever cli tools if necessary unarchive: remote_src: yes + extra_opts: + - "--strip-components=1" src: https://clever-tools.cellar.services.clever-cloud.com/releases/{{ clever_cli_version }}/clever-tools-{{ clever_cli_version }}_linux.tar.gz dest: "{{ ansible_env.HOME }}/{{ clever_user_path }}" when: clever_returned_version|failed or clever_returned_version.stdout != clever_cli_version @@ -19,6 +21,7 @@ copy: src: "{{ item }}" dest: "{{ ansible_env.HOME }}/{{ clever_user_path }}/{{ item }}" + mode: 0755 with_items: - clever-set-domain.sh - clever-set-drain.sh -- cgit v1.2.3