homeserver/roles/robertdebock.bootstrap/tasks/main.yml

59 lines
1.7 KiB
YAML
Raw Normal View History

2021-02-13 14:20:18 +01:00
---
# tasks file for bootstrap
- name: include assert.yml
import_tasks: assert.yml
run_once: yes
delegate_to: localhost
- name: wait for host
wait_for:
port: "{{ ansible_port | default('22') }}"
host: "{{ (ansible_ssh_host | default(ansible_host) | default(inventory_hostname)) }}"
connection: local
become: no
when:
- ansible_connection is defined
- ansible_connection not in [ "docker", "container" ]
- bootstrap_wait_for_host | bool
- name: prepare system
block:
- name: test connection
wait_for_connection:
timeout: "{{ bootstrap_timeout }}"
register: bootstrap_connect
changed_when: no
rescue:
- name: gather bootstrap facts
include_tasks: "gather_facts.yml"
- name: install bootstrap packages
raw: "{{ bootstrap_install.raw }}"
register: bootstrap_install_packages
changed_when:
- (bootstrap_install.stdout_regex in bootstrap_install_packages.stdout and
bootstrap_os_family in [ "Alpine", "Archlinux", "Gentoo" ]) or
(bootstrap_install.stdout_regex not in bootstrap_install_packages.stdout and
bootstrap_os_family in [ "Debian", "RedHat", "Suse" ])
vars:
ansible_user: "{{ bootstrap_user }}"
always:
- name: set bootstrap_ansible_user
set_fact:
bootstrap_ansible_user: "{{ ansible_user | default(omit) if bootstrap_connect is succeeded else bootstrap_user }}"
changed_when: no
- name: ensure system is prepared
block:
- name: gather ansible facts
setup:
- name: install bootstrap packages
package:
name: "{{ item }}"
state: present
loop: "{{ bootstrap_facts_packages.split() }}"
vars:
ansible_user: "{{ bootstrap_ansible_user | default(omit) }}"