Can't get gpg key accepted automatically for new repo on CentOS 7

Here’s the play I’ve tried:

`

  • hosts: eliza
    tags:
  • grafana
    roles:
  • role: service_restart

tasks:

`

This results is:

`

[vagrant@jolly ansible-repo]$ ./run-ansible-vagrant playbooks/prometheus/grafana.yml

PLAY [eliza] *******************************************************************

TASK [setup] *******************************************************************
ok: [eliza]

TASK [Add grafana repository] **************************************************
changed: [eliza]

TASK [rpm_key] *****************************************************************
changed: [eliza] => (item=https://packagecloud.io/gpg.key)
changed: [eliza] => (item=https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana)

TASK [Install grafana] *********************************************************
fatal: [eliza]: FAILED! => {“changed”: false, “failed”: true, “msg”: “Failure talking to yum: failure: repodata/repomd.xml from grafana: [Errno 256] No more mirrors to try.\nhttps://packagecloud.io/grafana/stable/el/6/x86_64/repodata/repomd.xml: [Errno -1] repomd.xml signature could not be verified for grafana”}

NO MORE HOSTS LEFT *************************************************************

PLAY RECAP *********************************************************************
eliza : ok=3 changed=2 unreachable=0 failed=1

[vagrant@jolly ansible-repo]$

`

If I run ‘yum -y install grafana’ it works and accepts the gpg keys. How am I supposed to do this correctly in ansible?

There’s a issue open for this exact case: https://github.com/ansible/ansible/issues/20711