Skip to content

Commit

Permalink
Merge pull request #58 from robertdebock/always-root
Browse files Browse the repository at this point in the history
Don't become, not variable user.
  • Loading branch information
robertdebock committed Feb 6, 2022
2 parents 8d7735d + 5dfb173 commit 590f15a
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 39 deletions.
3 changes: 0 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
# defaults file for bootstrap

# The user to use to connect to machines.
bootstrap_user: root

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

Expand Down
4 changes: 0 additions & 4 deletions meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ argument_specs:
This role tries to figure out what to install and uses the raw module to install the packages.
author: Robert de Bock
options:
bootstrap_user:
type: "str"
default: root
description: "The username to use to connect to machines."
bootstrap_wait_for_host:
type: "bool"
default: no
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Converge
hosts: all
become: yes
become: no
gather_facts: no

roles:
Expand Down
7 changes: 0 additions & 7 deletions tasks/assert.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
---

- name: test if bootstrap_user is set correctly
ansible.builtin.assert:
that:
- bootstrap_user is defined
- bootstrap_user is string
quiet: yes

- name: test if bootstrap_wait_for_host is set correctly
ansible.builtin.assert:
that:
Expand Down
4 changes: 1 addition & 3 deletions tasks/gather_facts.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
---

- name: lookup bootstrap facts
become: no
ansible.builtin.raw: "cat /etc/os-release"
become: no
check_mode: no
register: bootstrap_facts
changed_when: no
vars:
ansible_user: "{{ bootstrap_user }}"

- name: set bootstrap facts (I)
ansible.builtin.set_fact:
Expand Down
26 changes: 5 additions & 21 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
run_once: yes
delegate_to: localhost

- name: wait for host
- name: wait for port to be available
ansible.builtin.wait_for:
port: "{{ ansible_port | default('22') }}"
host: "{{ (ansible_ssh_host | default(ansible_host) | default(inventory_hostname)) }}"
connection: local
become: no
timeout: "{{ bootstrap_timeout }}"
# host: "{{ ansible_ssh_host | default(ansible_host) | default(inventory_hostname) }}"
# connection: local
# become: no
when:
- ansible_connection is defined
- ansible_connection not in [ "container", "docker", "community.docker.docker" ]
Expand All @@ -37,21 +38,6 @@
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" ])
vars:
ansible_user: "{{ bootstrap_user }}"
always:
- name: set bootstrap_ansible_user connected
ansible.builtin.set_fact:
bootstrap_ansible_user: "{{ ansible_user }}"
when:
- bootstrap_connect is succeeded
- ansible_user is defined

- name: set bootstrap_ansible_user not connected
ansible.builtin.set_fact:
bootstrap_ansible_user: "{{ bootstrap_user }}"
when:
- bootstrap_connect is failed

- name: ensure system is prepared
block:
Expand All @@ -63,5 +49,3 @@
name: "{{ item }}"
state: present
loop: "{{ bootstrap_facts_packages.split() }}"
vars:
ansible_user: "{{ bootstrap_ansible_user | default(omit) }}"

0 comments on commit 590f15a

Please sign in to comment.