Skip to content

Commit

Permalink
bulk updates
Browse files Browse the repository at this point in the history
  • Loading branch information
buluma committed Oct 30, 2023
1 parent 04b64d2 commit 28b159f
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 51 deletions.
23 changes: 12 additions & 11 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
# Ansible managed
#
exclude_paths:
- ./meta/preferences.yml
- ./molecule/default/prepare.yml
- ./molecule/default/converge.yml
- ./molecule/default/verify.yml
- ./molecule/default/collections.yml
- ./.tox
- ./.cache
- ./.github
- ./requirements.yml
- ./.gitlab-ci.yml
- molecule/default/prepare.yml
- molecule/default/converge.yml
- molecule/default/verify.yml
- molecule/default/collections.yml
- .tox
- .cache
- .github
- requirements.yml

skip_list:
- var-spacing
- yaml[truthy]

enable_list:
- name[prefix]
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
repository:
description: Prepare your system to be managed by Ansible.
homepage: https://buluma.github.io/
topics: bootstrap, python, sudo, ansible, molecule, tox, playbook, hacktoberfest
topics: bootstrap, python, sudo, system, ansible, molecule, tox, playbook
3 changes: 2 additions & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ galaxy_info:
description: Prepare your system to be managed by Ansible.
license: Apache-2.0
company: ShadowNet
min_ansible_version: "2.10"
min_ansible_version: "2.12"

platforms:
- name: Alpine
Expand Down Expand Up @@ -34,5 +34,6 @@ galaxy_info:
- bootstrap
- python
- sudo
- system

dependencies: []
6 changes: 3 additions & 3 deletions tasks/assert.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---

- name: Test if bootstrap_wait_for_host is set correctly
- name: assert | Test bootstrap_wait_for_host
ansible.builtin.assert:
that:
- bootstrap_wait_for_host is defined
- bootstrap_wait_for_host is boolean
quiet: yes

- name: Test if bootstrap_timeout is set correctly
- name: assert | Test bootstrap_timeout
ansible.builtin.assert:
that:
- bootstrap_timeout is defined
- bootstrap_timeout is number
- bootstrap_timeout >= 0
quiet: yes

- name: Test if bootstrap_become is set correctly
- name: assert | Test bootstrap_become
ansible.builtin.assert:
that:
- bootstrap_become is defined
Expand Down
9 changes: 4 additions & 5 deletions tasks/gather_facts.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
---

- name: Lookup bootstrap facts
- name: gather_facts | Lookup bootstrap facts
ansible.builtin.raw: "cat /etc/os-release"
become: no
check_mode: no
register: bootstrap_facts
changed_when: no

- name: Set bootstrap facts (I)
- name: gather_facts | Set bootstrap facts (I)
ansible.builtin.set_fact:
bootstrap_distribution: "{{ item }}"
bootstrap_distribution_major_version: "{{ bootstrap_facts.stdout_lines | join(',') | regex_replace(
'^.*VERSION_ID=\"(\\d{1,2})(\\.\\d{1,4})*?\".*$','\\1') | default('NA') }}"
bootstrap_distribution_major_version: "{{ bootstrap_facts.stdout_lines | join(',') | regex_replace('^.*VERSION_ID=\"(\\d{1,2})(\\.\\d{1,4})*?\".*$', '\\1') | default('NA') }}"
loop: "{{ bootstrap_os_family_map | dict2items | map(attribute='value') | flatten }}"
when:
- bootstrap_facts.rc == 0
- bootstrap_distribution is not defined
- bootstrap_facts.stdout is regex('PRETTY_NAME=.'~ bootstrap_search[item] | default(item) ~'.*')
become: no

- name: Set bootstrap facts (II)
- name: gather_facts | Set bootstrap facts (II)
ansible.builtin.set_fact:
bootstrap_os_family: "{{ item.key }}"
loop: "{{ bootstrap_os_family_map | dict2items }}"
Expand Down
17 changes: 6 additions & 11 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# tasks file for bootstrap

- name: Import assert.yml
ansible.builtin.import_tasks: assert.yml
ansible.builtin.import_tasks:
file: assert.yml
run_once: yes
delegate_to: localhost

Expand All @@ -14,7 +15,8 @@
when:
- ansible_connection is defined
- ansible_connection not in [ "container", "docker", "community.docker.docker" ]
- bootstrap_wait_for_host | bool
- ansible_connection is not none
- bootstrap_wait_for_host

- name: Prepare system
# At this stage, python and/or sudo are not installed, `become` can't be used.
Expand All @@ -36,6 +38,8 @@

- name: Install bootstrap packages (raw)
ansible.builtin.raw: "{{ bootstrap_install.raw }}"
args:
executable: /bin/sh
register: bootstrap_install_packages
changed_when:
- (bootstrap_install.stdout_regex in bootstrap_install_packages.stdout and
Expand All @@ -47,15 +51,6 @@
ansible.builtin.setup:
become: no

- name: SmokeTests
ansible.builtin.debug:
msg:
- "ansible_version => {{ ansible_version }}"
- "ansible_distribution => {{ ansible_distribution }}"
- "ansible_distribution_major_version => {{ ansible_distribution_major_version }}"
- "ansible_os_family => {{ ansible_os_family }}"
- "ansible_system => {{ ansible_system }}"

- name: Install bootstrap packages (package)
ansible.builtin.package:
name: "{{ item }}"
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
#
[tox]
minversion = 4.2.4
envlist = py{311}-ansible{5,6,7}
envlist = py3-ansible{6,7,8}

skipsdist = true

[testenv]
deps =
-rrequirements.txt
ansible5: ansible == 5.*
ansible6: ansible == 6.*
ansible7: ansible == 7.*
ansible8: ansible == 8.*
commands = molecule test
setenv =
TOX_ENVNAME={envname}
Expand Down
24 changes: 7 additions & 17 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ _bootstrap_packages:
Alpine: python3 sudo
Archlinux: python sudo
Debian: python3 sudo gnupg python3-apt
FreeBSD: python sudo
OpenBSD: python3 sudo gnupg
Gentoo: python sudo gentoolkit
RedHat: &redhat_packages python3 sudo
RedHat: python3 sudo
Suse: python3 python3-xml sudo
Amazon: python sudo
CentOS_7: python sudo
Expand All @@ -23,29 +21,23 @@ bootstrap_packages: "{{ _bootstrap_packages[bootstrap_distribution ~'_'~ bootstr

_bootstrap_install:
Alpine:
raw: "LANG=C apk update ; apk add {{ bootstrap_packages }}"
raw: "export LANG=C ; apk update ; apk add {{ bootstrap_packages }}"
stdout_regex: 'Installing'
Archlinux:
raw: "LANG=C pacman -Sy --noconfirm {{ bootstrap_packages }}"
raw: "export LANG=C ; pacman -Sy --noconfirm {{ bootstrap_packages }}"
stdout_regex: ' installing python'
Debian:
raw: "LANG=C apt-get update && apt-get install -y {{ bootstrap_packages }}"
raw: "export LANG=C ; apt-get update && apt-get install -y {{ bootstrap_packages }}"
stdout_regex: ' 0 newly installed'
FreeBSD:
raw: "env LANG=C pkg install -y {{ bootstrap_packages }}"
stdout_regex: 'New packages to be INSTALLED'
OpenBSD:
raw: "env LANG=C pkg_add -U -I -y {{ bootstrap_packages }}"
stdout_regex: 'New packages to be INSTALLED'
Gentoo:
raw: "LANG=C equery l {{ bootstrap_packages }} ||
raw: "export LANG=C ; equery l {{ bootstrap_packages }} ||
(emaint -a sync ; emerge -qkv {{ bootstrap_packages }} ; echo 'changed')"
stdout_regex: 'changed'
RedHat:
raw: "LANG=C yum -y install {{ bootstrap_packages }}"
raw: "export LANG=C ; yum -y install {{ bootstrap_packages }}"
stdout_regex: 'Nothing'
Suse:
raw: "LANG=C zypper -n install {{ bootstrap_packages }}"
raw: "export LANG=C ; zypper -n install {{ bootstrap_packages }}"
stdout_regex: 'Nothing'

# Map the right install command, based on gathered bootstrap facts.
Expand All @@ -61,8 +53,6 @@ bootstrap_os_family_map:
Debian: [Debian, Ubuntu, Raspbian, Neon, KDE neon,
Linux Mint, SteamOS, Devuan, Kali, Cumulus Linux,
'Pop!_OS', Parrot, Pardus GNU/Linux]
FreeBSD: [FreeBSD]
OpenBSD: [OpenBSD]
Gentoo: [Gentoo, Funtoo]
RedHat: [RedHat, Fedora, CentOS, Scientific, SLC,
Ascendos, CloudLinux, PSBM, Rocky, OracleLinux,
Expand Down

0 comments on commit 28b159f

Please sign in to comment.