BIOS update succeeds, but shows as ansible failure

Hello all.

Here’s a simple one, I think, which is non-fatal, but I’d like to clean it up. I want to push BIOS updates to our Dell desktops, and have created a playbook for that purpose:

  • hosts: all

gather_facts: false

tasks:

  • name: Copy Dell BIOS update to desktop
    win_copy: src=/etc/ansible/files/OptiPlex_7040_1.8.1.exe dest=‘C:/temp/OptiPlex_7040_1.8.1.exe’
  • name: Install Dell BIOS update
    raw: c:\windows\system32\cmd.exe /C “c:\temp\OptiPlex_7040_1.8.1.exe /s /r /f”

When I run it, BIOS does get updated. However, since the update really happens after the desktops reboot, Ansible sees it as a failure:

fatal: [conference03]: FAILED! => {“changed”: true, “failed”: true, “rc”: 6, “stderr”: “”, “stdout”: “”, “stdout_lines”: }

Is there a way for this not to show as a failure?

Also, I’d like to extend the playbook to delete the BIOS update executable from the desktops. Again, since the desktops have rebooted, the playbook end before the delete can happen. How can I deal with that?

Thanks.

A few different things

  • I would avoid using the key=value options for Windows, it screws around with paths and you are forces to either escape backslashes with \ or use forward slashes which don’t work in all cases
  • I would use win_command to execute commands instead of raw (unless you are on a version older than 2.2)
  • No need to call cmd.exe when you are executing a variable, just another interpreter that can mess up your arguments
  • It is failing as the return code is not 0, in this case you are getting 6 as the rc

Obviously the rc of 6 means something and you probably need to find out what it is but if it is valid you can do;

`

  • name; Copy Dell BIOS update to desktop
    win_copy:
    src: /etc/ansible/files/OptiPlex_7040_1.8.1.exe
    dest: C:\temp\OptiPlex_7040_1.8.1.exe

  • name: Install Dell BIOS update
    win_command: C:\temp\OptiPlex_7040_1.8.1.exe /s /r /f
    register: bios_result
    failed_when: bios_result.rc != 6
    `

You could also have the following failed_when so it doesn’t fail if the RC is 0 or 6: ‘failed_when: bios_result.rc not in [0, 6]’

Thanks

Jordan

Jordan, thanks for the reply!

I’ll try the suggestions you mentioned:

  • I’ll consider taking a different approach vis-a-vis key-value pairs (just sticking with what I’ve used for a long time);
  • use win_command instead of raw (again, I’ve been using raw for so long the it’s etched in my mind);
  • OK on the use of cmd.exe;
  • I have no idea what an rc of 6 means. The ansible-playbook man page doesn’t list a return code of 6. Googling hasn’t turned up anything.

No worries, they were merely suggestions, the raw/win_command side is probably more important once you get into setting environment variables or using become (they don’t work with raw).

The return code is completely independent of Ansible and is what the executable returned, usually 0 means that is was successful and non 0 is a failure. Unfortunately there is no standard what each return code means and it is completely based on the executable you are running. In this case I would probably contact dell to see what it may mean.

One thing that may have muddied the water a bit was that it was running through cmd, while I believe it just passes through the return value, it might be a good idea to check what the RC is when running it without cmd.exe /c.

Thanks

Jordan