# lookup.ini plugin doesn't work

**URL:** <https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752>\
**Category:** Ansible Project\
**Created:** [March 10, 2023, 12:55pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752 "2023-03-10T12:55:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![neha0021997](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@neha0021997](https://forum.ansible.com/u/neha0021997)\
**Post date:** [March 10, 2023, 12:55pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/1 "2023-03-10T12:55:16Z")

</div>

Hi Team,

I have created one file where I have specify a variable:

path: /opt/si/ansible/conf/virtual\_host

transient\_partition\_size = 200G

And then trying to print the variable by using lookup through another playbook:

- debug:

msg: “{{ lookup(‘ini’, ‘transient\_partition\_size section={{control\_environment}} file=/opt/si/ansible/conf/virtual-host’) }}”

Result:

Error was a \<class ‘ansible.errors.AnsibleError’\>, original message: An unhandled exception occurred while running the lookup plugin ‘ini’. Error was a \<class ‘ConfigParser.MissingSectionHeaderError’\>, original message: File contains no section headers.\nfile: \<???\>, line: 1\nu’transient\_partition\_size = 200G\n’"}

Can you help me here…?

Please find more info regarding version  
ansible --version  
ansible 2.9.27

python version = 2.7.5 (default, May 27 2022, 11:27:32) [GCC 4.8.5 20150623 (Red Hat  
4.8.5-44)]

Thanks  
Neha

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [March 10, 2023, 1:00pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/2 "2023-03-10T13:00:12Z")

</div>

Error is - File contains no section headers.

You need a section in ini file that you have created.

---

<div class="post-metadata">

**Author:** ![neha0021997](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@neha0021997](https://forum.ansible.com/u/neha0021997)\
**Post date:** [March 10, 2023, 1:17pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/3 "2023-03-10T13:17:08Z")

</div>

Ok, one more question though. I have not mentioned any file extension like .ini, .conf, .cfg. Will that work without the same as well.

Thanks  
Neha

---

<div class="post-metadata">

**Author:** ![abhijeetJanwalkar](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@abhijeetJanwalkar](https://forum.ansible.com/u/abhijeetJanwalkar)\
**Post date:** [March 10, 2023, 1:29pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/4 "2023-03-10T13:29:53Z")

</div>

Hey,  
Is there a typo in file name

- and \_.  
Or it’s only in mail.

Warm regards  
Abhijeet

---

<div class="post-metadata">

**Author:** ![neha0021997](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@neha0021997](https://forum.ansible.com/u/neha0021997)\
**Post date:** [March 10, 2023, 1:52pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/5 "2023-03-10T13:52:10Z")

</div>

Hi Abhijeet,

I have updated my config file as below:

file path: /opt/si/ansible/conf/virtual\_host.conf

[control\_environment]  
transient\_partition\_size = 150G

and my playbook task is as below:

- debug:

msg: “{{ lookup(‘ini’, ‘transient\_partition\_size section={{control\_environment}} file=/opt/si/ansible/conf/virtual\_host.conf’) }}”

Error is as below:  
Error was a \<class ‘ansible.errors.AnsibleError’\>, original message: An unhandled exception occurred while running the lookup plugin ‘ini’. Error was a \<class ‘ConfigParser.NoSectionError’\>, original message: No section:

Not sure, what is the issue now…

Thanks

---

<div class="post-metadata">

**Author:** ![neha0021997](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@neha0021997](https://forum.ansible.com/u/neha0021997)\
**Post date:** [March 10, 2023, 1:55pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/6 "2023-03-10T13:55:10Z")

</div>

Adding the full error message:

Error was a \<class ‘ansible.errors.AnsibleError’\>, original message: An unhandled exception occurred while running the lookup plugin ‘ini’. Error was a \<class ‘ConfigParser.NoSectionError’\>, original message: No section: u’edgy’"}ESC[0m

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [March 10, 2023, 2:05pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/7 "2023-03-10T14:05:51Z")

</div>

# cat virtual\_host.conf

[control\_environment]  
transient\_partition\_size = 150G

---

<div class="post-metadata">

**Author:** ![neha0021997](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@neha0021997](https://forum.ansible.com/u/neha0021997)\
**Post date:** [March 10, 2023, 2:14pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/8 "2023-03-10T14:14:53Z")

</div>

As mentioned in the error:  
Error was a \<class ‘ansible.errors.AnsibleError’\>, original message: An unhandled exception occurred while running the lookup plugin ‘ini’. Error was a \<class ‘ConfigParser.NoSectionError’\>, original message: No section: u’edgy’"}

When I have updated the section name with ‘edgy’ as below:

[edgy]  
transient\_partition\_size = 150G

and used the same playbook task code

it works for me now… I suppose, there is somewhere in my system, control\_environment value has beens et to edgy, if I am not wrong. Do u have any idea about this?

Thanks

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [March 10, 2023, 2:37pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/9 "2023-03-10T14:37:08Z")

</div>

You are using ‘{{’ for Jinja templating for section name in the lookup plugin.

If you are setting the section value to ‘control\_environment’ then don’t include the ‘{{’ in the lookup plugin.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [March 10, 2023, 3:02pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/10 "2023-03-10T15:02:12Z")

</div>

Your quoting is all wrong. You are passing in one long string.  
Use this:

msg: “{{ lookup(‘ini’, ‘transient\_partition\_size’, section=‘control\_environment’, file=‘/opt/si/ansible/conf/virtual\_host.conf’) }}”

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [March 10, 2023, 3:08pm UTC](https://forum.ansible.com/t/lookup-ini-plugin-doesnt-work/37752/11 "2023-03-10T15:08:55Z")

</div>

Also, if your file doesn’t have sections, only `key=value` pairs, then specify `type='properties'`, like this:

msg: “{{ lookup(‘ini’, ‘transient\_partition\_size’, type=‘properties’, file=‘/opt/si/ansible/conf/virtual\_host.conf’) }}”
