Ansible support on Amazon Linux (#10466)

- Improve the ansible script to support Amazon Linux
- Remove the port validation on the preflight template
- Display message to show the host IP for user to access the app
This commit is contained in:
geekup-legodevops 2022-02-09 16:10:45 +07:00 committed by GitHub
parent 2d8e7fee0d
commit 7a950004db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 230 additions and 134 deletions

View File

@ -92,7 +92,7 @@ After complete the above step. Now the only remain step we need to do is run the
You can run the ansible playbook with the following command
```
$ ansible-playbook -i inventory main.yml --extra-var "@appsmith-vars.yml"
$ ansible-playbook -i inventory appsmith-playbook.yml --extra-var "@appsmith-vars.yml"
```
The command above will use the host information from the `inventory` file & feed your configuration vars from `appsmith-vars.yml` before running the playbook

View File

@ -23,3 +23,5 @@ docker_apt_gpg_key: https://download.docker.com/linux/{{ ansible_distribution |
# A list of users who will be added to the docker group.
docker_users: []
template_file_name: 'docker-compose.yml'

View File

@ -0,0 +1,6 @@
---
- name: Successful installation message
debug:
msg: "Successful installation. Please open http://{{ ansible_host }}/ to view your instance"
listen: "Start Appsmith with docker-compose"

View File

@ -0,0 +1,81 @@
---
- name: Make sure docker from distro is not installed
yum:
name: "{{ item }}"
state: absent
with_items:
- docker
- docker-common
- container-selinux
- docker-selinux
- docker-engine
- name: Update all packages
yum:
name: '*'
state: latest
update_only: yes
become: true
- name: Install yum-utils
yum:
name: "{{ item }}"
state: present
update_cache: yes
with_items:
- python-pip
- yum-utils
- device-mapper-persistent-data
- lvm2
- amazon-linux-extras
become: true
- name: Add extras repository
shell: yum-config-manager --enable extras
become: true
- name: Enable Some packages from amazon-linux-extras packages
shell: "amazon-linux-extras enable python3.8 ansible2 docker"
become: true
- name: Clean yum metadata cache
command: yum clean metadata
args:
warn: false
- name: Ensure a list of yum packages are installed
yum:
name: "{{ packages }}"
state: latest
update_cache: yes
vars:
packages:
- python3.8
- ansible
- docker
become: true
- name: Upgrade pip3
shell: "python3.8 -m pip install pip --upgrade"
become: true
- name: Install Docker-compose
get_url:
url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64
dest: '{{ docker_compose_path }}'
mode: 0755
become: true
- name: Ensure handlers are notified now to avoid firewall conflicts.
meta: flush_handlers
- name: Ensure docker users are added to the docker group.
user:
name: "{{ ansible_user }}"
groups: docker
append: true
become: true
- name: reset ssh connection to allow user changes to affect 'current login user'
meta: reset_connection

View File

@ -0,0 +1,78 @@
---
- name: Upgrade all packages to the latest version
apt:
name: '*'
state: latest
become: true
- name: Install required system packages
apt:
update_cache: yes
name:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- python3-pip
- virtualenv
- python3-setuptools
- gnupg2
state: latest
become: true
tags:
- always
- name: Ensure old versions of Docker are not installed
package:
name:
- docker
- docker-engine
state: absent
- name: Extra packages for Ubuntu
apt:
name: linux-image-extra-virtual
state: latest
become: true
when: ansible_distribution == "Ubuntu"
- name: Add key id
apt_key:
url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg"
state: present
become: true
- name: Add docker repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release | lower }} stable"
filename: docker
state: present
become: true
- name: Install docker
apt:
name: docker-ce
update_cache: yes
state: present
become: true
- name: Install Docker-compose
get_url:
url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64
dest: '{{ docker_compose_path }}'
mode: 0755
become: true
- name: Ensure handlers are notified now to avoid firewall conflicts.
meta: flush_handlers
- name: Ensure docker users are added to the docker group.
user:
name: "{{ ansible_user }}"
groups: docker
append: true
become: true
- name: reset ssh connection to allow user changes to affect 'current login user'
meta: reset_connection

View File

@ -0,0 +1,3 @@
---
- include_tasks: Debian-setup-docker.yml

View File

@ -1,8 +1,21 @@
---
- include_tasks: preflight.yml
- include_tasks: setup-ubuntu.yml
- name: Throw error when finding out properly running container
fail:
msg: "Appsmith may already run on this server. Please check out from this address http://{{ansible_host}}"
when:
- container_running.stdout == 'true'
- http_request.status == 200
- include_tasks: setup-docker.yml
- name: Throw error when existing container not reachable
fail:
msg: "Appsmith may be installed but not work properly. Please check on server (IP: {{ansible_host}})"
when: container_running.stdout == 'true'
- include_tasks: "{{ ansible_distribution }}-setup-docker.yml"
when: "'docker' not in ansible_facts.packages"
- include_tasks: start-docker.yml
- include_tasks: setup-appsmith.yml

View File

@ -1,35 +1,32 @@
---
- name: Check if docker is installed
package_facts:
manager: auto
- name: Check running container
shell: docker inspect --format={{ '{{.State.Running}}' }} appsmith
register: container_running
ignore_errors: True
- name: Check folder installation exist and empty
find:
paths: '{{ install_dir }}'
register: filesFound
stat:
path: '{{ install_dir }}'
register: installDir
- fail:
msg: 'The {{ install_dir }} folder is existed and not empty'
when: filesFound.matched > 0
- name: Check docker-compose.yml file exists
stat:
path: '{{ install_dir }}/{{ template_file_name }}'
register: template_file
- name: Check port 80 is listening
wait_for:
port: 80
delay: 2
timeout: 5
msg: 'Timeout waiting for 80 to respond'
register: port_80
ignore_errors: yes
- fail:
msg: 'Port 80 is running'
when: port_80.failed == false
- name: Check port 443 is listening
wait_for:
port: 443
delay: 2
timeout: 5
msg: 'Timeout waiting for 443 to respond'
register: port_443
ignore_errors: yes
- fail:
msg: 'Port 443 is running'
when: port_443.failed == false
- name: Health check running container
uri:
url: http://localhost/api/v1/users/me
method: GET
status_code:
- 200
- 502
- 503
register: http_request
when:
- container_running.stdout == 'true'

View File

@ -3,14 +3,17 @@
file:
path: '{{ install_dir }}'
state: directory
when: installDir.stat.exists == false
- name: Download docker-compose.yml
get_url:
url: https://raw.githubusercontent.com/appsmithorg/appsmith/release/deploy/aws_ami/docker-compose.yml
dest: '{{ install_dir }}'
mode: 0440
when: template_file.stat.exists == false
- name: Start Appsmith
shell: docker-compose up -d
args:
chdir: '{{ install_dir }}'
notify: "Start Appsmith with docker-compose"

View File

@ -1,47 +0,0 @@
---
- name: Install Docker
package:
name: '{{ docker_package }}'
state: '{{ docker_package_state }}'
become: yes
- name: Ensure Docker is started and enabled at boot
service:
name: docker
state: '{{ docker_service_state }}'
enabled: '{{ docker_service_enabled }}'
- name: Ensure handlers are notified now to avoid firewall conflicts
meta: flush_handlers
- name: Ensure docker users are added to the docker group
user:
name: '{{ ansible_user }}'
groups: docker
append: true
become: yes
- name: reset ssh connection to allow user changes to affect 'current login user'
meta: reset_connection
- name: Check current docker-compose version
command: docker-compose --version
register: docker_compose_current_version
changed_when: false
failed_when: false
- name: Delete existing docker-compose version if it's different
file:
path: '{{ docker_compose_path }}'
state: absent
when: >
docker_compose_current_version.stdout is defined
and docker_compose_version not in docker_compose_current_version.stdout
become: yes
- name: Install Docker-compose
get_url:
url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64
dest: '{{ docker_compose_path }}'
mode: 0755
become: yes

View File

@ -1,53 +0,0 @@
---
- name: Upgrade all packages to the latest version
apt:
name: '*'
state: latest
become: yes
- name: Install required system packages
apt:
update_cache: yes
name:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- python3-pip
- virtualenv
- python3-setuptools
state: latest
become: yes
tags:
- always
- name: Ensure old versions of Docker are not installed
package:
name:
- docker
- docker-engine
state: absent
- name: Ensure dependencies are installed
apt:
name:
- apt-transport-https
- ca-certificates
- gnupg2
- curl
state: present
become: yes
- name: Add Docker apt key
shell: >
curl -sSL {{ docker_apt_gpg_key }} | sudo apt-key add -
args:
warn: false
become: yes
- name: Add Docker repository
apt_repository:
repo: '{{ docker_apt_repository }}'
state: present
update_cache: true
become: yes

View File

@ -0,0 +1,13 @@
---
- name: Enable docker
service:
enabled: yes
name: 'docker'
state: 'started'
become: true
- name: Start docker
service:
name: 'docker'
state: 'restarted'
become: true