# mitogen and playbook\_name

**URL:** <https://forum.ansible.com/t/mitogen-and-playbook-name/38524>\
**Category:** Ansible Project\
**Created:** [October 17, 2023, 1:58pm UTC](https://forum.ansible.com/t/mitogen-and-playbook-name/38524 "2023-10-17T13:58:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [October 17, 2023, 1:58pm UTC](https://forum.ansible.com/t/mitogen-and-playbook-name/38524/1 "2023-10-17T13:58:10Z")

</div>

In the beginning of the playbook, I calculate the playbook\_name this way:

playbook\_name: “{{ lookup(‘file’, ‘/proc/self/cmdline’) | regex\_replace(‘\u0000’, ’ ').split() | select match(‘match’, ‘\[1\]\*[.]y[a]\*ml’) | list|first|basename }}”

This works in a typical, ssh playbook run. We are now testing mitogen, and using the playbook\_name variable fails with the error:  
“Make sure your variable name does not contain invalid characters like ‘-’: expected str, bytes or os.PathLike object, not AnsibleUndefined”

The ansible-playbook name is configServer.yml so it doesn’t contain any strange characters.

Has anyone else had this problem with mitogen? is there another way to get the playbook name being run?

* * *

1. a-zA-Z-\_/0-9

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [October 17, 2023, 3:08pm UTC](https://forum.ansible.com/t/mitogen-and-playbook-name/38524/2 "2023-10-17T15:08:03Z")

</div>

My initial reaction would be: this looks like a workaround for something that does not exist, probably for a reason. And then you add mitogen to the mix, which is notorious for pushing the limits with many things.

What is the use case for this playbook\_name variable?

---

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [October 17, 2023, 4:13pm UTC](https://forum.ansible.com/t/mitogen-and-playbook-name/38524/3 "2023-10-17T16:13:14Z")

</div>

We use it in many instances to only do something for a specific playbook. We have about 5 playbooks that work on different networks and rather than maintain 5 different playbooks we use the “when playbook\_name == abc.yml” a lot. Is there another way to get the playbook name?

---

<div class="post-metadata">

**Author:** ![Philippe\_Kueck](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@Philippe\_Kueck](https://forum.ansible.com/u/Philippe_Kueck)\
**Post date:** [October 17, 2023, 4:18pm UTC](https://forum.ansible.com/t/mitogen-and-playbook-name/38524/4 "2023-10-17T16:18:04Z")

</div>

Hi,

---

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [October 17, 2023, 5:34pm UTC](https://forum.ansible.com/t/mitogen-and-playbook-name/38524/5 "2023-10-17T17:34:46Z")

</div>

When I print out “{{ ansible\_play\_name }}” I simply get “localhost.”

---

<div class="post-metadata">

**Author:** ![Philippe\_Kueck](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@Philippe\_Kueck](https://forum.ansible.com/u/Philippe_Kueck)\
**Post date:** [October 17, 2023, 5:51pm UTC](https://forum.ansible.com/t/mitogen-and-playbook-name/38524/6 "2023-10-17T17:51:39Z")

</div>

You need to name the playbook:

---

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [October 18, 2023, 8:10pm UTC](https://forum.ansible.com/t/mitogen-and-playbook-name/38524/7 "2023-10-18T20:10:15Z")

</div>

Got it - makes sense now. Thanks!
