Task doesn't "complete" with any result during second play run

I’m a newbie with Ansible and I’m sure this is probably some feature of it but I can’t figure out what it is.

I have a playbook to

  • copy a package from the controller to a host
  • unpack/install the file

The first time I ran the playbook, everything worked. Then, just to see what happens, I deleted the package and install file and ran the play again. The package got copied to the host again. But the package doesn’t get installed even though the relevant task completes with no errors.

The only thing I noticed is the task returns a state of “ok” versus “changed”.

- name: Install Software
  hosts: all
  become: true
  become_user: root

    - name: Copy software install package to RHEL
      when: inventory_hostname in groups['rhel']
      ansible.builtin.copy:
        src: /home/ansible/software.rpm
        dest: /home/ansible
        owner: ansible
        group: ansible
        mode: '0644'

    - name: Extract install file on RHEL
      when: inventory_hostname in groups['rhel']
      ansible.builtin.yum:
        name: /home/ansible/software.rpm
        state: present
        disable_gpg_check: true

The second task, on the first play run, puts the software in the /opt directory. I deleted it and ran the play again but nothing gets created in the /opt directory the second time.

How do I fix this? Thanks.

It sounds like you might have omitted to uninstall the package? What exactly did you do to delete the package?

This is what what I would expect to happen if the package is installed and nothing needs to be done.

1 Like

It sounds like you might have omitted to uninstall the package? What exactly did you do to delete the package?

I just manually deleted it in another window. I didn’t use Ansible to delete it.

This is what what I would expect to happen if the package is installed and nothing needs to be done.

But the package isn’t installed. I deleted the pacakge and then ran the playbook again. I’m expecting it to install again but it doesn’t.

I think he means your wording is a little unclear, “I deleted the package” could mean you deleted the RPM but didn’t do a yum erase <package>. If you do yum info | grep <some part of the package name>, is it completely gone from yum?

3 Likes

ahh yeah that is my problem. I didn’t do yum erase. I just straight up removed the entire directory the package was in. I’m also a Linux newbie:) Thanks!

It’s yum remove by the way :wink:

1 Like

Both work for yum, but yes, erase was an alias for remove. For dnf (the next iteration of package manager), only remove will work.

1 Like

Another side note. Don’t assume that some RPM package just puts the software in /opt. Some parts of the software usually end up in other directories. If you remove software directory in /opt, you will have leftovers in other places and your package manager (yum) will not be aware of it. That’s what package manager are used for - to track all the package files so they can be removed cleanly if you choose so. In other words, use package manager both for installation and removal of software package, and other package management tasks of course.

3 Likes