# How to pass 'hosts' value to an included/imiported playbook?

**URL:** <https://forum.ansible.com/t/how-to-pass-hosts-value-to-an-included-imiported-playbook/32964>\
**Category:** Ansible Developer\
**Created:** [May 18, 2020, 6:48pm UTC](https://forum.ansible.com/t/how-to-pass-hosts-value-to-an-included-imiported-playbook/32964 "2020-05-18T18:48:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Bi](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@Peter\_Bi](https://forum.ansible.com/u/Peter_Bi)\
**Post date:** [May 18, 2020, 6:48pm UTC](https://forum.ansible.com/t/how-to-pass-hosts-value-to-an-included-imiported-playbook/32964/1 "2020-05-18T18:48:28Z")

</div>

I’ve playbook A to include roles to conduct an operation. Now I want to create playbook B to import/include playbook A but want to pass ‘hosts’ value to A. In other words, I want to make A to work dynamically with different hosts depending on the playbooks (B/C/D/E/etc.) that include/import it.

I’ve searched around and couldn’t find a good way to do it, I’m running Ansible 2.7.10

I tried in Playbook B like [-import\_playbook playbook-A.yml my-host=‘host\_B\_name’] (in playbook A [hosts: {{‘my-host’}}]), but got error: Invalid variable name in vars specified for PlaybookInclude: ‘my-host’ is not a valid variable name

Any help or idea here?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Richard\_Megginson](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/richard_megginson/32/4540_2.png) [@Richard\_Megginson](https://forum.ansible.com/u/Richard_Megginson)\
**Post date:** [May 18, 2020, 7:01pm UTC](https://forum.ansible.com/t/how-to-pass-hosts-value-to-an-included-imiported-playbook/32964/2 "2020-05-18T19:01:46Z")

</div>

> I've playbook A to include roles to conduct an operation. Now I want to create playbook B to import/include playbook A but want to pass 'hosts' value to A. In other words, I want to make A to work dynamically with different hosts depending on the playbooks (B/C/D/E/etc.) that include/import it.
> 
> I've searched around and couldn't find a good way to do it, I'm running Ansible 2.7.10
> 
> I tried in Playbook B like [-import\_playbook playbook-A.yml my-host='host\_B\_name'] (in playbook A [hosts: {{'my-host'}}]), but got error: Invalid variable name in vars specified for PlaybookInclude: 'my-host' is not a valid variable name

[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_variables.html#creating-valid-variable-names](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#creating-valid-variable-names)
