Ansible Sandbox

From UVOO Tech Wiki
Jump to navigation Jump to search
- 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}}"