PowerCLI

 View Only

Fetching IP address of remote Host and add to inventory File

  • 1.  Fetching IP address of remote Host and add to inventory File

    Posted Aug 21, 2020 08:13 AM

    Hi everyone,

    can anyone know how to fetch the IP-address of a remote host and add to the inventory file?

    #insert hostname  into inventory

      - name: add to ansible hosts file

        lineinfile:

          dest: /etc/ansible/inventory

          insertbefore: 'product'

          line: '{{item.vmname }}   {{item.variable}}={{item.ansible_host}}'

          state: present

        with_items:

          - {vmname: '{{vmname}}', variable: "ansible_host", ansible_host: " {{ansible_default_ipv4.address}} "}

        run_once: true

        delegate_to: localhost

    this play works perfect but it writes the IP-address of ansible host into inventory file not the IP-address of remote-host (vmname).