amendlik / salt-gen-resource

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

tags are not created #7

Closed Mapel88 closed 4 years ago

Mapel88 commented 4 years ago

This is the command I'm using: ./SaltGenResource.py -a environment,region,roles -t roles,environment,region -G environment:STG

received the following warnings:

[WARNING ] Requested grain 'roles' is not available on minion: nl1-stgjob03
[WARNING ] Requested grain 'environment' is not available on minion: nl1-stgjob03
[WARNING ] Requested grain 'region' is not available on minion: nl1-stgjob03

Even though they exists and attributes are created properly:

nl1-stgjob03:
  IP: 1.1.1.1
  environment: STG
  hostname: nl1-stgjob03
  region: NL
  roles: job
[root@master]# salt 'nl1-stgjob03' grains.get roles
nl1-stgjob03:
    - job
[root@master scripts]# salt 'nl1-stgjob03' grains.get region
nl1-stgjob03:
    - NL
[root@master scripts]# salt 'nl1-stgjob03' grains.get environment
nl1-stgjob03:
    - STG

Output after the fix:

nl1-stgjob03:
  IP: 1.1.1.1
  environment: STG
  hostname: nl1-stgjob03
  region: NL
  roles: job
  tags:
  - STG
  - job
  - NL
amendlik commented 4 years ago

It looks like the values you are requesting are actually lists with a single item, not scalars. That is evident from the '-' next to the returned values. In any case, that is supposed to work by adding each list item as a tag.

I'm afraid I can't accept your patch because your solution assumes that the grain will always be a list, and it will always add only the first item as a tag, rather than all items.

As it happens, I made a few changes to the relevant function earlier this week and I believe that your issue was inadvertently fixed. Could you you please test the script on the develop branch and let me know if that works for you?

Mapel88 commented 4 years ago

I tested the code in develop branch and now the tags are added properly. Thanks a lot!