Skip to content

Commit

Permalink
update ansible playbook for alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriipavlov committed Mar 6, 2024
1 parent 7a33b24 commit 92c2f4d
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/workflow-develop2-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Develop Deploy
name: Develop2 Deploy

on:
push:
Expand All @@ -7,13 +7,13 @@ on:
workflow_dispatch: {}

jobs:
deploy-to-dev:
deploy-to-dev2:
uses: ./.github/workflows/job-deploy.yml
secrets:
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_CONFIG: ${{ secrets.SSH_CONFIG_DEV2 }}
with:
SSH_ALIAS: ssh_alias
DEPLOY_PATH_DESTINATION: /srv/develop2.starter-kit.io
DEPLOYMENT_NAME: "StarterKit push to develop"
DEPLOYMENT_NAME: "StarterKit push to develop2"
ENVIRONMENT_TYPE: dev
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ terraform:
terraform -chdir=iac/terraform $(PARAMS)

ansible:
ansible-playbook -i iac/ansible/inventory.ini iac/ansible/prepare-servers.yml $(PARAMS)
ansible-playbook -i iac/ansible/inventory.ini iac/ansible/playbook-alpine.yml $(PARAMS)

# docker build|docker push|docker clean
docker:
Expand Down
3 changes: 3 additions & 0 deletions iac/ansible/inventory.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[development]
develop.starter-kit.io ansible_user=ubuntu

[development2]
develop2.starter-kit.io ansible_user=alpine

[staging]
staging.starter-kit.io ansible_user=ubuntu

Expand Down
81 changes: 81 additions & 0 deletions iac/ansible/playbook-alpine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
- name: Install Docker with Docker Compose plugin on Alpine Server
hosts:
- development2
become: yes
become_method: doas
tasks:
- name: Update apk cache
command: apk update

- name: Install required system packages
apk:
name: "{{ packages }}"
state: present
vars:
packages:
- make
- rsync
- docker
- docker-cli-compose

- name: Add docker service to start at boot
command: rc-update add docker default

- name: Start docker service
service:
name: docker
state: started
enabled: yes

- name: Add current user to the docker group
user:
name: "{{ ansible_user }}"
groups: docker
append: yes

- name: Verify Docker installation
command: docker --version
register: docker_version
changed_when: false

- name: Output Docker version
debug:
var: docker_version.stdout

- name: Verify Docker Compose installation
command: docker compose version
register: compose_version
changed_when: false

- name: Output Docker Compose plugin version
debug:
var: compose_version.stdout

- name: Ensure ansible_user owns the deploy folder
file:
path: /srv
owner: "{{ ansible_user }}"
state: directory
recurse: yes

- name: Update hostname
hostname:
name: "{{ inventory_hostname }}"

- name: Update hostname with command
command: hostname "{{ inventory_hostname }}"

- name: Ensure ~/.profile exists
file:
path: "/home/{{ ansible_user }}/.profile"
state: touch
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"

- name: Update command prompt (PS1) to show user@hostname in .profile
lineinfile:
path: "/home/{{ ansible_user }}/.profile"
line: "export PS1='\\u@$(hostname):\\w\\$ '"
regexp: '^export PS1='
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
File renamed without changes.
19 changes: 18 additions & 1 deletion iac/terraform/instances.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ resource "aws_instance" "develop-server" {
}
}

resource "aws_instance" "develop2-server" {
ami = "ami-01c3c86584374c23b" # alpine-3.19.1-aarch64-uefi-cloudinit-r0 64-bit (Arm), SSD Volume Type
instance_type = "t4g.nano"
vpc_security_group_ids = [aws_security_group.allow_http_s.id, aws_security_group.allow_ssh.id]
key_name = aws_key_pair.deploy.key_name

tags = {
Name = "starter-kit.io DEV2"
Environment = "Development"
}

root_block_device {
volume_type = "gp2" # General Purpose SSD
volume_size = 8 # Size in GB
}
}

/*resource "aws_instance" "production-server" {
ami = "ami-0fc02b454efabb390" # Ubuntu Server 22.04 LTS (HVM) 64-bit (Arm), SSD Volume Type
instance_type = "t4g.micro"
Expand All @@ -34,7 +51,7 @@ resource "aws_instance" "develop-server" {
}*/

output "develop_ip_addr" {
value = aws_instance.develop-server.public_ip
value = aws_instance.develop2-server.public_ip
}

/*output "prod_ip_addr" {
Expand Down

0 comments on commit 92c2f4d

Please sign in to comment.