mitogen and playbook_name

34 views
Skip to first unread message

Kathy L

unread,
Oct 17, 2023, 9:58:11 AM10/17/23
to Ansible Project
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', '^[a-zA-Z-_/0-9]*[.]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?

Dick Visser

unread,
Oct 17, 2023, 11:08:33 AM10/17/23
to ansible...@googlegroups.com
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?



Sent from Gmail Mobile


--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/41feabb8-15f9-461b-be84-08a899a5b010n%40googlegroups.com.

Kathy Lyons

unread,
Oct 17, 2023, 12:13:37 PM10/17/23
to ansible...@googlegroups.com
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?

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/UcCnrJRs4iY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAF8BbLaOnMnU70b-x-TFH6XTtA33qLZfVkCHbhQ%2BGWET3NwsSg%40mail.gmail.com.

Philippe Kueck

unread,
Oct 17, 2023, 12:18:20 PM10/17/23
to ansible...@googlegroups.com
Hi,

On 17.10.23 18:13, Kathy Lyons wrote:
> 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?

How about this?

---
- name: "foobar playbook"
hosts: localhost
gather_facts: no
tasks:
- debug:
msg: '{{ansible_play_name}}'
...

- Philippe

Kathy Lyons

unread,
Oct 17, 2023, 1:35:09 PM10/17/23
to ansible...@googlegroups.com
When I print out "{{ ansible_play_name }}" I simply get "localhost."

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/UcCnrJRs4iY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

Philippe Kueck

unread,
Oct 17, 2023, 1:52:00 PM10/17/23
to ansible...@googlegroups.com
You need to name the playbook:

---
- name: "your playbook name goes here"
hosts: yourhostlist
tasks:
- debug:
msg: >
{{ansible_play_name}} should print
"your playbook name goes here"
...

On 17.10.23 19:34, Kathy Lyons wrote:
> When I print out "{{ ansible_play_name }}" I simply get "localhost."
>
> On Tue, Oct 17, 2023 at 12:18 PM 'Philippe Kueck' via Ansible Project
> <ansible...@googlegroups.com
> <mailto:ansible...@googlegroups.com>> wrote:
>
> Hi,
>
> On 17.10.23 18:13, Kathy Lyons wrote:
> > 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?
>
> How about this?
>
> ---
> - name: "foobar playbook"
>    hosts: localhost
>    gather_facts: no
>    tasks:
>      - debug:
>          msg: '{{ansible_play_name}}'
> ...
>
> - Philippe
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/UcCnrJRs4iY/unsubscribe <https://groups.google.com/d/topic/ansible-project/UcCnrJRs4iY/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to
> ansible-proje...@googlegroups.com
> <mailto:ansible-project%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/674aaf12-2177-46eb-a995-1dbe04113fd4%40quarantine.de <https://groups.google.com/d/msgid/ansible-project/674aaf12-2177-46eb-a995-1dbe04113fd4%40quarantine.de>.
>
> --
> 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 ansible-proje...@googlegroups.com
> <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAK9%2BsMc9TdqUcWtvOFNv9Uw6p5Upcgx3qGZ5cqbT8Y%3DQnSksiA%40mail.gmail.com <https://groups.google.com/d/msgid/ansible-project/CAK9%2BsMc9TdqUcWtvOFNv9Uw6p5Upcgx3qGZ5cqbT8Y%3DQnSksiA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Kathy Lyons

unread,
Oct 18, 2023, 4:07:49 PM10/18/23
to 'Philippe Kueck' via Ansible Project
Got it - makes sense now.  Thanks!
Reply all
Reply to author
Forward
0 new messages