Trying to get the yum repolist -v data to a json format that I can parse 
with Ansible  is tricky enough for a beginner.

On Tuesday, April 21, 2020 at 11:01:00 AM UTC+2, Spoonless wrote:
>
> Hi,
>
> So, if I get the output of my yum repolist -v to a json format then I can 
> use the json query in Ansible, like here:
>
>
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#json-query-filter
>
> I guess, Python or jq or something to prep the output in the required 
> format.
> (I'll have to get to grips with that part.)
>
> Thanks again.
>
>
>
> On Monday, April 20, 2020 at 11:26:55 PM UTC+2, Kai Stian Olstad wrote:
>>
>> On Fri, Apr 17, 2020 at 12:59:09AM -0700, 'Spoonless' via Ansible Project 
>> wrote: 
>> > Hi again, 
>> > 
>> > Thanks for the tip in the right direction: 
>> > 
>> > I now have this: 
>> > 
>> >   tasks: 
>> >     - name: Set the required enabled repo information as facts 
>> >       shell: "yum repolist -v | grep {{item}} | awk -F\": \" '{print 
>> $2}'" 
>> >       with_items: 
>> >         - "Repo-id" 
>> >         - "Repo-updated" 
>> >         - "Repo-pkgs" 
>> >         - "Repo-size" 
>> >         - "Repo-name" 
>> >         - "Repo-baseurl" 
>> >         - "Repo-filename" 
>> >       register: output       
>> >     - set_fact: 
>> >         repoid: "{{ output.results.0.stdout }}" 
>> > #        repoupdated: "{{ output.results.1.stdout }}" 
>> > #        repopkgs: "{{ output.results.2.stdout }}" 
>> > #        reposize: "{{ output.results.3.stdout }}"         
>> >         reponame: "{{ output.results.4.stdout }}" 
>> >         repobaseurl: "{{ output.results.5.stdout }}" 
>> >         repofilename: "{{ output.results.6.stdout }}" 
>> > 
>> >     - debug: 
>> >         msg: "{{reponame}} is an illegal url" 
>> >       when: repobaseurl is search("ftp://somehostname.*";) 
>> >       
>> > 
>> > 
>> > == 
>> > 
>> > But.. 
>> > My debug output is now showing all of the repo's and not filtering. 
>> > ? 
>>
>> Yes, the stdout will contain everything. 
>>
>> output.results.0.stdout_lines.0 will contain the repo-id for the first 
>> one. 
>> output.results.0.stdout_lines.1 will contain the repo-id for the second 
>> one. 
>>
>> output.results.5.stdout_lines.0 will contain the repo-baseurl for the 
>> first one. 
>> output.results.5.stdout_lines.1 will contain the repo-baseurl for the 
>> second one. 
>>
>>
>> It isn't easy to parse text in Ansible, i would create a script that did 
>> the 
>> parsing and returned a json that you can use a lot easier in Ansible. 
>>
>>
>> -- 
>> Kai Stian Olstad 
>>
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/cf1a3c5c-ce18-4f40-9b35-e80bde066e4d%40googlegroups.com.

Reply via email to