set_fact

50 views
Skip to first unread message

coach rhca

unread,
Sep 30, 2018, 1:46:12 PM9/30/18
to Ansible Project
Hi,

I am trying to create a role in which i have variable file ( main.yml) under vars folder containing

---
 group1:
    cid: t1234
    env: uat
    status: active


and in the tasks (main.yml ) i have
---
- name: setting values
  set_fact:
    cid: "{{item.cid}}"
    env : "{{item.env}}"
  with_items: "{{ group1}}"

  ****other lines*********

but when i run the ansible-playbook --syntax-check for task file i get the error
 #ansible-playbook -syntax-check tasks/main.yml

ERROR! 'with_items' is not a valid attribute for a Play
The offending line appears to be:

---
- name: setting values
  ^ here



Could you please let know where we are going wrong ,also if we can use set_fact with with_items or with_dict.






Kai Stian Olstad

unread,
Sep 30, 2018, 1:59:55 PM9/30/18
to ansible...@googlegroups.com
On Sunday, 30 September 2018 19.46.12 CEST coach rhca wrote:
> I am trying to create a role in which i have variable file ( main.yml)
> under vars folder containing
>
> ---
> group1:
> cid: t1234
> env: uat
> status: active
>
>
> and in the tasks (main.yml ) i have
> ---
> - name: setting values
> set_fact:
> cid: "{{item.cid}}"
> env : "{{item.env}}"
> with_items: "{{ group1}}"
>
> ****other lines*********
>
> but when i run the ansible-playbook --syntax-check for task file i get the
> error
> #ansible-playbook -syntax-check tasks/main.yml
>
> *ERROR! 'with_items' is not a valid attribute for a Play*

ansible-playbook --syntax-check can only check syntax on playbooks, not task files.

If you have a playbook that include the role it will check the syntax on the role.


--
Kai Stian Olstad


Kuldip Madnani

unread,
Oct 1, 2018, 12:12:18 AM10/1/18
to Ansible Project
with_items accepts a list. I don't understand the purpose of using with_items here. You can directly set  cid as {{ group1.cid }} and env as {{ group1.env }}

coach rhca

unread,
Oct 2, 2018, 12:26:54 AM10/2/18
to ansible...@googlegroups.com
thank you guys..

--
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/xPEiOwXLLks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/39446127.Q3cXPdm5SL%40x1.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages