Refactor playbooks and roles to enhance task organization and improve package management. Update development and local playbooks to include descriptive names, streamline APT tasks, and ensure consistent use of Ansible modules. Modify group variables for timezone and update role metadata for clarity. Improve error handling and user feedback in various roles, including applications, base, and snap, by utilizing built-in Ansible modules and adding necessary checks.

This commit is contained in:
ilia 2025-08-29 15:42:09 -04:00
parent 0ad062b911
commit 67a5caef36
36 changed files with 197 additions and 224 deletions

0
.ansible/.lock Normal file
View File

View File

@ -1,4 +1,5 @@
- hosts: dev - name: Configure development environment
hosts: dev
become: true become: true
roles: roles:
@ -14,11 +15,11 @@
pre_tasks: pre_tasks:
- name: Update apt cache - name: Update apt cache
apt: ansible.builtin.apt:
update_cache: yes update_cache: true
tasks: tasks:
# Additional tasks can be added here if needed # Additional tasks can be added here if needed
- name: Display completion message - name: Display completion message
debug: ansible.builtin.debug:
msg: "Development environment setup completed successfully!" msg: "Development environment setup completed successfully!"

View File

@ -1,6 +1,6 @@
--- ---
# Common variables for all hosts # Common variables for all hosts
timezone: UTC timezone: America/Toronto
locale: en_US.UTF-8 locale: en_US.UTF-8
ansible_python_interpreter: /usr/bin/python3 ansible_python_interpreter: /usr/bin/python3

View File

@ -1,4 +1,5 @@
- hosts: localhost - name: Setup local development environment
hosts: localhost
connection: local connection: local
become: true become: true
@ -15,10 +16,10 @@
pre_tasks: pre_tasks:
- name: Update apt cache - name: Update apt cache
apt: ansible.builtin.apt:
update_cache: yes update_cache: true
tasks: tasks:
- name: Display completion message - name: Display completion message
debug: ansible.builtin.debug:
msg: "Local development environment setup completed successfully!" msg: "Local development environment setup completed successfully!"

View File

@ -1,2 +1 @@
---
dependencies: [] dependencies: []

View File

@ -1,34 +1,35 @@
--- ---
- name: Check if applications are already installed - name: Check if applications are already installed
package_facts: ansible.builtin.package_facts:
manager: apt manager: apt
- name: Check if Brave browser is installed - name: Check if Brave browser is installed
command: brave-browser --version ansible.builtin.command: brave-browser --version
register: brave_check register: applications_brave_check
ignore_errors: true ignore_errors: true
changed_when: false changed_when: false
failed_when: false failed_when: false
no_log: true no_log: true
- name: Set installation conditions - name: Set installation conditions
set_fact: ansible.builtin.set_fact:
desktop_apps_needed: "{{ ['redshift', 'libreoffice', 'evince'] | difference(ansible_facts.packages.keys()) | length > 0 }}" applications_desktop_apps_needed: "{{ ['redshift', 'libreoffice', 'evince'] | difference(ansible_facts.packages.keys()) | length > 0 }}"
brave_needs_install: "{{ brave_check.rc != 0 or 'brave-browser' not in ansible_facts.packages }}" applications_brave_needs_install: "{{ applications_brave_check.rc != 0 or 'brave-browser' not in ansible_facts.packages }}"
- name: Install desktop applications - name: Install desktop applications
apt: ansible.builtin.apt:
name: name:
- redshift - redshift
- libreoffice - libreoffice
- evince - evince
state: present state: present
when: desktop_apps_needed when: applications_desktop_apps_needed
- name: Brave browser installation - name: Brave browser installation
when: applications_brave_needs_install
block: block:
- name: Remove old Brave repository files - name: Remove old Brave repository files
file: ansible.builtin.file:
path: "{{ item }}" path: "{{ item }}"
state: absent state: absent
loop: loop:
@ -36,31 +37,29 @@
- /etc/apt/sources.list.d/brave-browser-release.sources - /etc/apt/sources.list.d/brave-browser-release.sources
- name: Download Brave APT key - name: Download Brave APT key
get_url: ansible.builtin.get_url:
url: https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg url: https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg
dest: /usr/share/keyrings/brave-browser-archive-keyring.gpg dest: /usr/share/keyrings/brave-browser-archive-keyring.gpg
mode: '0644' mode: '0644'
- name: Add Brave repository - name: Add Brave repository
apt_repository: ansible.builtin.apt_repository:
repo: "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg] https://brave-browser-apt-release.s3.brave.com/ stable main" repo: "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg] https://brave-browser-apt-release.s3.brave.com/ stable main"
filename: brave-browser filename: brave-browser
state: present state: present
- name: Install Brave browser - name: Install Brave browser
apt: ansible.builtin.apt:
name: brave-browser name: brave-browser
state: present state: present
when: brave_needs_install
- name: Display application status - name: Display application status
debug: ansible.builtin.debug:
msg: msg:
- "Desktop apps needed: {{ desktop_apps_needed }}" - "Desktop apps needed: {{ applications_desktop_apps_needed }}"
- "Brave needed: {{ brave_needs_install }}" - "Brave needed: {{ applications_brave_needs_install }}"
- "Redshift: {{ 'Installed' if 'redshift' in ansible_facts.packages else 'Missing' }}" - "Redshift: {{ 'Installed' if 'redshift' in ansible_facts.packages else 'Missing' }}"
- "LibreOffice: {{ 'Installed' if 'libreoffice' in ansible_facts.packages else 'Missing' }}" - "LibreOffice: {{ 'Installed' if 'libreoffice' in ansible_facts.packages else 'Missing' }}"
- "Evince: {{ 'Installed' if 'evince' in ansible_facts.packages else 'Missing' }}" - "Evince: {{ 'Installed' if 'evince' in ansible_facts.packages else 'Missing' }}"
- "Brave: {{ brave_check.stdout if brave_check.rc == 0 else 'Not installed' }}" - "Brave: {{ applications_brave_check.stdout if applications_brave_check.rc == 0 else 'Not installed' }}"
when: ansible_debug_output | default(false) | bool when: ansible_debug_output | default(false) | bool

View File

@ -1,10 +1,11 @@
--- ---
# handlers file for base # handlers file for base
- name: restart fail2ban - name: Restart fail2ban
systemd: ansible.builtin.systemd:
name: fail2ban name: fail2ban
state: restarted state: restarted
- name: reload ufw - name: Reload ufw
command: ufw reload ansible.builtin.command: ufw reload
changed_when: false

View File

@ -1,52 +1 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: [] dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@ -1,6 +1,6 @@
--- ---
- name: Install base system packages - name: Install base system packages
apt: ansible.builtin.apt:
name: name:
# Base utilities # Base utilities
- htop - htop
@ -20,7 +20,7 @@
state: present state: present
- name: Configure fail2ban - name: Configure fail2ban
template: ansible.builtin.template:
src: jail.local.j2 src: jail.local.j2
dest: /etc/fail2ban/jail.local dest: /etc/fail2ban/jail.local
mode: '0644' mode: '0644'
@ -29,10 +29,10 @@
# UFW enablement moved to ssh role to avoid lockout # UFW enablement moved to ssh role to avoid lockout
- name: Set timezone - name: Set timezone
timezone: community.general.timezone:
name: "{{ timezone | default('UTC') }}" name: "{{ timezone | default('UTC') }}"
- name: Configure locale - name: Configure locale
locale_gen: community.general.locale_gen:
name: "{{ locale | default('en_US.UTF-8') }}" name: "{{ locale | default('en_US.UTF-8') }}"
state: present state: present

View File

@ -1,5 +1,6 @@
--- ---
- hosts: localhost - name: Test base role
hosts: localhost
remote_user: root remote_user: root
roles: roles:
- base - base

View File

@ -1,7 +1,7 @@
galaxy_info: galaxy_info:
author: your name author: ansible-user
description: your role description description: Development tools and environment setup role
company: your company (optional) company: Personal
# If the issue tracker for your role is not on github, uncomment the # If the issue tracker for your role is not on github, uncomment the
# next line and provide a value # next line and provide a value
@ -14,9 +14,9 @@ galaxy_info:
# - GPL-3.0-only # - GPL-3.0-only
# - Apache-2.0 # - Apache-2.0
# - CC-BY-4.0 # - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc) license: MIT
min_ansible_version: 2.1 min_ansible_version: "2.9"
# If this a Container Enabled role, provide the minimum Ansible Container version. # If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version: # min_ansible_container_version:

View File

@ -1,13 +1,13 @@
--- ---
- name: Install development packages - name: Install development packages
apt: ansible.builtin.apt:
name: name:
# Development tools # Development tools
- git - git
- nodejs - nodejs
- npm - npm
# Build tools # Build tools
- build-essential - build-essential
- python3 - python3
- python3-pip - python3-pip
state: present state: present

View File

@ -1,5 +1,6 @@
--- ---
- hosts: localhost - name: Test development role
hosts: localhost
remote_user: root remote_user: root
roles: roles:
- development - development

View File

@ -1,7 +1,7 @@
galaxy_info: galaxy_info:
author: your name author: ansible-user
description: your role description description: Docker installation and configuration role
company: your company (optional) company: Personal
# If the issue tracker for your role is not on github, uncomment the # If the issue tracker for your role is not on github, uncomment the
# next line and provide a value # next line and provide a value
@ -14,9 +14,9 @@ galaxy_info:
# - GPL-3.0-only # - GPL-3.0-only
# - Apache-2.0 # - Apache-2.0
# - CC-BY-4.0 # - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc) license: MIT
min_ansible_version: 2.1 min_ansible_version: "2.9"
# If this a Container Enabled role, provide the minimum Ansible Container version. # If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version: # min_ansible_container_version:

View File

@ -1,7 +1,7 @@
--- ---
- name: Debug distribution information - name: Debug distribution information
debug: ansible.builtin.debug:
msg: msg:
- "Distribution: {{ ansible_facts['distribution'] }}" - "Distribution: {{ ansible_facts['distribution'] }}"
- "Distribution Release: {{ ansible_facts['distribution_release'] }}" - "Distribution Release: {{ ansible_facts['distribution_release'] }}"
- "Distribution Version: {{ ansible_facts['distribution_version'] }}" - "Distribution Version: {{ ansible_facts['distribution_version'] }}"
@ -9,7 +9,7 @@
when: ansible_debug_output | default(false) | bool when: ansible_debug_output | default(false) | bool
- name: Check if Docker is already installed - name: Check if Docker is already installed
command: docker --version ansible.builtin.command: docker --version
register: docker_check register: docker_check
ignore_errors: true ignore_errors: true
changed_when: false changed_when: false
@ -17,19 +17,20 @@
no_log: true no_log: true
- name: Check if Docker packages are installed via apt - name: Check if Docker packages are installed via apt
package_facts: ansible.builtin.package_facts:
manager: apt manager: apt
register: docker_apt_check register: docker_apt_check
changed_when: false changed_when: false
- name: Set installation condition - name: Set installation condition
set_fact: ansible.builtin.set_fact:
docker_needs_install: "{{ docker_check.rc != 0 or 'docker-ce' not in ansible_facts.packages }}" docker_needs_install: "{{ docker_check.rc != 0 or 'docker-ce' not in ansible_facts.packages }}"
- name: Docker installation tasks - name: Docker installation tasks
when: docker_needs_install
block: block:
- name: Install Docker requirements - name: Install Docker requirements
apt: ansible.builtin.apt:
name: name:
- apt-transport-https - apt-transport-https
- ca-certificates - ca-certificates
@ -39,7 +40,7 @@
state: present state: present
- name: Remove old Docker repository files - name: Remove old Docker repository files
file: ansible.builtin.file:
path: "{{ item }}" path: "{{ item }}"
state: absent state: absent
loop: loop:
@ -47,19 +48,19 @@
- /etc/apt/sources.list.d/docker-ce.list - /etc/apt/sources.list.d/docker-ce.list
- name: Create keyrings directory - name: Create keyrings directory
file: ansible.builtin.file:
path: /etc/apt/keyrings path: /etc/apt/keyrings
state: directory state: directory
mode: '0755' mode: '0755'
- name: Setup Docker GPG key - name: Setup Docker GPG key
include_tasks: setup_gpg_key.yml ansible.builtin.include_tasks: setup_gpg_key.yml
- name: Setup Docker repository - name: Setup Docker repository
include_tasks: "setup_repo_{{ ansible_facts['distribution'] | lower | replace(' ', '_') }}.yml" ansible.builtin.include_tasks: "setup_repo_{{ ansible_facts['distribution'] | lower | replace(' ', '_') }}.yml"
- name: Install Docker CE - name: Install Docker CE
apt: ansible.builtin.apt:
name: name:
- docker-ce - docker-ce
- docker-ce-cli - docker-ce-cli
@ -69,27 +70,25 @@
state: present state: present
- name: Start and enable Docker service - name: Start and enable Docker service
systemd: ansible.builtin.systemd:
name: docker name: docker
state: started state: started
enabled: yes enabled: true
- name: Set target user variable - name: Set target user variable
set_fact: ansible.builtin.set_fact:
target_user: "{{ ansible_user | default(ansible_user_id) }}" docker_target_user: "{{ ansible_user | default(ansible_user_id) }}"
- name: Add user to docker group - name: Add user to docker group
user: ansible.builtin.user:
name: "{{ target_user }}" name: "{{ docker_target_user }}"
groups: docker groups: docker
append: yes append: true
when: docker_needs_install
- name: Display Docker status - name: Display Docker status
debug: ansible.builtin.debug:
msg: msg:
- "Docker already installed: {{ docker_check.stdout if docker_check.rc == 0 else 'Not found' }}" - "Docker already installed: {{ docker_check.stdout if docker_check.rc == 0 else 'Not found' }}"
- "Docker CE package installed: {{ 'Yes' if 'docker-ce' in ansible_facts.packages else 'No' }}" - "Docker CE package installed: {{ 'Yes' if 'docker-ce' in ansible_facts.packages else 'No' }}"
- "Actions taken: {{ 'None - Docker already present' if not docker_needs_install else 'Docker installation/configuration performed' }}" - "Actions taken: {{ 'None - Docker already present' if not docker_needs_install else 'Docker installation/configuration performed' }}"
when: ansible_debug_output | default(false) | bool when: ansible_debug_output | default(false) | bool

View File

@ -1,19 +1,20 @@
--- ---
- name: Download Docker's official GPG key - name: Download Docker's official GPG key
get_url: ansible.builtin.get_url:
url: https://download.docker.com/linux/ubuntu/gpg url: https://download.docker.com/linux/ubuntu/gpg
dest: /tmp/docker.gpg dest: /tmp/docker.gpg
mode: '0644' mode: '0644'
- name: Convert and install Docker GPG key - name: Convert and install Docker GPG key
shell: gpg --dearmor < /tmp/docker.gpg > /etc/apt/keyrings/docker.gpg ansible.builtin.shell: gpg --dearmor < /tmp/docker.gpg > /etc/apt/keyrings/docker.gpg
changed_when: false
- name: Set permissions on Docker GPG key - name: Set permissions on Docker GPG key
file: ansible.builtin.file:
path: /etc/apt/keyrings/docker.gpg path: /etc/apt/keyrings/docker.gpg
mode: '0644' mode: '0644'
- name: Clean up temporary GPG key file - name: Clean up temporary GPG key file
file: ansible.builtin.file:
path: /tmp/docker.gpg path: /tmp/docker.gpg
state: absent state: absent

View File

@ -1,6 +1,6 @@
--- ---
- name: Add Docker repository for Debian - name: Add Docker repository for Debian
apt_repository: ansible.builtin.apt_repository:
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable" repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
state: present state: present
update_cache: yes update_cache: true

View File

@ -1,10 +1,14 @@
--- ---
- name: Set Ubuntu codename for Linux Mint - name: Set Ubuntu codename for Linux Mint
set_fact: ansible.builtin.set_fact:
ubuntu_codename: "{{ 'jammy' if ansible_distribution_version is version('22', '>=') else 'focal' if ansible_distribution_version is version('21', '>=') else 'focal' if ansible_distribution_version is version('20', '>=') else 'bionic' }}" docker_ubuntu_codename: >
{{ 'jammy' if ansible_distribution_version is version('22', '>=') else
'focal' if ansible_distribution_version is version('21', '>=') else
'focal' if ansible_distribution_version is version('20', '>=') else
'bionic' }}
- name: Add Docker repository for Linux Mint (using Ubuntu base) - name: Add Docker repository for Linux Mint (using Ubuntu base)
apt_repository: ansible.builtin.apt_repository:
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ ubuntu_codename }} stable" repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ docker_ubuntu_codename }} stable"
state: present state: present
update_cache: yes update_cache: true

View File

@ -1,6 +1,6 @@
--- ---
- name: Add Docker repository for Ubuntu - name: Add Docker repository for Ubuntu
apt_repository: ansible.builtin.apt_repository:
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable" repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present state: present
update_cache: yes update_cache: true

View File

@ -1,5 +1,6 @@
--- ---
- hosts: localhost - name: Test docker role
hosts: localhost
remote_user: root remote_user: root
roles: roles:
- docker - docker

View File

@ -1,7 +1,7 @@
galaxy_info: galaxy_info:
author: your name author: ansible-user
description: your role description description: System maintenance and updates role
company: your company (optional) company: Personal
# If the issue tracker for your role is not on github, uncomment the # If the issue tracker for your role is not on github, uncomment the
# next line and provide a value # next line and provide a value
@ -14,9 +14,9 @@ galaxy_info:
# - GPL-3.0-only # - GPL-3.0-only
# - Apache-2.0 # - Apache-2.0
# - CC-BY-4.0 # - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc) license: MIT
min_ansible_version: 2.1 min_ansible_version: "2.9"
# If this a Container Enabled role, provide the minimum Ansible Container version. # If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version: # min_ansible_container_version:

View File

@ -1,25 +1,25 @@
--- ---
- name: Upgrade all packages - name: Upgrade all packages
apt: ansible.builtin.apt:
upgrade: dist upgrade: dist
- name: Autoremove unused packages - name: Autoremove unused packages
apt: ansible.builtin.apt:
autoremove: yes autoremove: true
- name: Clean apt cache - name: Clean apt cache
apt: ansible.builtin.apt:
autoclean: yes autoclean: true
- name: Check if reboot is required - name: Check if reboot is required
stat: ansible.builtin.stat:
path: /var/run/reboot-required path: /var/run/reboot-required
register: reboot_required register: maintenance_reboot_required
- name: Reboot if required - name: Reboot if required
reboot: ansible.builtin.reboot:
msg: "Reboot triggered by Ansible after system changes." msg: "Reboot triggered by Ansible after system changes."
when: when:
- ansible_facts['pkg_mgr'] == "apt" - ansible_facts['pkg_mgr'] == "apt"
- reboot_required.stat.exists - maintenance_reboot_required.stat.exists
- skip_reboot | default(false) | bool == false - not (skip_reboot | default(false) | bool)

View File

@ -1,5 +1,6 @@
--- ---
- hosts: localhost - name: Test maintenance role
hosts: localhost
remote_user: root remote_user: root
roles: roles:
- maintenance - maintenance

View File

@ -1,7 +1,7 @@
galaxy_info: galaxy_info:
author: your name author: ansible-user
description: your role description description: Shell configuration and setup role
company: your company (optional) company: Personal
# If the issue tracker for your role is not on github, uncomment the # If the issue tracker for your role is not on github, uncomment the
# next line and provide a value # next line and provide a value
@ -14,9 +14,9 @@ galaxy_info:
# - GPL-3.0-only # - GPL-3.0-only
# - Apache-2.0 # - Apache-2.0
# - CC-BY-4.0 # - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc) license: MIT
min_ansible_version: 2.1 min_ansible_version: "2.9"
# If this a Container Enabled role, provide the minimum Ansible Container version. # If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version: # min_ansible_container_version:

View File

@ -1,40 +1,41 @@
--- ---
- name: Set target user variable - name: Set target user variable
set_fact: ansible.builtin.set_fact:
target_user: "{{ ansible_user | default(ansible_user_id) }}" shell_target_user: "{{ ansible_user | default(ansible_user_id) }}"
- name: Install shell packages - name: Install shell packages
apt: ansible.builtin.apt:
name: name:
- zsh - zsh
- tmux - tmux
state: present state: present
- name: Set zsh as default shell for user - name: Set zsh as default shell for user
user: ansible.builtin.user:
name: "{{ target_user }}" name: "{{ shell_target_user }}"
shell: /usr/bin/zsh shell: /usr/bin/zsh
- name: Install Oh My Zsh for user - name: Install Oh My Zsh for user
become: true become: true
become_user: "{{ target_user }}" become_user: "{{ shell_target_user }}"
shell: sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" "" --unattended ansible.builtin.shell: sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" "" --unattended
args: args:
creates: "/home/{{ target_user }}/.oh-my-zsh" creates: "/home/{{ shell_target_user }}/.oh-my-zsh"
- name: Clone Powerlevel10k theme - name: Clone Powerlevel10k theme
git: ansible.builtin.git:
repo: https://github.com/romkatv/powerlevel10k.git repo: https://github.com/romkatv/powerlevel10k.git
dest: "/home/{{ target_user }}/.oh-my-zsh/custom/themes/powerlevel10k" dest: "/home/{{ shell_target_user }}/.oh-my-zsh/custom/themes/powerlevel10k"
version: master
depth: 1 depth: 1
update: no update: false
become: true become: true
become_user: "{{ target_user }}" become_user: "{{ shell_target_user }}"
- name: Deploy .zshrc for user - name: Deploy .zshrc for user
copy: ansible.builtin.copy:
src: files/.zshrc src: files/.zshrc
dest: "/home/{{ target_user }}/.zshrc" dest: "/home/{{ shell_target_user }}/.zshrc"
owner: "{{ target_user }}" owner: "{{ shell_target_user }}"
group: "{{ target_user }}" group: "{{ shell_target_user }}"
mode: '0644' mode: '0644'

View File

@ -1,5 +1,6 @@
--- ---
- hosts: localhost - name: Test shell role
hosts: localhost
remote_user: root remote_user: root
roles: roles:
- shell - shell

View File

@ -1,5 +1,5 @@
--- ---
- name: restart snapd - name: Restart snapd
systemd: ansible.builtin.systemd:
name: snapd name: snapd
state: restarted state: restarted

View File

@ -1,2 +1,12 @@
--- galaxy_info:
author: ansible-user
description: Snap package manager configuration role
company: Personal
license: MIT
min_ansible_version: "2.9"
galaxy_tags: []
dependencies: [] dependencies: []

View File

@ -1,76 +1,78 @@
--- ---
- name: Enable 'universe' repo (Ubuntu and Mint only) - name: Enable 'universe' repo (Ubuntu and Mint only)
command: add-apt-repository universe ansible.builtin.command: add-apt-repository universe
when: ansible_facts['distribution'] in ["Ubuntu", "Linux Mint"] when: ansible_facts['distribution'] in ["Ubuntu", "Linux Mint"]
changed_when: false changed_when: false
ignore_errors: true failed_when: false
- name: Remove Mint's nosnap.pref block (Mint only) - name: Remove Mint's nosnap.pref block (Mint only)
file: ansible.builtin.file:
path: /etc/apt/preferences.d/nosnap.pref path: /etc/apt/preferences.d/nosnap.pref
state: absent state: absent
when: ansible_facts['distribution'] == "Linux Mint" when: ansible_facts['distribution'] == "Linux Mint"
- name: Install Snap daemon - name: Install Snap daemon
apt: ansible.builtin.apt:
name: snapd name: snapd
state: present state: present
when: ansible_facts['os_family'] == "Debian" when: ansible_facts['os_family'] == "Debian"
notify: restart snapd notify: restart snapd
- name: Enable snapd socket on Debian - name: Enable snapd socket on Debian
systemd: ansible.builtin.systemd:
name: snapd.socket name: snapd.socket
enabled: true enabled: true
state: started state: started
when: ansible_facts['distribution'] == "Debian" when: ansible_facts['distribution'] == "Debian"
- name: Force Ansible to reload facts - name: Force Ansible to reload facts
setup: ansible.builtin.setup:
- name: Wait for snapd to be ready - name: Wait for snapd to be ready
command: snap wait system seed.loaded ansible.builtin.command: snap wait system seed.loaded
register: snap_wait_result register: snap_wait_result
until: snap_wait_result.rc == 0 until: snap_wait_result.rc == 0
retries: 10 retries: 10
delay: 5 delay: 5
when: ansible_facts['os_family'] == "Debian" when: ansible_facts['os_family'] == "Debian"
ignore_errors: true failed_when: false
changed_when: false
- name: Check if snap is working - name: Check if snap is working
command: snap list ansible.builtin.command: snap list
register: snap_check register: snap_check
when: ansible_facts['os_family'] == "Debian" when: ansible_facts['os_family'] == "Debian"
ignore_errors: true failed_when: false
changed_when: false
- name: Install VSCode IDE (Snap, all distros) - name: Install VSCode IDE (Snap, all distros)
community.general.snap: community.general.snap:
name: code name: code
classic: true classic: true
state: present state: present
when: when:
- ansible_facts['os_family'] == "Debian" - ansible_facts['os_family'] == "Debian"
- snap_check is defined - snap_check is defined
- snap_check.rc == 0 - snap_check.rc == 0
ignore_errors: true failed_when: false
- name: Install Cursor (Snap, all distros) - name: Install Cursor (Snap, all distros)
community.general.snap: community.general.snap:
name: cursor name: cursor
state: present state: present
when: when:
- ansible_facts['os_family'] == "Debian" - ansible_facts['os_family'] == "Debian"
- snap_check is defined - snap_check is defined
- snap_check.rc == 0 - snap_check.rc == 0
ignore_errors: true failed_when: false
- name: Display snap installation status - name: Display snap installation status
debug: ansible.builtin.debug:
msg: | msg: |
Snap check result: {{ snap_check.rc if snap_check is defined else 'not defined' }} Snap check result: {{ snap_check.rc if snap_check is defined else 'not defined' }}
VSCode and Cursor installation may have failed if snap is not properly configured. VSCode and Cursor installation may have failed if snap is not properly configured.
You may need to manually install these applications or troubleshoot snap on this host. You may need to manually install these applications or troubleshoot snap on this host.
when: when:
- ansible_facts['os_family'] == "Debian" - ansible_facts['os_family'] == "Debian"
- snap_check is defined - snap_check is defined
- snap_check.rc != 0 - snap_check.rc != 0

View File

@ -1,5 +1,5 @@
--- ---
- name: restart ssh - name: Restart ssh
systemd: ansible.builtin.systemd:
name: ssh name: ssh
state: restarted state: restarted

View File

@ -1,7 +1,7 @@
galaxy_info: galaxy_info:
author: your name author: ansible-user
description: your role description description: SSH configuration and security role
company: your company (optional) company: Personal
# If the issue tracker for your role is not on github, uncomment the # If the issue tracker for your role is not on github, uncomment the
# next line and provide a value # next line and provide a value
@ -14,9 +14,9 @@ galaxy_info:
# - GPL-3.0-only # - GPL-3.0-only
# - Apache-2.0 # - Apache-2.0
# - CC-BY-4.0 # - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc) license: MIT
min_ansible_version: 2.1 min_ansible_version: "2.9"
# If this a Container Enabled role, provide the minimum Ansible Container version. # If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version: # min_ansible_container_version:

View File

@ -1,23 +1,22 @@
--- ---
- name: Ensure SSH server installed - name: Ensure SSH server installed
apt: ansible.builtin.apt:
name: openssh-server name: openssh-server
state: present state: present
- name: Configure firewalls - allow SSH port - name: Configure firewalls - allow SSH port
ufw: community.general.ufw:
rule: allow rule: allow
port: '22' port: '22'
proto: tcp proto: tcp
- name: Configure firewalls - allow SSH by name (backup) - name: Configure firewalls - allow SSH by name (backup)
ufw: community.general.ufw:
rule: allow rule: allow
name: OpenSSH name: OpenSSH
ignore_errors: true failed_when: false
- name: Enable UFW with deny default policy - name: Enable UFW with deny default policy
ufw: community.general.ufw:
state: enabled state: enabled
policy: deny policy: deny

View File

@ -1,5 +1,6 @@
--- ---
- hosts: localhost - name: Test ssh role
hosts: localhost
remote_user: root remote_user: root
roles: roles:
- ssh - ssh

View File

@ -1,7 +1,7 @@
galaxy_info: galaxy_info:
author: your name author: ansible-user
description: your role description description: User account management role
company: your company (optional) company: Personal
# If the issue tracker for your role is not on github, uncomment the # If the issue tracker for your role is not on github, uncomment the
# next line and provide a value # next line and provide a value
@ -14,9 +14,9 @@ galaxy_info:
# - GPL-3.0-only # - GPL-3.0-only
# - Apache-2.0 # - Apache-2.0
# - CC-BY-4.0 # - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc) license: MIT
min_ansible_version: 2.1 min_ansible_version: "2.9"
# If this a Container Enabled role, provide the minimum Ansible Container version. # If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version: # min_ansible_container_version:

View File

@ -1,10 +1,10 @@
--- ---
- name: Set target user variable - name: Set target user variable
set_fact: ansible.builtin.set_fact:
target_user: "{{ ansible_user | default(ansible_user_id) }}" user_target_user: "{{ ansible_user | default(ansible_user_id) }}"
- name: Ensure user exists - name: Ensure user exists
user: ansible.builtin.user:
name: "{{ target_user }}" name: "{{ user_target_user }}"
state: present state: present
when: ansible_connection != 'local' when: ansible_connection != 'local'

View File

@ -1,5 +1,6 @@
--- ---
- hosts: localhost - name: Test user role
hosts: localhost
remote_user: root remote_user: root
roles: roles:
- user - user