question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ansible: "msg": "You need to install \"jc\" prior to running jc filter"

See original GitHub issue

Installed jc locally and w/ ansible-galaxy for some reason it’s not being found:

---
- name: "Get Junos OS configuration"
  hosts: junos_all
  connection: local
  gather_facts: no
  
  tasks:

    - name: run show version on remote devices
      juniper.device.command:
        commands: show system uptime
      register: output

    - name: Print response
      debug:
        var: "{{ output.stdout_lines | community.general.jc('System booted') }}"
jc --version
jc version 1.16.1
https://github.com/kellyjonbrazil/jc
© 2019-2021 Kelly Brazil

dig example.com | jc --dig

[{"id":30676,"opcode":"QUERY","status":"NOERROR","flags":["qr","rd","ra"],"query_num":1,"answer_num":1,"authority_num":0,"additional_num":1,"opt_pseudosection":{"edns":{"version":0,"flags":[],"udp":1220}},"question":{"name":"example.com.","class":"IN","type":"A"},"answer":[{"name":"example.com.","class":"IN","type":"A","ttl":17,"data":"93.184.216.34"}],"query_time":44,"server":"192.168.32.11#53(192.168.32.11)","when":"Thu Aug 26 11:25:12 PDT 2021","rcvd":56,"when_epoch":1630002312,"when_epoch_utc":null}]

ansible --version

ansible [core 2.11.4]
  config file = /Users/nmoore/code/neteng/automation/junos/ansible/ansible.cfg
  configured module search path = ['/Users/nmoore/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/nmoore/.ansible/collections:/usr/share/ansible/collections
  executable location = /Library/Frameworks/Python.framework/Versions/3.9/bin/ansible
  python version = 3.9.6 (v3.9.6:db3ff76da1, Jun 28 2021, 11:49:53) [Clang 6.0 (clang-600.0.57)]
  jinja version = 3.0.1
  libyaml = True

ag collection list
# /Users/nmoore/.ansible/collections/ansible_collections
Collection             Version
---------------------- -------
cisco.meraki           2.4.2
community.general      3.5.0
juniper.device         1.0.0
paloaltonetworks.panos 2.7.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kellyjonbrazilcommented, Aug 26, 2021

BTW, you can also parse the first 5 lines using the jc key/value parser (kv):

var2: "{{ output.stdout_lines[:5] | community.general.jc('kv') }}"

should produce this:

{
  "current time": "2021-08-26 19:25:41 UTC",
  "time source": "NTP CLOCK",
  "system booted": "2020-08-16 08:04:36 UTC (53w4d 11:21 ago)",
  "protocols started": "2020-08-16 08:13:26 UTC (53w4d 11:12 ago)",
  "last configured": "2021-08-26 00:43:22 UTC (18:42:19 ago) by someuser"
}

(Actually you’ll, probably have to join that list with \n)

0reactions
kellyjonbrazilcommented, Aug 26, 2021

I think you just need to do the join before it goes to jc:

var: "{{ output.stdout_lines[:6] | join('\n') | community.general.jc('kv') }}"

(I changed the 5 to 6 since I noticed an extra \n at the beginning of the output. Hope that works)

Thanks for the suggestion - I’ll look into signing up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

community.general.jc filter – Convert output of many shell ...
To install it, use: ansible-galaxy collection install community.general . You need further requirements to be able to use this filter plugin, ...
Read more >
ansible-sample/jc.yml at master - filter - GitHub
fatal: [localhost]: FAILED! =>. # msg: You need to install "jc" prior to running jc filter. # require: # pip install jc. tasks:...
Read more >
"You need to install 'jmespath' prior to running json_query filter ...
It seems that: Ansible is using the non-default version python3.8; The module jmespath needs to be installed for both versions separately.
Read more >
Parsing Command Output in Ansible with JC - Brazil's Blog
Installation. To use the jc filter plugin, you just need to install jc and the community.general collection on the Ansible controller.
Read more >
jc · PyPI
Argument Command or Filetype Documentation ‑‑acpi acpi command parser details ‑‑airport airport ‑I command parser details ‑‑airport‑s airport ‑s command parser details
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found