# Callin variables from vars\_file

**URL:** <https://forum.ansible.com/t/callin-variables-from-vars-file/38618>\
**Category:** Ansible Project\
**Created:** [December 7, 2023, 2:29pm UTC](https://forum.ansible.com/t/callin-variables-from-vars-file/38618 "2023-12-07T14:29:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimitri\_Yioulos](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@Dimitri\_Yioulos](https://forum.ansible.com/u/Dimitri_Yioulos)\
**Post date:** [December 7, 2023, 2:29pm UTC](https://forum.ansible.com/t/callin-variables-from-vars-file/38618/1 "2023-12-07T14:29:27Z")

</div>

Good day all!

I’ve created a playbook to do some DNS work. There are basically two plays - one changes the zone’s serial number, and the other adds TXT records. I get the zone files from a variables file in var\_files (zones.yml). The first play works fine.

As to the second play, I’ve created another variables file that includes the TXT records, but I’m not quite sure how to set it up. Here are the two variables files:

zones -  
zone\_files:

- /var/named/chroot/var/named/trioboiler.com.hosts
- /var/named/chroot/var/named/trioboiler2.com.hosts

certs -  
certs:  
/var/named/chroot/var/named/trioboiler.com.hosts:

- ‘\_some-string TXT “aZCCCChonRJiOCL1ZtkKMKnx7U2k3wbSswyClGb6wGk”’
- ‘\_some-string TXT “aZDDDDhonRJiOCL1ZtkKMKnx7U2k3wbSswyClGb6wGk”’  
/var/named/chroot/var/named/trioboiler2.com.hosts:
- ‘\_some-string TXT “aZYYYYhonRJiOCL1ZtkKMKnx7U2k3wbSswyClGb6wGk”’
- ‘\_some-string TXT “aZZZZhonRJiOCL1ZtkKMKnx7U2k3wbSswyClGb6wGk”’

Here’s are the plays that I want to use the certs variable file in:

- name: Add TXT entry 1 to zone file  
lineinfile:  
dest: “{{ item }}”  
insertafter: EOF  
line: ‘\_acme-challenge TXT “aZCCCChonRJiOCL1ZtkKMKnx7U2k3wbSswyClGb6wGk”’  
with\_items: “{{ zone\_files }}”  
register: add\_txt1

- name: Add TXT entry 2 to zone file  
lineinfile:  
dest: “{{ item }}”  
insertafter: EOF  
line: ‘\_acme-challenge TXT “aZCCCChonRJiOCL1ZtkKMKnx7U2k3wbSswyClGb6wGk”’  
with\_items: “{{ zone\_files }}”  
register: add\_txt2

\*Note that the TXT record has to be added to the zone twice.

The idea, of course, is to not have to put the “line:” in manually for each zone in the two plays. All of that said:

1. am I generally on the right track?
2. if so, do I have the variables file set up correctly?
3. how do I use that variables files in the plays? I’m

I know this is a big ask, but would, as always, appreciate your help.
