No, the Ansible dnf module doesn't support enabling Copr repositories.
You can add a task that tests if your Copr repository is already enabled that guards the Copr enable task.
Example:
shell:
cmd: |
dnf -C repolist enabled -v | grep '^Repo-id' | awk '$3 == "copr:copr.fedorainfracloud.org:ganto:lxd" {print "enabled"}'
warn: no
check_mode: no
changed_when: false
register: lxd_copr
- name: Enable Fedora Copr for LXD
command:
cmd: dnf -y copr enable ganto/lxd
warn: no
when: lxd_copr.stdout == ''
Notes:
- double check the id of your copr repository as it's different from the short name you use to enable it
- I set
warn: no because ansible warns about all dnf commands (because it suggests to use the dnf module, if possible)
- I set
check_mode: no since it's safe to execute it even in --check mode
- I set
changed_when: false because the command doesn't change system state
Alternatively you can add and enable a Copr repository with the yum_repository Ansible module.
Example:
- name: enable copr
yum_repository:
name: "copr:copr.fedorainfracloud.org:{{ item[0] }}:{{ item[1] }}"
file: "_copr:copr.fedorainfracloud.org:{{ item[0] }}:{{ item[1] }}"
description: "{{ item[2] }}"
baseurl: "{{ copr_url }}/results/{{ item[0] }}/{{ item[1] }}/fedora-$releasever-$basearch/"
gpgkey: "{{ copr_url }}/results/{{ item[0] }}/{{ item[1] }}/pubkey.gpg"
gpgcheck: yes
enabled: yes
skip_if_unavailable: yes
vars:
#copr_url: https://copr-be.cloud.fedoraproject.org
copr_url: https://download.copr.fedorainfracloud.org
loop:
- [ganto, lxd, "Copr repo for LXD"]
This approximates the effect of the dnf copr enable ganto/lxd call. But there are some minor textual differences in the resulting .repo file (e.g. True vs. 1, keys with default values missing) that would lead to this task reporting changed if e.g. the repository was already enabled with dnf copr.
Also, this arguably has a higher maintenance overhead as one would have to track changes Copr introduces to its .repo files.