feat(ghost): add role for deployment using docker
This commit was merged in pull request #7.
	This commit is contained in:
		
							
								
								
									
										38
									
								
								roles/ghost/defaults/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								roles/ghost/defaults/main.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ghost_domain: ~
 | 
				
			||||||
 | 
					ghost_version: "5.33.6"
 | 
				
			||||||
 | 
					ghost_user: ghost
 | 
				
			||||||
 | 
					ghost_user_group: ghost
 | 
				
			||||||
 | 
					ghost_base_path: /opt/ghost
 | 
				
			||||||
 | 
					ghost_data_path: "{{ ghost_base_path }}/data"
 | 
				
			||||||
 | 
					ghost_config_path: "{{ ghost_base_path }}/config"
 | 
				
			||||||
 | 
					ghost_config_file: "{{ ghost_config_path }}/ghost.env"
 | 
				
			||||||
 | 
					ghost_database_username: ghost
 | 
				
			||||||
 | 
					ghost_database_password: ~
 | 
				
			||||||
 | 
					ghost_database_database: ghost
 | 
				
			||||||
 | 
					ghost_database_host: ~
 | 
				
			||||||
 | 
					ghost_base_config:
 | 
				
			||||||
 | 
					  url: "https://{{ ghost_domain }}"
 | 
				
			||||||
 | 
					  database__client: mysql
 | 
				
			||||||
 | 
					  database__connection__host: "{{ ghost_database_host }}"
 | 
				
			||||||
 | 
					  database__connection__user: "{{ ghost_database_username }}"
 | 
				
			||||||
 | 
					  database__connection__password: "{{ ghost_database_password }}"
 | 
				
			||||||
 | 
					  database__connection__database: "{{ ghost_database_database }}"
 | 
				
			||||||
 | 
					ghost_config: {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ghost_container_name: ghost
 | 
				
			||||||
 | 
					ghost_container_image_name: docker.io/ghost
 | 
				
			||||||
 | 
					ghost_container_image_tag: ~
 | 
				
			||||||
 | 
					ghost_container_base_volumes:
 | 
				
			||||||
 | 
					  - "{{ ghost_data_path }}:{{ ghost_container_data_directory }}:rw"
 | 
				
			||||||
 | 
					ghost_container_extra_volumes: []
 | 
				
			||||||
 | 
					ghost_container_volumes:
 | 
				
			||||||
 | 
					  "{{ ghost_container_base_volumes + ghost_container_extra_volumes }}"
 | 
				
			||||||
 | 
					ghost_container_base_labels:
 | 
				
			||||||
 | 
					  version: "{{ ghost_version }}"
 | 
				
			||||||
 | 
					ghost_container_extra_labels: {}
 | 
				
			||||||
 | 
					ghost_container_restart_policy: "unless-stopped"
 | 
				
			||||||
 | 
					ghost_container_networks: ~
 | 
				
			||||||
 | 
					ghost_container_purge_networks: ~
 | 
				
			||||||
 | 
					ghost_container_etc_hosts: ~
 | 
				
			||||||
							
								
								
									
										56
									
								
								roles/ghost/tasks/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								roles/ghost/tasks/main.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					- name: Ensure ghost group is created
 | 
				
			||||||
 | 
					  ansible.builtin.group:
 | 
				
			||||||
 | 
					    name: "{{ ghost_user_group }}"
 | 
				
			||||||
 | 
					    state: present
 | 
				
			||||||
 | 
					    system: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Ensure ghost user is created
 | 
				
			||||||
 | 
					  ansible.builtin.user:
 | 
				
			||||||
 | 
					    name: "{{ ghost_user }}"
 | 
				
			||||||
 | 
					    groups:
 | 
				
			||||||
 | 
					      - "{{ ghost_user_group }}"
 | 
				
			||||||
 | 
					    append: true
 | 
				
			||||||
 | 
					    state: present
 | 
				
			||||||
 | 
					    system: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Ensure host paths for docker volumes exist for ghost
 | 
				
			||||||
 | 
					  ansible.builtin.file:
 | 
				
			||||||
 | 
					    path: "{{ item }}"
 | 
				
			||||||
 | 
					    state: directory
 | 
				
			||||||
 | 
					    mode: "0750"
 | 
				
			||||||
 | 
					    owner: "{{ ghost_user }}"
 | 
				
			||||||
 | 
					    group: "{{ ghost_user_group }}"
 | 
				
			||||||
 | 
					  loop:
 | 
				
			||||||
 | 
					    - "{{ ghost_base_path }}"
 | 
				
			||||||
 | 
					    - "{{ ghost_data_path }}"
 | 
				
			||||||
 | 
					    - "{{ ghost_config_path }}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Ensure ghost configuration file is templated
 | 
				
			||||||
 | 
					  ansible.builtin.template:
 | 
				
			||||||
 | 
					    src: "ghost.env.j2"
 | 
				
			||||||
 | 
					    dest: "{{ ghost_config_file }}"
 | 
				
			||||||
 | 
					    owner: "{{ ghost_user }}"
 | 
				
			||||||
 | 
					    group: "{{ ghost_user_group }}"
 | 
				
			||||||
 | 
					    mode: "0644"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Ensure ghost container image is present on host
 | 
				
			||||||
 | 
					  community.docker.docker_image:
 | 
				
			||||||
 | 
					    name: "{{ ghost_container_image }}"
 | 
				
			||||||
 | 
					    state: present
 | 
				
			||||||
 | 
					    source: pull
 | 
				
			||||||
 | 
					    force_source: "{{ ghost_container_image_tag is defined }}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Ensure ghost container is running
 | 
				
			||||||
 | 
					  community.docker.docker_container:
 | 
				
			||||||
 | 
					    name: "{{ ghost_container_name }}"
 | 
				
			||||||
 | 
					    image: "{{ ghost_container_image }}"
 | 
				
			||||||
 | 
					    ports: "{{ ghost_container_ports | default(omit, true) }}"
 | 
				
			||||||
 | 
					    labels: "{{ ghost_container_labels }}"
 | 
				
			||||||
 | 
					    volumes: "{{ ghost_container_volumes }}"
 | 
				
			||||||
 | 
					    env_file: "{{ ghost_config_file }}"
 | 
				
			||||||
 | 
					    etc_hosts: "{{ ghost_container_etc_hosts | default(omit, true) }}"
 | 
				
			||||||
 | 
					    networks: "{{ ghost_container_networks | default(omit, true) }}"
 | 
				
			||||||
 | 
					    purge_networks: "{{ ghost_container_purge_networks | default(omit, true) }}"
 | 
				
			||||||
 | 
					    restart_policy: "{{ ghost_container_restart_policy }}"
 | 
				
			||||||
 | 
					    state: started
 | 
				
			||||||
							
								
								
									
										3
									
								
								roles/ghost/templates/ghost.env.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								roles/ghost/templates/ghost.env.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					{% for key, value in ghost_config_complete.items() %}
 | 
				
			||||||
 | 
					{{ key }}={{ value }}
 | 
				
			||||||
 | 
					{% endfor %}
 | 
				
			||||||
							
								
								
									
										10
									
								
								roles/ghost/vars/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								roles/ghost/vars/main.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ghost_container_image: "{{ ghost_container_image_name}}:{{ ghost_container_image_tag | default(ghost_version, true) }}"
 | 
				
			||||||
 | 
					ghost_container_labels: >-2
 | 
				
			||||||
 | 
					  {{ ghost_container_base_labels
 | 
				
			||||||
 | 
					  | combine(ghost_container_extra_labels) }}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ghost_container_data_directory: "/var/lib/ghost/content"
 | 
				
			||||||
 | 
					ghost_config_complete: >-2
 | 
				
			||||||
 | 
					  {{ ghost_base_config | combine(ghost_config, recursive=True) }}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user