On Fri, 31 Jan 2020 20:14:51 -0800 (PST)
Glen Collins <[email protected]> wrote:

> - name: Set facts
>   set_fact:
>        dummy_fact: "Hello world"
>        cacheable: yes
>   delegate_to: fake_host
>   delegate_facts: true
> 
> This sets the fact in the hostname fake_host just fine.
> [...]
> I have tried to target the playbook using host: fake_host but the playbook 
> run tells me the host is invalid or something to that effect.

This *can't* set the fact in the hostname fake_host just fine if the host
in not valid. The play 

  - hosts: all
    tasks:
      - set_fact:
          dummy_fact: "Hello world"
          cacheable: yes
        delegate_to: fake_host
        delegate_facts: true
        run_once: true
      - debug:
          var: hostvars.fake_host.ansible_facts
        run_once: true


should report

    "hostvars.fake_host.ansible_facts": "VARIABLE IS NOT DEFINED!"

> Can someone tell me if this is even possible to do? Possible to target
> directly?

If the host is valid. All works as expected. For example, the playbook
  
  - hosts: all
    tasks:
      - set_fact:
          dummy_fact: "Hello world"
          cacheable: yes
        delegate_to: test_01
        delegate_facts: true
        run_once: true
      - debug:
          var: hostvars.test_01.ansible_facts
        run_once: true

  - hosts: test_01
    tasks:
      - debug:
          var: hostvars.test_01.ansible_facts
      - meta: clear_facts
      - debug:
          var: hostvars.test_01.ansible_facts

gives

  PLAY [all]
  ok: [test_01] => {
    "hostvars.test_01.ansible_facts": {
        "dummy_fact": "Hello world"
    }
  }

  PLAY [test_01]
  ok: [test_01] => {
    "hostvars.test_01.ansible_facts": {
        "dummy_fact": "Hello world"
    }
  }
  ok: [test_01] => {
    "hostvars.test_01.ansible_facts": {}
  }

To make it reproducible test it without tower. HTH,

        -vlado

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200201072943.32bd43d9%40gmail.com.

Attachment: pgpbXo9oaHKBU.pgp
Description: OpenPGP digital signature

Reply via email to