amendlik / salt-gen-resource

Generate Rundeck node resources from the Salt Mine
Other
8 stars 7 forks source link

Use compound flag in rundeck doesn't work #5

Closed Mapel88 closed 4 years ago

Mapel88 commented 5 years ago

Hi,

This is not really an issue with the script itself because it's working just fine, more of a consult if you don't mind... I'm trying to use the compound feature in rundeck, but it doesn't seem to work...

When running the script as follows I'm getting the desired output: SaltGenResource.py -t roles -C 'G@region:region and G@roles:role1 or G@roles:role2 or G@roles:role3' When I put the same arguments in rundeck I don't get any nodes...

Do you, perhaps, have an example on how to use the compound flag in rundeck? I think it can't handle the ''.

Would be very much appreciated...

Thanks in advance.

amendlik commented 5 years ago

If I understand correctly, the script works fine from the command line, but not when executed by RunDeck. The first thing I would suggest is to set --log-file-level=debug and see if there are any clues in /var/log/salt/resource-generator

Is your configuration in a file or database? If it's in a file, can you share the relevant portion?

Mapel88 commented 5 years ago

I don't use DB at all. But which section do you need? the nodes? Cause I configured it directly in rundeck under project settings --> edit nodes. I don't see an option to add screen shots, but I can copy my exact configuration. Is that what you need?

I will try to add the debug as you said and will update.

amendlik commented 5 years ago

According to the Rundeck documentation:

When using filesystem storage type, each Project has a configuration file called project.properties, located at this path:

  • rpm/deb: /var/rundeck/projects/project/etc/project.properties
  • launcher: $RDECK_BASE/projects/project/etc/project.properties

So you should be able to find the project.properties file on your server. I am interested in the section that defines your resources providers. The lines should start with resources.source.#.config.

Mapel88 commented 5 years ago

resources.source.1.config.args=--log-file-level\=debug -s -a environment -C 'G@region\:SV and G@roles\:webapp or G@roles\:api or G@roles\:job' resources.source.1.config.file=/rundeck/scripts/SaltGenResource.py resources.source.1.config.format=resourceyaml resources.source.1.config.interpreter=sudo resources.source.1.type=script

amendlik commented 5 years ago

I am able to reproduce similar behavior. To confirm, I'd like you to share a line from your debug log file. Please look for a line like this: [DEBUG ] Calling mine.get with target: '*' type: 'compound'

That will tell us exactly what targeting expression is being used.

amendlik commented 5 years ago

I went pouring through the Rundeck source code to understand how it passes arguments to resource scripts and I found something interesting. There seems to be an undocumented option that looks like it will solve your problem. Please add this to your project configuration:

resources.source.1.config.argsQuoted=true

You may also have to play with changing single quotes to double quotes. Please try it and let me know your results.

Mapel88 commented 5 years ago

This is what I get from the log: Calling mine.get with target: ''G@region:SV' type: 'compound' It only catches the first filter and ignores the rest.

argsQuoted is available in the UI. I already tried it but it also doesn't work. resource generator log is empty when using this flag. This is from rundeck service log: sudo: /rundeck/scripts/SaltGenResource.py --log-file-level=debug -s -a environment -C 'G@region:SV and G@roles:webapp or G@roles:api or G@roles:job': command not found

This is the project config with args quoted enabled:

resources.source.1.config.args=--log-file-level\=debug -s -a environment -C 'G@region\:SV and G@roles\:webapp or G@roles\:api or G@roles\:job'
resources.source.1.config.argsQuoted=true
resources.source.1.config.file=/rundeck/scripts/SaltGenResource.py
resources.source.1.config.format=resourceyaml
resources.source.1.config.interpreter=sudo
resources.source.1.type=script
amendlik commented 5 years ago

Thank your for the information. Based on that, it does not appear to be possible due to the way Rundeck parses the string. It all comes down to this line.

I will follow up with Rundeck to get this resolved. In the meantime the best I can recommend is that you set a custom grain on the nodes you want to target, then target by that grain. For example, let's say you want to use a grain/value of: rdnode=true.

You would first set it like this:

salt -C 'G@region:SV and G@roles:webapp or G@roles:api or G@roles:job' grains.setval rdnode true

Then you could run SaltGenResource with a grain target like -G rdnode:true. That would avoid the problem of having spaces in your targeting expression.

Mapel88 commented 5 years ago

Thank you for your effort and tips. I will open a bug for Rundeck as well.

luisrivas35 commented 5 years ago

Hi guys

I would like to know if any of you already opened a case with Rundeck regarding this issue aforementioned. If it is the case, could you tell me the details?

Regards

Mapel88 commented 5 years ago

I opened a ticket in rundeck support and was working with them to replicate the issue. I think they forwarded it to their developers team recently.

amendlik commented 4 years ago

Fixed in version 3.1.1 of Rundeck