Ansible: Provided hosts list is empty
<p>I have this below playbook where the remote host is an user input and subsequently I am trying to gather facts about the remote host and copy the same to a file in local:</p>

<pre><code>---
- hosts: localhost
  vars_prompt:
      name: hostname
      prompt: "Enter Hostname"
  tasks:
    - name: Add hosts to known_hosts file
      add_host: name={{ hostname }} groups=new
    - name: Check if Host is reachable
      shell: ansible -m ping {{ hostname }}
    - name: Remove existing remote hosts
      shell: ssh-keygen -R {{ hostname }}
    - name: Setup passwordless SSH login
      shell: ssh-copy-id -i ~/.ssh/id_rsa user@{{ hostname }}
    - name: Display facts
      command: ansible {{ groups['new'] }} -m setup
      register: output
    - copy: content="{{ output }}" dest=/var/tmp/dir/Node_Health/temp
...
</code></pre>

<p>I get the below error in the <code>temp</code> file:</p>

<pre><code>Node_Health]# cat temp
{"start": "2016-06-17 09:26:59.174155", "delta": "0:00:00.279268", "cmd": ["ansible", "[udl360x4675]", "-m", "setup"], "end": "2016-06-17 09:26:59.453423", "stderr": " [WARNING]: provided hosts list is empty, only localhost is available", "stdout": "", "stdout_lines": [], "changed": true, "rc": 0, "warnings":
</code></pre>

<p>I also tried the below playbook which also gives the same error:</p>

<pre><code>---
 - hosts: localhost
  vars_prompt:
      name: hostname
      prompt: "Enter Hostname"
  tasks:
    - name: Add hosts to known_hosts file
      add_host: name={{ hostname }} groups=new
    - name: Check if Host is reachable
      shell: ansible -m ping {{ hostname }}
    - name: Remove existing remote hosts
      shell: ssh-keygen -R {{ hostname }}
    - name: Setup passwordless SSH login
      shell: ssh-copy-id -i ~/.ssh/id_rsa user@{{ hostname }}
- hosts: new
   tasks:
    - name: Display facts
      command: ansible {{ groups['new'] }} -m setup
      register: output
    - local_action: copy content="{{ output }}" dest=/var/tmp/dir/Node_Health/temp
...
</code></pre>

<p>Any help will be appreciated.</p>