facts: get platform info from NetBox
Instead of pinging each host to see if it’s Windows. Make sure to set the platform at least for such hosts.
This commit is contained in:
parent
7cbbf635a8
commit
d162f175a4
3 changed files with 14 additions and 21 deletions
|
@ -1,21 +1,21 @@
|
|||
# Read secrets and keys.
|
||||
- name: Get SSH keys
|
||||
- name: Get public SSH keys for root login
|
||||
delegate_to: localhost
|
||||
check_mode: false
|
||||
run_once: true
|
||||
block:
|
||||
- name: Get GPG key IDs
|
||||
- name: Read GPG key IDs from secret store
|
||||
shell: cat ${PASSWORD_STORE_DIR:-~/.password-store}/.gpg-id
|
||||
changed_when: false
|
||||
register: gpg_ids
|
||||
|
||||
- name: Export public SSH keys
|
||||
- name: Retrieve public SSH keys from GPG keyring
|
||||
shell: echo "$(gpg --export-ssh-key {{ item }} | cut -d ' ' -f 1,2) $(gpg --list-keys --with-colons {{ item }} | sed -n 's@uid:.*<\(.*\)>.*@\1@p')"
|
||||
loop: '{{ gpg_ids.stdout_lines }}'
|
||||
changed_when: false
|
||||
register: ssh_export
|
||||
|
||||
- name: Set SSH keys to deploy on servers
|
||||
- name: Store a list of SSH keys
|
||||
set_fact:
|
||||
ssh_keys: '{{ ssh_export.results | map(attribute="stdout") }}'
|
||||
failed_when: not ssh_keys # something must be terribly wrong so let’s not lock everyone out
|
||||
|
@ -52,23 +52,13 @@
|
|||
|
||||
# Set host-specific connection parameters.
|
||||
- name: Set SSH connection username
|
||||
delegate_to: localhost
|
||||
set_fact:
|
||||
ansible_ssh_user: "{{ password.user }}"
|
||||
when: password.user is defined
|
||||
|
||||
- name: Check if the host is running Windows
|
||||
win_ping:
|
||||
vars:
|
||||
ansible_shell_type: powershell
|
||||
failed_when: false
|
||||
ignore_errors: true
|
||||
ignore_unreachable: true
|
||||
register: result
|
||||
|
||||
- name: Set connection parameters for Windows
|
||||
set_fact:
|
||||
ansible_shell_type: powershell
|
||||
ansible_become_method: runas
|
||||
ansible_become_flags: ""
|
||||
when: result.ping|default("") == "pong"
|
||||
when: platform == "windows"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue