Thank you for your help in my last post. I have come quite a way (small compared to many of you) but nevertheless making good progress each day.
I hit roadblocks quite a bit and thankfully google has helped me quite a bit. I have come across this problem now which I hope some of you can explain and then help me with finding a solution. This is my code so far:
Quad Zero,
You didn’t even indicate if you tried using the module JYL took the time to point out to you. There are examples there and everything. If you want pre-written Ansible code without doing any research or leg work you should look on galaxy.ansible.com.
And that is really weak criticizing someone that took more time to try to solve your problem than you did. People are likely going to stop responding to you after that comment.
Indeed.
I’ve noticed quite a few people are frantically trying to shoehorn shell commands into ansible. This works yes but lacks all the goodies that ansible brings such as idempotency etc.
The questions then tend to narrow down to why the output of a dozen twelve cat/grep/sed/awk pipes doesn’t do what they want.
In this case it’s not clear why you’d want to blindly add all rpm keys. This once again looks like a sledgehammer and should instead be done by iterating over the keys you actually want, with rpm_key.
So I did search all the modules. My question was how to import all the keys from the /etc/pki… all i could find was individual loads, it was so that I run multiple CentOS and RedHat servers and some have different repos enabled, so bulk import would be a better solution I thought?
Sure, my bad, though I just asked myself how I would go about if someone asked me the same question. I would only reply directly to their question but that is just me. Anyways, don’t want to stir anything further so apologies to all esp to JYL for my rude comment.
Thank you to those that helped me and to everyone that replied to this thread
Yes, so I may have replied to your comment above in my reply back to Michael.
I guess my knowledge on Ansible is still very new, so currently just getting things done, until I get to grips with better understanding.
Could anyone please recommend any good books that covers most of the modules in depth? Just trying to learn and last night was quite frustrating for me.
No problem.
So the 'ansible way' is to use native modules wherever possible. The
shell/command task should be used only if there is no reasonable way
to achieve things using native modules.
In your case the ansible way could look something like this:
- name: Ensure found keys are trusted
rpm_key:
key: "{{ item.path }}"
state: present
loop: "{{ gpg_found.files }}"
You will find that once run, subsequent runs will not actually do
anything anymore as the desired state will have been reached after the
first run: idempotence.
You can optionally tune these tasks, for instance to fit the pattern
of the key names, etc.