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') }}"

On Friday, March 10, 2023 at 9:37:39 AM UTC-5 Abhijeet Kasurde wrote:

> 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.
>
>
> On Fri, Mar 10, 2023 at 7:45 PM Neha Singh <[email protected]> wrote:
>
>> 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
>>
>> On Friday, March 10, 2023 at 7:36:27 PM UTC+5:30 Abhijeet Kasurde wrote:
>>
>>> # cat virtual_host.conf
>>> [control_environment]
>>> transient_partition_size = 150G
>>>
>>> ---
>>> - hosts: localhost
>>>   gather_facts: no
>>>   tasks:
>>>     - debug:
>>>         msg: "{{ lookup('ini', 'transient_partition_size 
>>> section=control_environment file=virtual_host.conf') }}"
>>>
>>>
>>> output - 
>>> ```
>>> TASK [debug] 
>>> *******************************************************************
>>> task path: /Volumes/data/src/playbooks/section.yml:5
>>> ok: [localhost] => {
>>>     "msg": "150G"
>>> }
>>> ```
>>>
>>>
>>> On Fri, Mar 10, 2023 at 7:25 PM Neha Singh <[email protected]> wrote:
>>>
>>>> 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
>>>>
>>>> On Friday, March 10, 2023 at 7:22:10 PM UTC+5:30 Neha Singh wrote:
>>>>
>>>>> 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
>>>>> On Friday, March 10, 2023 at 7:00:14 PM UTC+5:30 Abhijeet Janwalkar 
>>>>> wrote:
>>>>>
>>>>>> Hey,
>>>>>> Is there a typo in file name 
>>>>>> - and _.
>>>>>> Or it's only in mail.
>>>>>>
>>>>>> Warm regards
>>>>>> Abhijeet 
>>>>>>
>>>>>> On Fri, 10 Mar, 2023, 14:17 Neha Singh, <[email protected]> wrote:
>>>>>>
>>>>>>> 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
>>>>>>>
>>>>>>> On Friday, March 10, 2023 at 6:30:40 PM UTC+5:30 Abhijeet Kasurde 
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Error is - File contains no section headers.
>>>>>>>>
>>>>>>>> You need a section in ini file that you have created.
>>>>>>>>
>>>>>>>> On Fri, Mar 10, 2023 at 6:25 PM Neha Singh <[email protected]> 
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> 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
>>>>>>>>>
>>>>>>>>> -- 
>>>>>>>>> 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 view this discussion on the web visit 
>>>>>>>>> https://groups.google.com/d/msgid/ansible-project/c80f627b-cdc9-4cf2-94f2-f3727fc175d1n%40googlegroups.com
>>>>>>>>>  
>>>>>>>>> <https://groups.google.com/d/msgid/ansible-project/c80f627b-cdc9-4cf2-94f2-f3727fc175d1n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>>> .
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> -- 
>>>>>>>> Thanks,
>>>>>>>> Abhijeet Kasurde
>>>>>>>>
>>>>>>> -- 
>>>>>>> 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 view this discussion on the web visit 
>>>>>>> https://groups.google.com/d/msgid/ansible-project/62bfa0b3-3686-42e1-9920-48aa2340e654n%40googlegroups.com
>>>>>>>  
>>>>>>> <https://groups.google.com/d/msgid/ansible-project/62bfa0b3-3686-42e1-9920-48aa2340e654n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>> .
>>>>>>>
>>>>>> -- 
>>>> 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 view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/ansible-project/354354ad-f625-4501-8d0c-adae376317fen%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/ansible-project/354354ad-f625-4501-8d0c-adae376317fen%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>
>>>
>>> -- 
>>> Thanks,
>>> Abhijeet Kasurde
>>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/003c7147-9d43-458f-937e-d2ba07852a0fn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/003c7147-9d43-458f-937e-d2ba07852a0fn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Thanks,
> Abhijeet Kasurde
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/48589b36-ee27-4840-9b42-dce7680b6e29n%40googlegroups.com.

Reply via email to