I noticed
Host "{{ hostvars.localhost.group}}"
Isn't working.
What's the best way to choose host groups on which my playbook should run
dynamically kindly help.
On Jun 17, 2019 8:20 AM, "Ansar Sahit" <[email protected]> wrote:
HI Kai ,
I tried giving if in a single line and still get same error.
- name : set fact variable
set_fact:
group: "{% if c == 1 %}grp1{% elif c == 2 %}grp2{% else %}grp3{%
endif %}"
Same error as mentioned above
On Jun 16, 2019 5:36 PM, "Kai Stian Olstad" <[email protected]>
wrote:
On 16.06.2019 13:21, Ansar Sahit wrote:
> Hi All,
>
> Thankyou for the response, I used Rigler's set_fact to determine the
> hostgroup like below
>
> - name: Set Group
> set_fact:
> group: |
> {% if c == 1 %}
> grp1
> {% elif c ==2 %}
> grp3
> {% else %}
> grp4
> {% endif %}
>
My hunch is that this produce a new line at the end.
You can check with
- debug: var=group
So when using YAML multi line you need to control the newlines.
|- will remove the last newline and {%- will remove any newline produced by
the YAML multiple lines
- name: Set Group
set_fact:
group: |-
{% if c == 1 %}
grp1
{%- elif c ==2 %}
grp3
{%- else %}
grp4
{%- endif %}
Im getting below error.
>
> [WARNING]: **Could not match supplied host pattern, ignoring: grp1**
>
It's probably a newline at the end.
--
Kai Stian Olstad
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/ms
gid/ansible-project/61028d51315a2b48d7a178bc0b79aff7%40olstad.com.
For more options, visit https://groups.google.com/d/optout.
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CABNWynCQFHYOOGOMnmJTBj_9hRETEt1L0ck0v6xNAOCUqJw_0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.