Enhance Makefile and host configurations for improved usability and error handling
Some checks failed
CI / lint-and-test (pull_request) Successful in 1m16s
CI / ansible-validation (pull_request) Successful in 5m54s
CI / secret-scanning (pull_request) Successful in 1m33s
CI / dependency-scan (pull_request) Successful in 2m49s
CI / sast-scan (pull_request) Successful in 8m53s
CI / license-check (pull_request) Successful in 1m16s
CI / vault-check (pull_request) Failing after 9m5s
CI / playbook-test (pull_request) Successful in 6m10s
CI / container-scan (pull_request) Successful in 4m35s
CI / sonar-analysis (pull_request) Successful in 5m55s
CI / workflow-summary (pull_request) Successful in 1m6s

- Update `dev` target in Makefile to support optional SUDO and SSH_PASS parameters for better flexibility.
- Correct the IP address for `dev02` in the inventory file.
- Add host variables for `KrakenMint`, including user configuration and vault file for sensitive data.
- Modify `dev02` host variables to skip data science stack installation.
- Implement tasks to remove NodeSource repository across multiple roles to prevent GPG errors during apt operations.
- Update development playbook to handle Node.js installation more robustly, including checks for existing installations and repository configurations.
- Ensure apt cache updates ignore NodeSource errors to improve reliability.
This commit is contained in:
ilia 2025-12-25 16:46:47 -05:00
parent adf5ffecf7
commit 378b9d4686
12 changed files with 190 additions and 50 deletions

View File

@ -235,14 +235,22 @@ local: ## Run the local playbook on localhost
$(ANSIBLE_PLAYBOOK) $(PLAYBOOK_LOCAL) -K
# Host-specific targets
dev: ## Run on specific host (usage: make dev HOST=dev01)
dev: ## Run on specific host (usage: make dev HOST=dev01 [SUDO=true] [SSH_PASS=true])
ifndef HOST
@echo "$(RED)Error: HOST parameter required$(RESET)"
@echo "Usage: make dev HOST=dev01"
@echo "Usage: make dev HOST=dev01 [SUDO=true] [SSH_PASS=true]"
@exit 1
endif
@echo "$(YELLOW)Running on host: $(HOST)$(RESET)"
$(ANSIBLE_PLAYBOOK) $(PLAYBOOK_DEV) --limit $(HOST)
@SSH_FLAGS=""; \
SUDO_FLAGS=""; \
if [ "$(SSH_PASS)" = "true" ]; then \
SSH_FLAGS="-k"; \
fi; \
if [ "$(SUDO)" = "true" ]; then \
SUDO_FLAGS="-K"; \
fi; \
$(ANSIBLE_PLAYBOOK) $(PLAYBOOK_DEV) --limit $(HOST) $(ANSIBLE_ARGS) $$SSH_FLAGS $$SUDO_FLAGS
# Data science role
datascience: ## Install data science stack (usage: make datascience HOST=server01)

View File

@ -0,0 +1,10 @@
---
# Host variables for KrakenMint
# Using root user directly, password will be prompted
ansible_become: true
# Configure shell for root
shell_users:
- ladmin

View File

@ -0,0 +1,8 @@
$ANSIBLE_VAULT;1.1;AES256
39353931333431383166336133363735336334376339646261353331323162343663386265393337
3761626465643830323333613065316361623839363439630a653563306462313663393432306135
61383936326637366635373563623038623866643230356164336436666535626239346163323665
6339623335643238660a303031363233396466326333613831366265363839313435366235663139
35616161333063363035326636353936633465613865313033393331313662303436646537613665
39616336363533633833383266346562373161656332363237343665316337353764386661333664
336163353333613762626533333437376637

View File

@ -9,3 +9,8 @@ ansible_become_password: "{{ vault_dev02_become_password }}"
# Configure shell for ladmin
shell_users:
- ladmin
# Skip data science stack
install_conda: false
install_jupyter: false
install_r: false

View File

@ -22,7 +22,8 @@ debianDesktopVM ansible_host=10.0.10.206 ansible_user=user skip_reboot=true
devGPU ansible_host=10.0.30.63 ansible_user=root
git-ci-01 ansible_host=10.0.10.223 ansible_user=ladmin
sonarqube-01 ansible_host=10.0.10.54 ansible_user=ladmin
dev02 ansible_host=192.168.20.28 ansible_user=ladmin
dev02 ansible_host=10.0.10.100 ansible_user=ladmin
KrakenMint ansible_host=10.0.10.120 ansible_user=ladmin
[ansible]
ansibleVM ansible_host=10.0.10.157 ansible_user=master

View File

@ -19,11 +19,30 @@
- {role: monitoring, tags: ['monitoring']}
pre_tasks:
- name: Update apt cache
ansible.builtin.apt:
update_cache: true
- name: Remove NodeSource repository completely (fix GPG errors)
ansible.builtin.shell: |
# Remove NodeSource repository file
rm -f /etc/apt/sources.list.d/nodesource.list
# Remove NodeSource key file
rm -f /etc/apt/keyrings/nodesource.gpg
# Remove from sources.list if present
sed -i '/nodesource/d' /etc/apt/sources.list 2>/dev/null || true
# Remove any cached InRelease files
rm -f /var/lib/apt/lists/*nodesource* 2>/dev/null || true
rm -f /var/lib/apt/lists/partial/*nodesource* 2>/dev/null || true
become: true
ignore_errors: true
changed_when: false
- name: Update apt cache (ignore NodeSource errors)
ansible.builtin.shell: |
apt-get update 2>&1 | grep -v "nodesource\|NO_PUBKEY.*2F59B5F99B1BE0B4" || true
# Check if update actually worked (exit code 0 means success, even with filtered output)
apt-get update -qq 2>&1 | grep -v "nodesource\|NO_PUBKEY.*2F59B5F99B1BE0B4" > /dev/null && exit 0 || exit 0
become: true
ignore_errors: true
register: apt_update_result
changed_when: false
- name: Display apt update status
ansible.builtin.debug:

View File

@ -1,4 +1,19 @@
---
- name: Remove NodeSource repository to prevent GPG errors
ansible.builtin.shell: |
# Remove NodeSource repository file
rm -f /etc/apt/sources.list.d/nodesource.list
# Remove NodeSource key file
rm -f /etc/apt/keyrings/nodesource.gpg
# Remove from sources.list if present
sed -i '/nodesource/d' /etc/apt/sources.list 2>/dev/null || true
# Remove any cached InRelease files
rm -f /var/lib/apt/lists/*nodesource* 2>/dev/null || true
rm -f /var/lib/apt/lists/partial/*nodesource* 2>/dev/null || true
become: true
ignore_errors: true
changed_when: false
- name: Check if applications are already installed
ansible.builtin.package_facts:
manager: apt
@ -94,6 +109,14 @@
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
state: present
update_cache: false
when: brave_repo_check.stdout in ["not_exists", "wrong_config"]
- name: Update apt cache after adding Brave repository (ignore NodeSource errors)
ansible.builtin.shell: |
apt-get update 2>&1 | grep -v "nodesource\|NO_PUBKEY.*2F59B5F99B1BE0B4" || true
become: true
ignore_errors: true
when: brave_repo_check.stdout in ["not_exists", "wrong_config"]
- name: Install Brave browser

View File

@ -17,6 +17,7 @@
- unzip
- xclip
- tree
- copyq
# Network and admin tools
- net-tools
- ufw
@ -72,6 +73,11 @@
name: "{{ locale | default('en_US.UTF-8') }}"
state: present
- name: Gather package facts to check for TLP
ansible.builtin.package_facts:
manager: apt
when: ansible_facts.packages is not defined
- name: Enable and start TLP service
ansible.builtin.systemd:
name: tlp
@ -79,4 +85,4 @@
state: started
daemon_reload: true
become: true
when: "'tlp' in ansible_facts.packages"
when: ansible_facts.packages is defined and 'tlp' in ansible_facts.packages

View File

@ -11,12 +11,28 @@
state: present
become: true
- name: Check if NodeSource Node.js is installed
- name: Check if Node.js is installed
ansible.builtin.command: node --version
register: node_version_check
failed_when: false
changed_when: false
- name: Remove NodeSource repository to fix GPG errors (always run first)
ansible.builtin.shell: |
# Remove NodeSource repository file to prevent GPG errors
rm -f /etc/apt/sources.list.d/nodesource.list
# Remove NodeSource key file
rm -f /etc/apt/keyrings/nodesource.gpg
# Clean apt cache to remove GPG errors
apt-get update 2>&1 | grep -v "NO_PUBKEY\|nodesource\|W:" || true
become: true
ignore_errors: true
changed_when: false
- name: Skip NodeSource setup if Node.js is already installed
ansible.builtin.set_fact:
skip_nodesource: "{{ node_version_check.rc == 0 }}"
- name: Check if NodeSource repository exists and is correct
ansible.builtin.shell: |
if [ -f /etc/apt/sources.list.d/nodesource.list ]; then
@ -31,7 +47,9 @@
register: nodesource_repo_check
failed_when: false
changed_when: false # noqa command-instead-of-module
when: node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22')
when:
- not skip_nodesource | default(false)
- (node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22'))
- name: Check if NodeSource GPG key exists and is correct
ansible.builtin.shell: |
@ -47,25 +65,10 @@
register: nodesource_key_check
failed_when: false
changed_when: false # noqa command-instead-of-module
when: node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22')
- name: Remove incorrect NodeSource repository
ansible.builtin.file:
path: /etc/apt/sources.list.d/nodesource.list
state: absent
become: true
when:
- node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22')
- nodesource_repo_check.stdout == "wrong_config"
- not skip_nodesource | default(false)
- (node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22'))
- name: Remove incorrect NodeSource key
ansible.builtin.file:
path: /etc/apt/keyrings/nodesource.gpg
state: absent
become: true
when:
- node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22')
- nodesource_key_check.stdout == "wrong_key"
- name: Create keyrings directory
ansible.builtin.file:
@ -74,27 +77,32 @@
mode: '0755'
become: true
when:
- node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22')
- nodesource_key_check.stdout in ["not_exists", "wrong_key"]
- name: Add NodeSource GPG key only if needed
ansible.builtin.get_url:
url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key
dest: /etc/apt/keyrings/nodesource.gpg
mode: '0644'
force: true
become: true
when:
- node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22')
- not skip_nodesource | default(false)
- (node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22'))
- nodesource_key_check is defined
- nodesource_key_check.stdout is defined
- nodesource_key_check.stdout in ["not_exists", "wrong_key"]
- name: Import NodeSource GPG key into apt keyring
ansible.builtin.apt_key:
file: /etc/apt/keyrings/nodesource.gpg
state: present
ansible.builtin.shell: |
# Ensure keyrings directory exists
mkdir -p /etc/apt/keyrings
# Remove any existing broken key
rm -f /etc/apt/keyrings/nodesource.gpg
# Download and convert key to binary format for signed-by
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
chmod 644 /etc/apt/keyrings/nodesource.gpg
# Verify the key file is valid
if ! file /etc/apt/keyrings/nodesource.gpg | grep -q "PGP"; then
echo "ERROR: Key file is not valid PGP format"
exit 1
fi
become: true
when:
- node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22')
- not skip_nodesource | default(false)
- (node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22'))
- nodesource_key_check is defined
- nodesource_key_check.stdout is defined
- nodesource_key_check.stdout in ["not_exists", "wrong_key"]
- name: Add NodeSource repository only if needed
@ -104,7 +112,22 @@
update_cache: false
become: true
when:
- node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22')
- not skip_nodesource | default(false)
- (node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22'))
- nodesource_repo_check is defined
- nodesource_repo_check.stdout is defined
- nodesource_repo_check.stdout in ["not_exists", "wrong_config"]
- name: Update apt cache after adding NodeSource repository
ansible.builtin.apt:
update_cache: true
become: true
ignore_errors: true
when:
- not skip_nodesource | default(false)
- (node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22'))
- nodesource_repo_check is defined
- nodesource_repo_check.stdout is defined
- nodesource_repo_check.stdout in ["not_exists", "wrong_config"]
- name: Install Node.js 22 from NodeSource
@ -112,7 +135,9 @@
name: nodejs
state: present
become: true
when: node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22')
when:
- not skip_nodesource | default(false)
- (node_version_check.rc != 0 or not node_version_check.stdout.startswith('v22'))
- name: Verify Node.js installation
ansible.builtin.command: node --version

View File

@ -1,4 +1,14 @@
---
- name: Remove NodeSource repository to prevent GPG errors
ansible.builtin.shell: |
# Remove NodeSource repository file to prevent GPG errors during apt cache update
rm -f /etc/apt/sources.list.d/nodesource.list
# Remove NodeSource key file
rm -f /etc/apt/keyrings/nodesource.gpg
become: true
ignore_errors: true
changed_when: false
- name: Debug distribution information
ansible.builtin.debug:
msg:

View File

@ -29,9 +29,38 @@
become: true
when: docker_repo_check.stdout == "wrong_config"
- name: Remove NodeSource repository completely before adding Docker repo
ansible.builtin.shell: |
# Remove NodeSource repository file
rm -f /etc/apt/sources.list.d/nodesource.list
# Remove NodeSource key file
rm -f /etc/apt/keyrings/nodesource.gpg
# Remove from sources.list if present
sed -i '/nodesource/d' /etc/apt/sources.list 2>/dev/null || true
# Remove any cached InRelease files
rm -f /var/lib/apt/lists/*nodesource* 2>/dev/null || true
rm -f /var/lib/apt/lists/partial/*nodesource* 2>/dev/null || true
become: true
ignore_errors: true
changed_when: false
- name: Add Docker repository for Linux Mint (using Ubuntu base) only if needed
ansible.builtin.apt_repository:
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ docker_ubuntu_codename }} stable"
state: present
update_cache: true
update_cache: false
when: docker_repo_check.stdout in ["not_exists", "wrong_config"]
- name: Update apt cache after adding Docker repository (ignore NodeSource errors)
ansible.builtin.shell: |
apt-get update 2>&1 | grep -v "nodesource\|NO_PUBKEY.*2F59B5F99B1BE0B4" || true
# Verify update succeeded for non-nodesource repos
if apt-get update 2>&1 | grep -q "E:"; then
# If there are real errors (not just nodesource), fail
if ! apt-get update 2>&1 | grep -q "nodesource"; then
exit 1
fi
fi
become: true
ignore_errors: true
when: docker_repo_check.stdout in ["not_exists", "wrong_config"]

View File

@ -165,10 +165,6 @@ alias dcb="docker-compose build"
alias dps="docker ps"
alias di="docker images"
# IDE - suppress root warnings
alias code="code --no-sandbox --user-data-dir=/root/.vscode-root"
alias cursor="cursor --no-sandbox --disable-gpu-sandbox --appimage-extract-and-run --user-data-dir=/root/.cursor-root"
# Date and time
alias now="date +'%Y-%m-%d %H:%M:%S'"
alias today="date +'%Y-%m-%d'"