semaphore-playbooks/debian12-basic.yml

55 lines
1.3 KiB
YAML
Raw Normal View History

2023-07-21 00:23:22 +00:00
---
- name: Update web servers
hosts: all
remote_user: root
2023-07-21 04:09:23 +00:00
vars:
swapfile_size: 1
swapfile_path: /swapfile
2023-07-21 00:23:22 +00:00
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:
2023-07-21 03:00:58 +00:00
- htop
2023-07-21 04:09:23 +00:00
- unp
- name: Create swap file
command: |
{% if swapfile_fallocate %}
fallocate -l {{ ((swapfile_size) | int * 1024 * 1024) }} {{ swapfile_path }}
{% else %}
dd if=/dev/zero of={{ swapfile_path }} bs=1M count={{ swapfile_size }}
{% endif %}
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"