Skip to content

Commit

Permalink
back to roots.
Browse files Browse the repository at this point in the history
  • Loading branch information
buluma committed Jun 17, 2024
1 parent 1a14b73 commit 296d23d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions tasks/assert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
that:
- bootstrap_wait_for_host is defined
- bootstrap_wait_for_host is boolean
quiet: yes
quiet: true

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

- name: assert | Test bootstrap_become
ansible.builtin.assert:
that:
- bootstrap_become is defined
- bootstrap_become is boolean
quiet: yes
quiet: true
10 changes: 5 additions & 5 deletions tasks/gather_facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

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

- name: gather_facts | Set bootstrap facts (I)
ansible.builtin.set_fact:
Expand All @@ -16,7 +16,7 @@
- bootstrap_facts.rc == 0
- bootstrap_distribution is not defined
- bootstrap_facts.stdout is regex('PRETTY_NAME=.'~ bootstrap_search[item] | default(item) ~'.*')
become: no
become: false

- name: gather_facts | Set bootstrap facts (II)
ansible.builtin.set_fact:
Expand All @@ -26,4 +26,4 @@
label: "{{ item.key }}"
when:
- bootstrap_distribution in item.value
become: no
become: false
14 changes: 8 additions & 6 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
- name: Import assert.yml
ansible.builtin.import_tasks:
file: assert.yml
run_once: yes
run_once: true
delegate_to: localhost

- name: Wait for port to be available
ansible.builtin.wait_for:
port: "{{ ansible_port | default('22') }}"
timeout: "{{ bootstrap_timeout }}"
become: no
become: false
when:
- ansible_connection is defined
- ansible_connection not in [ "container", "docker", "community.docker.docker" ]
Expand All @@ -20,17 +20,18 @@

- name: Prepare system
# At this stage, python and/or sudo are not installed, `become` can't be used.
become: no
# This means this role has to run as root, can't switch user.
become: false
block:
- name: Test connection
ansible.builtin.wait_for_connection:
timeout: "{{ bootstrap_timeout }}"
register: bootstrap_connect
changed_when: no
changed_when: false
- name: Test sudo
ansible.builtin.command:
cmd: sudo --version
changed_when: no
changed_when: false
rescue:
- name: Gather bootstrap facts
ansible.builtin.include_tasks:
Expand All @@ -49,11 +50,12 @@

- name: Gather ansible facts
ansible.builtin.setup:
become: no
become: false

- name: Install bootstrap packages (package)
ansible.builtin.package:
name: "{{ item }}"
state: present
update_cache: true
loop: "{{ bootstrap_facts_packages.split() }}"
become: "{{ bootstrap_become }}"

0 comments on commit 296d23d

Please sign in to comment.