U1.28 Ubuntu Quick Start (QS): Swap file management with Ansible - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki
- we can change the swap file setting with a list of commands until we need to manage more than one virtual machine or hosts
- read the article How To Add Swap Space on Ubuntu 20.04
sudo swapon --show
sudo swapon -s
free -h
sudo fallocate -l 1G /swapfile
ls -lh /swapfile
sudo chmod 600 /swapfile
ls -lh /swapfilels -lh /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
sudo swapon -s
free -h
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
cat /proc/sys/vm/swappiness
sudo nano /etc/sysctl.conf
- add to /etc/sysctl.conf-file the line below
vm.swappiness=60
-
instead of writing new playbook from scratch
- read the article [Ansible Role: Swap] (https://galaxy.ansible.com/geerlingguy/swap)
- read the article Ansible-Galaxy Role: Swap
-
our goal is to check it out
-
Pre-installed DHCP in the virtual environment (for example, a hardware implementation of a DHCP server in a modem)
-
Deploy four Ubuntu 20.04 TLS virtual machines. Consult the articles U1.01 and U1.02
- Device name = u200401, ip = 192.168.100.12
- Device name = u200402, ip = 192.168.100.3
- Device name = u200403, ip = 192.168.100.17
- Device name = UbuntuAnsible, ip = 192.168.100.26
-
For each machine u200401, u200402, u200403, UbuntuAnsible
- run the command python3 --version
- In our case it returns : Python 3.8.10
- run the command python3 --version
-
For each machine u200401, u200402, u200403, UbuntuAnsible
- we have sudo-enabled user = yury with identical password for each machine
-
For each machine u200401, u200402, u200403, UbuntuAnsible
- run the command
sudo apt install openssh-server
- For the machine UbuntuAnsible
- run the commands (no sudo prefix for the first four commands)
ssh-keygen
ssh-copy-id 192.168.100.12
ssh-copy-id 192.168.100.3
ssh-copy-id 192.168.100.17
- For the machine UbuntuAnsible
- read the article Installing Ansible on Ubuntu
- run the commands
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible
- For the machine UbuntuAnsible
- run the command (no sudo prefix for command)
ansible-galaxy install geerlingguy.swap
Click to show the picture
Click to show the picture
- For the machine UbuntuAnsible
- run command (no sudo prefix for command)
mkdir swapmng
cd swapmng
- For the machine UbuntuAnsible
- run command (no sudo prefix for command)
nano inventory.ini
- insert definitions
[all]
node1 ansible_host=192.168.100.12
node2 ansible_host=192.168.100.3
node3 ansible_host=192.168.100.17
[swap128]
node1
[swap256]
node2
[swap512]
node3
- For the machine UbuntuAnsible
- run command (no sudo prefix for command)
nano swapon_pb.yml
- modify swapon_pb.yml and save
---
- hosts: swap128
vars:
swap_file_size_mb: '128'
roles:
- geerlingguy.swap
- hosts: swap256
vars:
swap_file_size_mb: '256'
roles:
- geerlingguy.swap
- hosts: swap512
vars:
swap_file_size_mb: '512'
roles:
- geerlingguy.swap
- For the machine UbuntuAnsible
- run command (no sudo prefix for command)
nano swapoff_pb.yml
- modify swapoff_pb.yml and save
---
- hosts: swap128
vars:
swap_file_state: absent
roles:
- geerlingguy.swap
- hosts: swap256
vars:
swap_file_state: absent
roles:
- geerlingguy.swap
- hosts: swap512
vars:
swap_file_state: absent
roles:
- geerlingguy.swap
- from inside u200401, u200402, u200403
- run command
free -m
Click to show the picture
- from inside UbuntuAnsible
- run command (no sudo prefix for command)
ansible-playbook -i inventory.ini --become --become-user=root -K swapon_pb.yml
Click to show the picture
- from inside u200401, u200402, u200403
- run command
free -m
Click to show the picture
- from inside UbuntuAnsible
- run command (no sudo prefix for command)
ansible-playbook -i inventory.ini --become --become-user=root -K swapoff_pb.yml
Click to show the picture
- from inside u200401, u200402, u200403
- run command
free -m