convert centos dnf command into ansible

user2236794 asked:

What is the ansible equivalent command below? I have searched and cant seem to find a way to do it in ansible except by using the shell module. Which might work, but not the best option.

"dnf -y copr enable konimex/neofetch"

My answer:


There’s nothing built in to Ansible to manage Copr repos, so running the command is fine, but you should make it idempotent by not running it if the repo is already installed.

For example:

- name: Install copr repo konimex/neofetch
  command:
    cmd: dnf -y copr enable konimex/neofetch
    creates: /etc/yum.repos.d/_copr:copr.fedorainfracloud.org:konimex:neofetch.repo

Thus when the repo file is already present, the command will not run again, and the task will return ok instead of changed.

(You also should use command instead of shell whenever possible.)


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.