ansible 2.2.1.0 does not evaluate variable lazily

90 views
Skip to first unread message

Steven Truong

unread,
Feb 23, 2017, 2:39:31 PM2/23/17
to Ansible Project
Hi all,

These are what I am trying:

base-ng.yml:
---
- name: Gathering the local facts from tags
  hosts: all
  gather_facts: yes
  roles:
    - facts

- include: "base_centos{{ ansible_distribution_major_version }}.yml" 
-----

base_centos7.yml:
--- 
  - hosts: all
    gather_facts: no
    roles:
    - { role: common, tags: ["base"] }

-----

ansible-playbook base-ng.yml -i "54.200.xx.xx," --private-key ~/.ssh/dev.pem  -u ec2-user -b -vvvvv
Using /home/steven/ansible/ansible.cfg as config file
statically included: /home/steven/ansible/roles/facts/tasks/pax_tags.yml
ERROR! 'ansible_distribution_major_version' is undefined


Did I do something wrong?  I am confused.

Thanks.

Steven Truong

unread,
Feb 23, 2017, 2:51:03 PM2/23/17
to Ansible Project
And when I did this:

---
- name: Gathering the local facts from tags
  hosts: all
  gather_facts: yes
  roles:
    - facts

- include: base_centos7.yml                                                                                          
  when: ansible_distribution_major_version == '7'

I got  a different error:
ERROR! Invalid role definition: None

Brian Coca

unread,
Feb 23, 2017, 2:54:15 PM2/23/17
to Ansible Project
it does evaluate variables lazily, the problem is that play includes
run at compile time, so the variable is needed before the fact
gathering happens.


----------
Brian Coca

Steven Truong

unread,
Feb 23, 2017, 4:02:48 PM2/23/17
to Ansible Project
Thanks. Brian....

Steven Truong

unread,
Feb 23, 2017, 4:29:39 PM2/23/17
to Ansible Project
I now have this two yml files and ansible-playbook works.  Cross my fingers....

Steven.

---
- name: Gathering the local facts from tags
  hosts: all
  gather_facts: yes
  roles:
    - facts

- include: base_test.yml 

----------------

base-test.yml:
---

- include: base_centos6.yml
  when: ansible_distribution_major_version == '6'

- include: base_centos7.yml
  when: ansible_distribution_major_version == '7'

Reply all
Reply to author
Forward
0 new messages