If I am correct, I would need the output from yum repolist -v : Loading "fastestmirror" plugin Loading "langpacks" plugin Adding en_US.UTF-8 to language list Config time: 0.008 Yum version: 3.4.3 Loading mirror speeds from cached hostfile Setting up Package Sacks pkgsack time: 0.008
Repo-id : docker-ce-stable/x86_64 Repo-name : Docker CE Stable - x86_64 Repo-revision: 1583949071 Repo-updated : Wed Mar 11 18:51:11 2020 Repo-pkgs : 70 Repo-size : 1.6 G Repo-baseurl : https://download.docker.com/linux/centos/7/x86_64/stable/ Repo-expire : 21,600 second(s) (last: Tue Apr 21 11:06:47 2020) Filter : read-only:present Repo-filename: /etc/yum.repos.d/docker-ce.repo Repo-id : jenkins Repo-name : Jenkins-stable Repo-revision: 1585146777 Repo-updated : Wed Mar 25 15:32:57 2020 Repo-pkgs : 102 Repo-size : 6.1 G Repo-baseurl : http://pkg.jenkins.io/redhat-stable/ Repo-expire : 21,600 second(s) (last: Tue Apr 21 11:06:48 2020) Filter : read-only:present Repo-filename: /etc/yum.repos.d/jenkins.repo == To look like this as a json file: { "repos": [ { "repoid_ref": "docker-ce-stable/x86_64", "reponame_ref": "Docker CE Stable - x86_64" }, { "repoid_ref": "jenkins", "reponame_ref": "Jenkins-stable" } ], "repoinfo": [ { "repoid": "docker-ce-stable/x86_64", "reponame": "Docker CE Stable - x86_64", "repoupdated": "Wed Mar 11 18:51:11 2020", "repopkgs": "70", "reposize": "1.6 G", "repobaseurl": "https://download.docker.com/linux/centos/7/x86_64/stable/", "repofilename": "/etc/yum.repos.d/docker-ce.repo", "repoid_ref": "docker-ce-stable/x86_64", "reponame_ref": "Docker CE Stable - x86_64" }, { "repoid": "jenkins", "reponame": "Jenkins-stable", "repoupdated": "Wed Mar 25 15:32:57 2020", "repopkgs": "102", "reposize": "6.1 G", "repobaseurl": "http://pkg.jenkins.io/redhat-stable/", "repofilename": "/etc/yum.repos.d/jenkins.repo", "repoid_ref": "jenkins", "reponame_ref": "Jenkins-stable" } ] } Any reasonable tips on doing that. ? I created that manually, for now, to then try the Ansible part: --- - hosts: "{{target_host}}" gather_facts: false become: true become_user: root tasks: - name: Display the JSON file content shell: cat /root/repoinfo_new.json register: result - name: save the Json data to a Variable as a Fact set_fact: jsondata: "{{ result.stdout | from_json }}" - name: Set facts - Repo id's set_fact: repoids: "{{ jsondata | json_query(jmesquery) }}" vars: jmesquery: '*.repoinfo[*].repoid' - name: Repo id's and Names set_fact: repoinfo: "{{ jsondata | json_query(jmesquery) }}" vars: jmesquery: '*.repoinfo[*].[repoid, reponame]' - name: Print all repoid names debug: msg: "{{ item }}" with_items: - "{{ repoids }}" - name: Print all repoids and Names debug: msg: "{{ item }}" with_items: - "{{ repoinfo }}" But I am not getting any output as yet. On Tuesday, April 21, 2020 at 7:00:52 PM UTC+2, Spoonless wrote: > > 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/64d357d1-2095-4a78-beed-7f8de8db27fb%40googlegroups.com.