summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruvok cheetah2023-10-31 17:09:42 +0100
committeruvok cheetah2023-10-31 17:09:42 +0100
commit81cc20bfa4cadf3515e273faf3996bc889495534 (patch)
tree2e2ed851733e060c3fb10a3fd2cc6dfe3f979c9c
parent2dded296b1bdf4e8deff9d5eae39ca7a1c10720a (diff)
initial_deploy: Get rid of target variable
specify inventory on cmd instead also, include a safety check
-rw-r--r--initial-deploy.yml49
1 files changed, 28 insertions, 21 deletions
diff --git a/initial-deploy.yml b/initial-deploy.yml
index f0a83d1..c0905c7 100644
--- a/initial-deploy.yml
+++ b/initial-deploy.yml
@@ -1,24 +1,31 @@
+---
+# use: specify inventory on command line
- name: Setup Ansible user and authorized keys
+ hosts: all
gather_facts: false
- hosts: "{{ target }}"
tasks:
- - name: Install Python if not already installed
- raw: test -e /usr/bin/python3 || (apt -y update && apt install -y python3-minimal)
- changed_when: false
- failed_when: false
- - name: Install sudo package
- package:
- name: "sudo"
- state: "present"
- - name: setup ansible user
- user:
- name: "ansible"
- groups: "sudo"
- password: "{{ mypass | password_hash('sha512') }}"
- shell: /bin/bash
- - name: Setup Authorized keys
- authorized_key:
- user: "ansible"
- state: present
- key: "{{ lookup('file', '~/.ssh/ansible.pub') }}"
-
+ - name: Check for single host
+ fail:
+ msg: "Single host check failed."
+ when: "play_hosts | length != 1"
+ delegate_to: localhost
+ run_once: true
+ - name: Install Python if not already installed
+ raw: test -e /usr/bin/python3 || (apt -y update && apt install -y python3-minimal)
+ changed_when: false
+ failed_when: false
+ - name: Install sudo package
+ package:
+ name: "sudo"
+ state: "present"
+ - name: Setup ansible user
+ user:
+ name: "ansible"
+ groups: "sudo"
+ password: "{{ mypass | password_hash('sha512') }}"
+ shell: /bin/bash
+ - name: Setup Authorized keys
+ ansible.posix.authorized_key:
+ user: "ansible"
+ state: present
+ key: "{{ lookup('file', '~/.ssh/ansible.pub') }}"