Skip to content

Commit

Permalink
update ansible configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriipavlov committed Mar 7, 2024
1 parent b56daef commit c235d1e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 193 deletions.
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/playbook.yml $(PARAMS)
ansible-playbook -i iac/ansible/inventory.yml iac/ansible/playbook.yml $(PARAMS)

# docker build|docker push|docker clean
docker:
Expand Down
11 changes: 0 additions & 11 deletions iac/ansible/inventory.ini

This file was deleted.

28 changes: 28 additions & 0 deletions iac/ansible/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
all:
children:
development:
hosts:
develop.starter-kit.io:
os: ubuntu
ansible_user: ubuntu

development2:
hosts:
develop2.starter-kit.io:
os: debian
ansible_user: admin
swap_vars:
size: 2G
swappiness: 20

staging:
hosts:
staging.starter-kit.io:
os: ubuntu
ansible_user: ubuntu

production:
hosts:
prod.starter-kit.io:
os: ubuntu
ansible_user: ubuntu
44 changes: 28 additions & 16 deletions iac/ansible/partials/setup-swap.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
# Setup swap

- name: Check if swap is already enabled
shell: swapon --show | grep -q "^"
register: swap_exists
changed_when: false
ignore_errors: true
- name: Gather system facts
setup:
# Ensures Ansible facts are up to date.

- name: Set fact for swap existence based on Ansible facts
set_fact:
swap_exists: "{{ ansible_swaptotal_mb > 0 }}"
# Checks if swap space is already enabled.

- name: Create swap file
command: fallocate -l 1G /swapfile
when: swap_exists.rc != 0
become: yes
command: fallocate -l "{{ swap_vars.size }}" /swapfile
when: not swap_exists
# Creates a swap file with the specified size from your main playbook's vars.

- name: Set swap file permissions
file:
path: /swapfile
mode: '0600'
when: swap_exists.rc != 0
become: yes
when: not swap_exists
# Sets appropriate permissions for the swap file.

- name: Set up swap space
command: mkswap /swapfile
when: swap_exists.rc != 0
become: yes
when: not swap_exists
# Initializes the swap file.

- name: Enable swap
command: swapon /swapfile
when: swap_exists.rc != 0
become: yes
when: not swap_exists
# Activates the swap file.

- name: Add swap to fstab
blockinfile:
path: /etc/fstab
block: "/swapfile none swap sw 0 0"
marker: "# {mark} ANSIBLE MANAGED BLOCK"
when: swap_exists.rc != 0
become: yes
when: not swap_exists
# Ensures the swap setup persists across reboots.

- name: Adjust swappiness
sysctl:
name: vm.swappiness
value: "{{ swap_vars.swappiness }}"
state: present
reload: yes
# This task is optional and adjusts the system's swappiness parameter.

82 changes: 0 additions & 82 deletions iac/ansible/playbook-alpine.yml

This file was deleted.

83 changes: 0 additions & 83 deletions iac/ansible/playbook-debian.yml

This file was deleted.

0 comments on commit c235d1e

Please sign in to comment.