Ask Your Question
1

dnf module in ansible playbook gives an error

asked 2018-11-30 20:58:41 -0600

yn1v gravatar image

Hello,

I have being trying to migrate my post install script to an ansible play book. When I use the dnf module I get an error. This is the content of my test playbook

- name: install VLC
  dnf:
     name: vlc
     state: latest

This is the output

ERROR! 'dnf' is not a valid attribute for a Play

I have been searching and only get references to yum.

Should I drop the use of dnf in the playbooks and stick with package ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-12-02 10:17:20 -0600

bivalence gravatar image

I can't pretend to be an expert at this stuff; I just fiddle with it until it works. It would probably be better to ask questions like this in stackoverflow, but, some comments/questions:

Is this the entire content of your playbook? The examples in the ansible docs for dnf look like your yaml above, but these examples are leaving off all the stuff at the top for the sake of brevity, and assuming you already know what to put there. But those examples from the module docs won't run as written.

I ran it as you provided it, and received the same error.

I am going to assume this is the entire playbook. In that case, the problem is that you've only provided a task list. You haven't provided the 'play'. But as the ansible docs say, each playbook consists of one or more 'plays' in a list. A play is what maps the tasks to specific hosts (in either an explicit or implicit inventory). But because it's missing the 'play' contents, ansible is analyzing your task list as a 'play', and 'dnf' is not valid attribute for 'plays'.

Minimal content that would add the 'play' would be something like:

---
- hosts: localhost
  tasks:

I changed your runbook to:

---
- hosts: localhost
  tasks:
  - name: install VLC
    dnf:
      name: vlc
      state: latest

and that now no longer fails for syntactical reasons. Although it does still fail because I need to run it as root, so here's what the working playbook looks like:

---
- hosts: localhost
  tasks:
  - name: install VLC
    dnf:
      name: vlc
      state: latest
    become: yes
edit flag offensive delete link more

Comments

1

I do have some content on the host file. I made a main.yml file that only have include to the other files that are kind of modular. But these small files was where I had the problem. I just inserted the line task and arranged the indentation and worked just fine. I am using the parameter --ask-pass to elevate to root and perform installs.

Thanks for your help.

yn1v gravatar imageyn1v ( 2018-12-02 16:39:32 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-11-30 20:58:41 -0600

Seen: 48 times

Last updated: Dec 02