Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crontab and crontab-u parsers fail if the only entry in the file has a special schedule #366

Closed
rrechtin opened this issue Feb 21, 2023 · 7 comments
Assignees
Labels
bug Something isn't working ready-to-ship

Comments

@rrechtin
Copy link

Apologies if anything is off, this is my first time submitting an issue on github.

I was attempting to use the ansible community.general.jc filter to parse crontab files, and ran into an issue. I have traced it to the crontab and crontab-u parsers. If the file contains only entries with "special" schedules (such as @hourly, @reboot, etc), the parser fails. This is due to the fact that when it reaches the part to append to the raw_output, because it was not initialized, it errors out.

I have attached two files with the example output (you get essentially the same output with crontab-u):

cat ~/test_jc_without_normal.txt | jc --crontab
jc:  Error - crontab parser could not parse the input data.
             If this is the correct parser, try setting the locale to C (LC_ALL=C).
             For details use the -d or -dd option. Use "jc -h --crontab" for help.

cat ~/test_jc_with_normal.txt | jc --crontab
{"variables":[],"schedule":[{"minute":["*"],"hour":["*"],"day_of_month":["*"],"month":["*"],"day_of_week":["*"],"command":"root /bin/sh do_the_other_thing"},{"occurrence":"daily","command":"root /bin/sh do_the_thing"}]}

test_jc_with_normal.txt
test_jc_without_normal.txt

@kellyjonbrazil kellyjonbrazil self-assigned this Feb 21, 2023
@kellyjonbrazil kellyjonbrazil added the bug Something isn't working label Feb 21, 2023
@kellyjonbrazil
Copy link
Owner

Thank you for reporting this issue! It looks like this could be a quick fix. Thanks for the samples!

@kellyjonbrazil
Copy link
Owner

I have a fix for this in the dev branch. You can test by copying the files to your plugin directory:
https://github.com/kellyjonbrazil/jc/blob/dev/jc/parsers/crontab.py
https://github.com/kellyjonbrazil/jc/blob/dev/jc/parsers/crontab_u.py

  • Linux/unix: $HOME/.local/share/jc/jcparsers
  • macOS: $HOME/Library/Application Support/jc/jcparsers
  • Windows: $LOCALAPPDATA\jc\jc\jcparsers

Let me know if you run into any other issues!

@rrechtin
Copy link
Author

rrechtin commented Feb 22, 2023

(Short version: fix works)

This may just be me being dense, but maybe you can help me out.

We're using a container to run ansible, and utilizing JC via ansible in the docker container. I have not been able to utilize the $HOME/.local/share/jc/jcparsers directory (/root/.local/share/jc/jcparsers) for parsers while using ansible. I can shell into the container and manually run cat "file" | jc --"custom-parser" and successfully parse, but ansible throws an error saying the parser isn't available.

If I rebuild the container to put the file in the jc distribution location under /usr/local, the fix works even through ansible.

@kellyjonbrazil
Copy link
Owner

This is a limitation with the Ansible plugin today. It doesn’t find plug-in parsers like the CLI - it only knows about built-in parsers.

I can update the Ansible plugin to use the newer API so it can find parsers in the plugin directory. In the mean-time you’d have to manually change out the file under jc/parsers wherever it is installed on your system/container until I get the fix in the next release.

It’s probably about time I update the Ansible plugin.

@rrechtin
Copy link
Author

No problem, that's easy to do for the container.

Thank you very much for the quick response and fix!

@kellyjonbrazil
Copy link
Owner

FYI, I have submitted a PR to Ansible Community General to update the jc Filter Plugin to allow parser plugins:

ansible-collections/community.general#6043

@kellyjonbrazil
Copy link
Owner

Added in v1.23.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready-to-ship
Projects
None yet
Development

No branches or pull requests

2 participants