Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #59 #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ This example is taken from `molecule/default/converge.yml` and is tested on each
---
- name: Converge
hosts: all
# This role installs packages using the `raw` module and needs to connect as
# `root`. (`sudo` is not available before bootstrapping.) All tasks in the
# role have `become` set to `no`, so you can use either `no` or `yes` for
# `become`, the role will not use become (so `sudo`) for any task.
# This role installs packages using the `raw` module and connects as
# `root` per default. (`sudo` is sometimes not available before bootstrapping.)
# All relevant tasks in the role have `become` set per default to `no`, so you can
# use either `no` or `yes` for `become`, the role will not use become (so `sudo`) for # any relevant task. Use `bootstrap_not_as_root` to override that behaviour.
become: yes # `no` will also work.
# This role installs python, gathering facts can't be done before `python` is
# installed. This role runs the `setup` module, so facts will be available
Expand All @@ -25,6 +25,7 @@ This example is taken from `molecule/default/converge.yml` and is tested on each

roles:
- role: robertdebock.bootstrap
# bootstrap_not_as_root: True
```

Also see a [full explanation and example](https://robertdebock.nl/how-to-use-these-roles.html) on how to use these roles.
Expand All @@ -36,6 +37,9 @@ The default values for the variables are set in `defaults/main.yml`:
---
# defaults file for bootstrap

# Allow to bootstrap as non root ( e.g. vagrant user )
bootstrap_not_as_root: no

# Do you want to wait for the host to be available?
bootstrap_wait_for_host: no

Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
# defaults file for bootstrap

# Allow to bootstrap as non root ( e.g. vagrant user )
bootstrap_not_as_root: no

# Do you want to wait for the host to be available?
bootstrap_wait_for_host: no

Expand Down
3 changes: 0 additions & 3 deletions tasks/gather_facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

- name: lookup bootstrap facts
ansible.builtin.raw: "cat /etc/os-release"
become: no
check_mode: no
register: bootstrap_facts
changed_when: no
Expand All @@ -17,7 +16,6 @@
- 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)
ansible.builtin.set_fact:
Expand All @@ -27,4 +25,3 @@
label: "{{ item.key }}"
when:
- bootstrap_distribution in item.value
become: no
6 changes: 3 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ansible.builtin.wait_for:
port: "{{ ansible_port | default('22') }}"
timeout: "{{ bootstrap_timeout }}"
become: no
become: "{{ bootstrap_not_as_root | default(False) | bool }}"
when:
- ansible_connection is defined
- ansible_connection not in [ "container", "docker", "community.docker.docker" ]
Expand All @@ -36,7 +36,7 @@
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", "Rocky", "Suse" ])
become: no
become: "{{ bootstrap_not_as_root | default(False) | bool }}"


- name: ensure system is prepared
Expand All @@ -49,4 +49,4 @@
name: "{{ item }}"
state: present
loop: "{{ bootstrap_facts_packages.split() }}"
become: no
become: "{{ bootstrap_not_as_root | default(False) | bool }}"