Ansible with registers using loop

Hi,

below is the playbook.i wanna multiple commands in a single task using loop (with_items) and copy the stdout of each loop for every hosts in a file.

Based on what you are looking for this should do it for you.


  • hosts: all
    gather_facts: true
    remote_user: remote
    sudo: true
    tasks:
  • name: capture linux_os
    shell: “{{ item }}”
    register: linux_os
    with_items:
  • ‘uname -a’
  • ‘cat /etc/resolv.conf’
  • name: creating inventory hosts
    file: path=“{{ inventory_hostname }}”.txt state=touch
    delegate_to: localhost
    sudo: false
  • name: results
    lineinfile: dest=“{{ inventory_hostname }}”.txt line=“{{ item.stdout }}”
    delegate_to: localhost
    sudo: false
    with_items: linux_os.results

resulting in.