feat: add playbooks for bootstrapping (installing python) and installing system packages (debian)
This commit is contained in:
parent
0771787c98
commit
c9b2f61787
40
playbooks/bootstrap.yml
Normal file
40
playbooks/bootstrap.yml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
- name: Bootstrap everything needed for an ansible connection
|
||||||
|
hosts: "{{ target_hosts | default('all', true) }}"
|
||||||
|
become: "{{ target_host_become | default(true, false) }}"
|
||||||
|
gather_facts: false
|
||||||
|
pre_tasks:
|
||||||
|
- name: Gather information about the target system
|
||||||
|
ansible.builtin.raw: "cat /etc/os-release | grep '^ID=' | cut -d '=' -f2"
|
||||||
|
register: target_host_os_info
|
||||||
|
check_mode: false
|
||||||
|
changed_when: false
|
||||||
|
- name: Set /etc/os-release system id
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
target_host_system_id: "{{ target_host_os_info.stdout_lines | first | trim }}"
|
||||||
|
delegate_to: localhost
|
||||||
|
tasks:
|
||||||
|
- name: Ensure apt bootstrap packages are installed
|
||||||
|
ansible.builtin.raw: "apt install {{ apt_bootstrap_packages | join(' ') }}"
|
||||||
|
register: target_host_apt_info
|
||||||
|
when: target_host_system_id in targets_using_apt
|
||||||
|
changed_when:
|
||||||
|
- "'0 upgraded' not in target_host_apt_info.stdout_lines | last"
|
||||||
|
- "'0 newly installed' not in target_host_apt_info.stdout_lines | last"
|
||||||
|
- name: Sort hosts into os-specific groups
|
||||||
|
ansible.builtin.group_by:
|
||||||
|
key: >-2
|
||||||
|
{{ (os_group_prefix
|
||||||
|
| default(false, true)
|
||||||
|
| ternary(os_group_prefix | default('') + (os_group_seperator | default('_')), ''))
|
||||||
|
+ target_host_system_id }}
|
||||||
|
when: target_hosts_sort_into_system_ids | default(false, true)
|
||||||
|
changed_when: false
|
||||||
|
delegate_to: localhost
|
||||||
|
vars:
|
||||||
|
targets_using_apt:
|
||||||
|
- debian
|
||||||
|
- ubuntu
|
||||||
|
apt_bootstrap_packages:
|
||||||
|
- python3
|
||||||
|
- python3-apt
|
15
playbooks/packages.yml
Normal file
15
playbooks/packages.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
- name: Install system packages on the remote
|
||||||
|
hosts: "{{ target_hosts | default('all', true) }}"
|
||||||
|
become: "{{ target_host_become | default(true, true) }}"
|
||||||
|
gather_facts: "{{ target_host_gather_facts | default(true, true) }}"
|
||||||
|
tasks:
|
||||||
|
- name: Install packages (apt)
|
||||||
|
ansible.builtin.apt:
|
||||||
|
package: "{{ package.name }}"
|
||||||
|
state: "{{ package.state | default('present') }}"
|
||||||
|
loop: "{{ system_packages | default([], true) }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: package
|
||||||
|
label: "{{ package.name }}"
|
||||||
|
when: ansible_facts['pkg_mgr'] == 'apt'
|
Loading…
x
Reference in New Issue
Block a user