From d7876c6a652ddfa6ed8b787e95380aa9865c0ecf Mon Sep 17 00:00:00 2001 From: DogeyStamp Date: Fri, 4 Mar 2022 07:30:52 -0500 Subject: [PATCH] Bootstrap Python onto the system --- roles/system/tasks/essential.yml | 1 + run.yml | 1 + tasks/bootstrap.yml | 9 +++++++++ tasks/set_host.yml | 1 + tasks/ssh_port.yml | 34 ++++++++++++++++---------------- 5 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 tasks/bootstrap.yml diff --git a/roles/system/tasks/essential.yml b/roles/system/tasks/essential.yml index 7abe458..97b1cef 100644 --- a/roles/system/tasks/essential.yml +++ b/roles/system/tasks/essential.yml @@ -16,6 +16,7 @@ shell: cmd: "if [[ $(pacman -Q linux | cut -d \" \" -f 2) > $(uname -r) ]]; then echo reboot; fi" register: reboot_check + changed_when: reboot_check.stdout == "reboot" - name: Reboot for kernel update reboot: diff --git a/run.yml b/run.yml index fe6d595..c8cab2d 100644 --- a/run.yml +++ b/run.yml @@ -7,6 +7,7 @@ pre_tasks: - import_tasks: tasks/set_host.yml - import_tasks: tasks/ssh_port.yml + - import_tasks: tasks/bootstrap.yml roles: - role: system diff --git a/tasks/bootstrap.yml b/tasks/bootstrap.yml new file mode 100644 index 0000000..9243a68 --- /dev/null +++ b/tasks/bootstrap.yml @@ -0,0 +1,9 @@ +- name: Check if Python is present + ping: + ignore_errors: true + register: ping + +- name: Bootstrap Python + become: no + raw: "echo root | su -c 'pacman-key --init && pacman-key --populate archlinuxarm && pacman --noconfirm -Syu python' root" + when: ping is failed diff --git a/tasks/set_host.yml b/tasks/set_host.yml index 69991ee..0629a2e 100644 --- a/tasks/set_host.yml +++ b/tasks/set_host.yml @@ -2,6 +2,7 @@ local_action: "command ping -c 1 {{ local_ip }}" become: no ignore_errors: true + changed_when: false register: up_static - name: Switch ansible_host to fallback IP diff --git a/tasks/ssh_port.yml b/tasks/ssh_port.yml index c3abe39..a08ce8c 100644 --- a/tasks/ssh_port.yml +++ b/tasks/ssh_port.yml @@ -1,42 +1,42 @@ -- name: Set default user for SSH +- name: Use default credentials for ssh set_fact: ansible_user: "{{ admin_username }}" - name: Attempt ssh connection become: no - wait_for_connection: - timeout: 10 - ignore_errors: true + raw: "echo Pong!" + ignore_unreachable: true + changed_when: false register: ssh_result_default -- name: Set ssh to fallback port +- name: Use fallback port for ssh set_fact: ansible_ssh_port: 22 when: - - ssh_result_default is failed + - ssh_result_default is unreachable - name: Attempt ssh connection become: no - wait_for_connection: - timeout: 10 - ignore_errors: true + raw: "echo Pong!" + ignore_unreachable: true + changed_when: false register: ssh_result_port when: - - ssh_result_default is failed + - ssh_result_default is unreachable -- name: Set ssh to fallback port and default Arch Linux ARM credentials +- name: Use fallback port and default Arch Linux ARM credentials for ssh set_fact: ansible_ssh_port: "22" ansible_user: "alarm" ansible_ssh_password: "alarm" when: - - ssh_result_default is failed - - ssh_result_port is failed + - ssh_result_default is unreachable + - ssh_result_port is unreachable - name: Attempt ssh connection become: no - wait_for_connection: - timeout: 10 + changed_when: false + raw: "echo Pong!" when: - - ssh_result_default is failed - - ssh_result_port is failed + - ssh_result_default is unreachable + - ssh_result_port is unreachable