Difference between revisions of "Ansible Sandbox"

From UVOO Tech Wiki
Jump to navigation Jump to search
(Created page with "``` - name: Playbook header to try multiple logins hosts: all gather_facts: no vars: usernames: - idjs - joe.smith - jsmith - foo password: somep...")
 
(No difference)

Latest revision as of 16:46, 16 November 2021

- name: Playbook header to try multiple logins
  hosts: all
  gather_facts: no
  vars:
    usernames:
    - idjs
    - joe.smith
    - jsmith
    - foo
    password: somepassword

  tasks:

  - name: Check if connection is possible
    shell: |
      SSHPASS='{{password}}' sshpass -e ssh -o User={{ item }} -o ConnectTimeout=10 -o PubkeyAuthentication=no {{ ansible_host }} /bin/true
    register: result
    connection: local
    ignore_errors: yes
    changed_when: False
    with_items: "{{usernames}}"

  # - debug:
  #     var: result

  - debug:
      msg: "{{ (result.results | rejectattr('failed', 'equalto', true)|first).item}}"