# A playbook is not working (with no error) after manual removal of the package from the server

**URL:** <https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357>\
**Category:** Get Help\
**Created:** [March 13, 2024, 2:25pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357 "2024-03-13T14:25:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saritha](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Saritha](https://forum.ansible.com/u/Saritha)\
**Post date:** [March 13, 2024, 2:25pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/1 "2024-03-13T14:25:40Z")

</div>

Example: I installed java using ansible playbook on remote server. Later someone uninstalled manually. Then I tried installing java again using the same playbook.  
the playbook is running successfully but not installing java this time.  
Tried restarting the remote server and running playbook again. but no luck.

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [March 13, 2024, 2:37pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/2 "2024-03-13T14:37:06Z")

</div>

Do you get any useful output when you run the playbook with maximum verbosity?

If not, please provide the contents of the playbook and evidence that Java is not installed on the remote system, as a start to troubleshooting.

---

<div class="post-metadata">

**Author:** ![Saritha](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Saritha](https://forum.ansible.com/u/Saritha)\
**Post date:** [March 13, 2024, 6:05pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/3 "2024-03-13T18:05:25Z")

</div>

## This is the playbook-

- name: install Java  
hosts: all  
tasks:

Output on Remote machine:  
PS C:\Users\XXXX\> java  
java : The term ‘java’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check  
the spelling of the name, or if a path was included, verify that the path is correct and try again.  
At line:1 char:1

- java
- 

```auto
  + CategoryInfo : ObjectNotFound: (java:String) [], CommandNotFoundException
  + FullyQualifiedErrorId : CommandNotFoundException
```

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [March 14, 2024, 12:38pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/4 "2024-03-14T12:38:07Z")

</div>

Unfortunately, I don’t have any win\_chocolatey experience. I was hoping to see something the verbose output that I could give a tip on researching, but I’m out of my depth on this one.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [March 15, 2024, 8:07pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/5 "2024-03-15T20:07:08Z")

</div>

The problem is that someone removed java manually instead of through chocolatey. Chocolatey makes its own database to track what it has installed, so it thinks that java is still installed. You can probably try `state: reinstalled` and to get it working again. Unfortunately, I don’t have enough experience with this to tell you how to detect false-positive chocolatey installs ahead of time.

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [March 15, 2024, 11:53pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/6 "2024-03-15T23:53:27Z")

</div>

If that’s the case, I would stat the installed binary to see if it exists. If it doesn’t, run the chocolatey module again with the `state: reinstall` flag.

Edit: Autocorrect changed “stat” to “stay”.

---

<div class="post-metadata">

**Author:** ![Saritha](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Saritha](https://forum.ansible.com/u/Saritha)\
**Post date:** [March 18, 2024, 1:36pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/7 "2024-03-18T13:36:31Z")

</div>

Thanks for the information. Will try and update

---

<div class="post-metadata">

**Author:** ![Saritha](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Saritha](https://forum.ansible.com/u/Saritha)\
**Post date:** [March 18, 2024, 1:37pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/8 "2024-03-18T13:37:46Z")

</div>

no worries. Thanks for checking

---

<div class="post-metadata">

**Author:** ![Saritha](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Saritha](https://forum.ansible.com/u/Saritha)\
**Post date:** [March 18, 2024, 9:20pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/9 "2024-03-18T21:20:36Z")

</div>

Thanks. The playbook worked after changing the state from present to reinstalled.  
But It would be great if we can add any condition to detect false-positive chocolatey installs just like you said

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [March 18, 2024, 9:24pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/10 "2024-03-18T21:24:43Z")

</div>

I think that’s what @Dustin was suggesting. You can use the `stat:` module to test if the java.exe binary exists where it’s supposed to be, and force a reinstall when it’s missing. Personally, I would prefer there be some native `choco validate` command or something that would scale to other application installs better, but I don’t know if anything like that exists.

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [March 18, 2024, 9:48pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/11 "2024-03-18T21:48:24Z")

</div>

I checked the [Chocolatey](https://docs.ansible.com/ansible/latest/collections/chocolatey/chocolatey/win_chocolatey_module.html) Documentation, and I didn’t see any reference to a module or parameter to verify a specific file to determine if the install was actually there.

I would recommend you open a feature request with the [chocolatey project](https://github.com/chocolatey/chocolatey-ansible) for your use case, to help Chocolately more intelligently determine install status.

As a workaround, I’d do something like the below playbook. Keep in mind, I’m doing this off the top of my head and not entirely familiar with Chocolately\_module. So, your mileage may vary.

```yaml
- name: install Java
  hosts: all
  tasks:
    - name: Install corretto17jdk
      win_chocolatey:
        name: corretto17jdk
        version: ‘17.X.X.X’
        state: present
      when: ansible_facts[‘os_family’] == “Windows”

    - name: Validate Executable Exists
      ansible.builtin.stat:
        path: /path/to/java/binary
      register: java

    - name: Force Reinstall if Binary Missing
      win_chocolatey:
        name: corretto17jdk
        version: ‘17.X.X.X’
        state: reinstalled
      when: ansible_facts[‘os_family’] == “Windows” and not java.stat.exists

```

Notice I install first, this will tackle first time installs. I re-install second, only if the java file does not exist. That way it will not re-install unless necessary.

---

<div class="post-metadata">

**Author:** ![Saritha](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Saritha](https://forum.ansible.com/u/Saritha)\
**Post date:** [May 16, 2024, 6:56pm UTC](https://forum.ansible.com/t/a-playbook-is-not-working-with-no-error-after-manual-removal-of-the-package-from-the-server/4357/12 "2024-05-16T18:56:52Z")

</div>

Sorry for the delay in reply . Got stuck in some other work.  
Thanks. will check this solution
