# rpm--import issues

**URL:** <https://forum.ansible.com/t/rpm-import-issues/32860>\
**Category:** Ansible Project\
**Created:** [May 6, 2020, 10:17am UTC](https://forum.ansible.com/t/rpm-import-issues/32860 "2020-05-06T10:17:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quad\_Zero](https://avatars.discourse-cdn.com/v4/letter/q/eb9ed0/32.png) [@Quad\_Zero](https://forum.ansible.com/u/Quad_Zero)\
**Post date:** [May 6, 2020, 10:17am UTC](https://forum.ansible.com/t/rpm-import-issues/32860/1 "2020-05-06T10:17:16Z")

</div>

Hi all,

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:

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [May 6, 2020, 11:31am UTC](https://forum.ansible.com/t/rpm-import-issues/32860/2 "2020-05-06T11:31:23Z")

</div>

Hi,

There’s a module to import key, please use it !

[https://docs.ansible.com/ansible/latest/modules/rpm\_key\_module.html](https://docs.ansible.com/ansible/latest/modules/rpm_key_module.html)

Regards,

JYL

---

<div class="post-metadata">

**Author:** ![Neha\_Pithadiya](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@Neha\_Pithadiya](https://forum.ansible.com/u/Neha_Pithadiya)\
**Post date:** [May 6, 2020, 11:35am UTC](https://forum.ansible.com/t/rpm-import-issues/32860/3 "2020-05-06T11:35:45Z")

</div>

I tried locally on my setup and faced same issue.

seems this rpm command uses shell , so you need to use “shell” module instead of “command” module.

eg : shell: “rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-\*”

Results of execution:

changed: [localhost] =\> {  
“changed”: true,  
“cmd”: “rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-_",  
“delta”: “0:00:00.072035”,  
“end”: “2020-05-06 16:57:24.092604”,  
“invocation”: {  
“module\_args”: {  
“\_raw\_params”: "rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-_”,  
“\_uses\_shell”: true,  
“argv”: null,  
“chdir”: null,  
“creates”: null,  
“executable”: null,  
“removes”: null,  
“stdin”: null,  
“stdin\_add\_newline”: true,  
“strip\_empty\_ends”: true,  
“warn”: true  
}  
},  
“rc”: 0,  
“start”: “2020-05-06 16:57:24.020569”,  
“stderr”: “”,  
“stderr\_lines”: ,  
“stdout”: “”,  
“stdout\_lines”:

Thanks and Regards,  
Neha Pithadiya.

---

<div class="post-metadata">

**Author:** ![Quad\_Zero](https://avatars.discourse-cdn.com/v4/letter/q/eb9ed0/32.png) [@Quad\_Zero](https://forum.ansible.com/u/Quad_Zero)\
**Post date:** [May 6, 2020, 11:01pm UTC](https://forum.ansible.com/t/rpm-import-issues/32860/4 "2020-05-06T23:01:19Z")

</div>

Thanks for your reply but really is not helpful bud.

This is like if i asked how i can get to a destination, you are telling me to go to a train or bus station.

---

<div class="post-metadata">

**Author:** ![Quad\_Zero](https://avatars.discourse-cdn.com/v4/letter/q/eb9ed0/32.png) [@Quad\_Zero](https://forum.ansible.com/u/Quad_Zero)\
**Post date:** [May 6, 2020, 11:04pm UTC](https://forum.ansible.com/t/rpm-import-issues/32860/5 "2020-05-06T23:04:34Z")

</div>

Neha,

This is amazing! Thank you so much for your reply and the time you took to actually run it for me.

Stay awesome as you are Neha 🙂

---

<div class="post-metadata">

**Author:** ![Michael\_M1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_M1](https://forum.ansible.com/u/Michael_M1)\
**Post date:** [May 6, 2020, 11:15pm UTC](https://forum.ansible.com/t/rpm-import-issues/32860/6 "2020-05-06T23:15:19Z")

</div>

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](http://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.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 7, 2020, 4:49am UTC](https://forum.ansible.com/t/rpm-import-issues/32860/7 "2020-05-07T04:49:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 7, 2020, 6:01am UTC](https://forum.ansible.com/t/rpm-import-issues/32860/8 "2020-05-07T06:01:48Z")

</div>

> Thanks for your reply but really is not helpful bud.
> 
> This is like if i asked how i can get to a destination, you are telling me to go to a train or bus station.

That was a bad move from you if you ask me.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Quad\_Zero](https://avatars.discourse-cdn.com/v4/letter/q/eb9ed0/32.png) [@Quad\_Zero](https://forum.ansible.com/u/Quad_Zero)\
**Post date:** [May 7, 2020, 11:40am UTC](https://forum.ansible.com/t/rpm-import-issues/32860/9 "2020-05-07T11:40:33Z")

</div>

Hi Michael,

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 🙂

---

<div class="post-metadata">

**Author:** ![Quad\_Zero](https://avatars.discourse-cdn.com/v4/letter/q/eb9ed0/32.png) [@Quad\_Zero](https://forum.ansible.com/u/Quad_Zero)\
**Post date:** [May 7, 2020, 11:43am UTC](https://forum.ansible.com/t/rpm-import-issues/32860/10 "2020-05-07T11:43:36Z")

</div>

Hi Dick,

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.

Thank you once again.

---

<div class="post-metadata">

**Author:** ![Quad\_Zero](https://avatars.discourse-cdn.com/v4/letter/q/eb9ed0/32.png) [@Quad\_Zero](https://forum.ansible.com/u/Quad_Zero)\
**Post date:** [May 7, 2020, 11:44am UTC](https://forum.ansible.com/t/rpm-import-issues/32860/11 "2020-05-07T11:44:52Z")

</div>

Apologies to you also Racke. Thank you for pointing this out.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 7, 2020, 4:22pm UTC](https://forum.ansible.com/t/rpm-import-issues/32860/12 "2020-05-07T16:22:57Z")

</div>

Hi

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:

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: Find RPM GPG keys  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;find:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paths: /etc/pki/rpm-gpg  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: gpg\_found

&nbsp;&nbsp;&nbsp;&nbsp;- name: Ensure found keys are trusted  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rpm\_key:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key: "{{ item.path }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: present  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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.
