Reputation: 420
Please help me.. I am trying to do this
- name: set anotherplaybook
set_fact:
anotherplaybook: "abc"
when: 'a' in item
- name: set anotherplaybook
set_fact:
anotherplaybook: "xyz"
when: 'x' in item
- import_playbook: "{{ anotherplaybook }}.yml"
this throwing anotherplaybook undefined error
Upvotes: 0
Views: 204
Reputation: 484
I know one thing for sure, is that your variable is not being set. As you didn't post any output to your play, I have to make a couple of assumptions. For starters, the variable 'item' is typically populated with you execute a "with_items" loop as part of your task. Seeing as you are not doing that, are you defining the item variable elsewhere in your playbook? If you are, that's not best practice, and you should probably pick a different variable label, to be more clear about what it is that you are evaluating in that task. Even if you are setting the item variable elsewhere, your when clause on the first two tasks is evaluating to false, so your set_fact task is never getting run, and that is why you are getting the error that you are.
Upvotes: 1