semaphore-playbooks/debian12-basic.yml
2023-07-21 06:12:06 +02:00

50 lines
No EOL
1.1 KiB
YAML

---
- name: Update web servers
hosts: all
remote_user: root
vars:
swapfile_size: 1024
swapfile_path: /swapfile
tasks:
- name: Update all packages to their latest version
ansible.builtin.apt:
name: "*"
state: latest
update_cache: yes
- name: Install a list of packages
ansible.builtin.apt:
pkg:
- htop
- unp
- name: Create swap file
command: dd if=/dev/zero of={{ swapfile_path }} bs=1M count={{ swapfile_size }}
args:
creates: "{{ swapfile_path }}"
register: swapfile_register_create
- name: Set swap file permissions
file:
path: "{{ swapfile_path }}"
state: "file"
owner: "root"
group: "root"
mode: "0600"
- name: Initialize swap file
command: mkswap {{ swapfile_path }}
when: swapfile_register_create is changed
- name: Enable swap file
command: swapon {{ swapfile_path }}
when: swapfile_register_create is changed
- name: Manage swap file in /etc/fstab
mount:
src: "{{ swapfile_path }}"
name: "none"
fstype: "swap"
opts: "sw,nofail"
dump: "0"
passno: "0"
state: "present"