Skip to content

Instantly share code, notes, and snippets.

@brootware
Last active September 8, 2024 11:16
Show Gist options
  • Save brootware/9061c5c72fdb2f82b5c23739d161b57e to your computer and use it in GitHub Desktop.
Save brootware/9061c5c72fdb2f82b5c23739d161b57e to your computer and use it in GitHub Desktop.
Quick and simple ansible play to test out on your own local host
---
- name: Local plays
hosts: localhost
gather_facts: yes
become: true
tasks:
- name: Update apt cache
apt:
update_cache: yes
when: ansible_os_family == "Debian"
- name: Upgrade all installed packages
apt:
upgrade: dist
allow_unauthenticated: yes
when: ansible_os_family == "Debian"
- name: Auto remove unused packages
apt:
autoremove: yes
when: ansible_os_family == "Debian"
- name: Check for presence of reboot status file.
stat:
path: /var/run/reboot-required
register: reboot_status_file
- name: Check file status of crypttab for LUKs encryption
stat:
path: /etc/crypttab
register: crypttab_status
- name: Debug crypttab
debug:
msg: "{{ crypttab_status }}"
- name: Prompt the user reboot is required if required and LUKs encryption exist.
debug:
msg: "A manual reboot is required for this machine as there is LUKs encryption."
when: reboot_status_file.stat.exists and crypttab_status.stat.exists == true
- name: Reboot the machine if no LUKs encryption.
reboot:
msg: "Rebooting the machine as updates have been applied."
reboot_timeout: 600
when: crypttab_status.stat.exists == false
# To run this ansible-playbook localplay.yml --ask-become-pass
- name: Local plays
hosts: localhost
gather_facts: yes
become: true
tasks:
- name: print out all details from gathered facts
ansible.builtin.debug:
msg: "{{ ansible_facts }}"
- name: update apt cache
ansible.builtin.apt:
update_cache: yes
when: ansible_os_family == "Debian"
# You can add in more plays here to test out.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment