Actualiser prestashop.yml
This commit is contained in:
parent
2d6f6080d7
commit
c35a91af5d
|
|
@ -1,35 +1,42 @@
|
||||||
---
|
---
|
||||||
- name: Create a test Portainer stack via SSH tunnel
|
- name: Deploy Prestashop stack via Portainer through SSH tunnel
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
connection: local
|
connection: local
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
# Bastion SSH
|
|
||||||
bastion_host: bdc.cci17.fr
|
bastion_host: bdc.cci17.fr
|
||||||
bastion_port: 17100
|
bastion_port: 17100
|
||||||
bastion_user: ansible
|
bastion_user: ansible
|
||||||
|
|
||||||
# Portainer (via tunnel local)
|
|
||||||
portainer_url: https://127.0.0.1:9443
|
portainer_url: https://127.0.0.1:9443
|
||||||
|
portainer_internal_ip: 10.30.0.151
|
||||||
|
portainer_internal_port: 9443
|
||||||
|
|
||||||
# Stack test
|
|
||||||
stack_name: test-stack-semaphore
|
|
||||||
stack_type: 2 # 2 = Docker standalone, 1 = Swarm
|
|
||||||
|
|
||||||
# Tunnel SSH
|
|
||||||
ssh_control_socket: /tmp/ssh-tunnel-portainer-9443.sock
|
ssh_control_socket: /tmp/ssh-tunnel-portainer-9443.sock
|
||||||
|
|
||||||
# Compose minimal de test
|
stack_type: 2 # 2 standalone, 1 swarm
|
||||||
stack_compose: |
|
stack_name_prefix: ps-
|
||||||
services:
|
|
||||||
web:
|
template_src: templates/prestashop-stack.yml.j2
|
||||||
image: nginx:alpine
|
rendered_compose_path: /tmp/prestashop-stack-rendered.yml
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- block:
|
- name: Ensure SITE_NAME provided
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- SITE_NAME is defined
|
||||||
|
- SITE_NAME | length > 0
|
||||||
|
fail_msg: "SITE_NAME doit etre fourni dans Semaphore (Options avancees)."
|
||||||
|
|
||||||
|
- name: Ensure PORTAINER_API_KEY provided
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- PORTAINER_API_KEY is defined
|
||||||
|
- PORTAINER_API_KEY | length > 10
|
||||||
|
fail_msg: "PORTAINER_API_KEY doit etre fourni via Groupe de variables Semaphore."
|
||||||
|
|
||||||
|
- block:
|
||||||
- name: Check local port 9443 is free
|
- name: Check local port 9443 is free
|
||||||
shell: ss -lnt | grep -q ':9443 '
|
shell: ss -lnt | grep -q ':9443 '
|
||||||
register: port_in_use
|
register: port_in_use
|
||||||
|
|
@ -44,7 +51,7 @@
|
||||||
-o UserKnownHostsFile=/dev/null
|
-o UserKnownHostsFile=/dev/null
|
||||||
-M -S {{ ssh_control_socket }}
|
-M -S {{ ssh_control_socket }}
|
||||||
-f -N
|
-f -N
|
||||||
-L 127.0.0.1:9443:10.30.0.151:9443
|
-L 127.0.0.1:9443:{{ portainer_internal_ip }}:{{ portainer_internal_port }}
|
||||||
{{ bastion_user }}@{{ bastion_host }}
|
{{ bastion_user }}@{{ bastion_host }}
|
||||||
changed_when: true
|
changed_when: true
|
||||||
|
|
||||||
|
|
@ -54,14 +61,15 @@
|
||||||
port: 9443
|
port: 9443
|
||||||
timeout: 20
|
timeout: 20
|
||||||
|
|
||||||
- name: Check Portainer API
|
- name: Render docker-compose from template (Jinja2)
|
||||||
uri:
|
template:
|
||||||
url: "{{ portainer_url }}/api/status"
|
src: "{{ template_src }}"
|
||||||
method: GET
|
dest: "{{ rendered_compose_path }}"
|
||||||
validate_certs: false
|
|
||||||
headers:
|
- name: Read rendered compose content
|
||||||
X-API-Key: "{{ lookup('env','PORTAINER_API_KEY') }}"
|
slurp:
|
||||||
status_code: [200]
|
src: "{{ rendered_compose_path }}"
|
||||||
|
register: compose_b64
|
||||||
|
|
||||||
- name: Get Portainer endpoints
|
- name: Get Portainer endpoints
|
||||||
uri:
|
uri:
|
||||||
|
|
@ -69,25 +77,26 @@
|
||||||
method: GET
|
method: GET
|
||||||
validate_certs: false
|
validate_certs: false
|
||||||
headers:
|
headers:
|
||||||
X-API-Key: "{{ lookup('env','PORTAINER_API_KEY') }}"
|
X-API-Key: "{{ PORTAINER_API_KEY }}"
|
||||||
|
status_code: [200]
|
||||||
register: endpoints_resp
|
register: endpoints_resp
|
||||||
|
|
||||||
- name: Select first endpoint
|
- name: Select first endpoint
|
||||||
set_fact:
|
set_fact:
|
||||||
endpoint_id: "{{ endpoints_resp.json[0].Id }}"
|
endpoint_id: "{{ endpoints_resp.json[0].Id }}"
|
||||||
|
|
||||||
- name: Create test stack
|
- name: Create stack in Portainer
|
||||||
uri:
|
uri:
|
||||||
url: "{{ portainer_url }}/api/stacks?type={{ stack_type }}&method=string&endpointId={{ endpoint_id }}"
|
url: "{{ portainer_url }}/api/stacks?type={{ stack_type }}&method=string&endpointId={{ endpoint_id }}"
|
||||||
method: POST
|
method: POST
|
||||||
validate_certs: false
|
validate_certs: false
|
||||||
headers:
|
headers:
|
||||||
X-API-Key: "{{ lookup('env','PORTAINER_API_KEY') }}"
|
X-API-Key: "{{ PORTAINER_API_KEY }}"
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
body_format: json
|
body_format: json
|
||||||
body:
|
body:
|
||||||
Name: "{{ stack_name }}"
|
Name: "{{ stack_name_prefix }}{{ SITE_NAME }}"
|
||||||
StackFileContent: "{{ stack_compose }}"
|
StackFileContent: "{{ compose_b64.content | b64decode }}"
|
||||||
Env: []
|
Env: []
|
||||||
status_code: [200, 201, 409]
|
status_code: [200, 201, 409]
|
||||||
register: create_stack
|
register: create_stack
|
||||||
|
|
@ -95,8 +104,8 @@
|
||||||
- name: Result
|
- name: Result
|
||||||
debug:
|
debug:
|
||||||
msg: >
|
msg: >
|
||||||
Stack creation HTTP status {{ create_stack.status }}
|
Stack '{{ stack_name_prefix }}{{ SITE_NAME }}' creation status {{ create_stack.status }}
|
||||||
(409 means the stack already exists)
|
(409 means it already exists)
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Close SSH tunnel
|
- name: Close SSH tunnel
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue