ansible loop through command for multiple hosts

58 views
Skip to first unread message

Hanumantha Reddy Basireddy

unread,
Sep 3, 2021, 2:23:11 PM9/3/21
to Ansible Project
Hi,

---
- hosts: all
  gather_facts: no

  tasks:
    - name: check for server ssh
      wait_for:
        port: 22
        host: "{{ item }}"
        state: started
        search_regex: SSH
        delay: 5
        timeout: 300
      register: ssh_out
      ignore_errors: true
      with_items:
        - 192.168.153.31
         - 192.168.153.32

    - debug: var=ssh_out.results

    - lineinfile:
        line: "{{item.state}}"
        path: /home/bindu/playbooks/salman/log/ssh_log
        create: yes
      loop: "{{ ssh_out.results  }}"

I am seeing error like "'PermissionError' object is not subscriptable".
Reply all
Reply to author
Forward
0 new messages