Disable ACS in a playbook?

Somewhat new to more complex Ansible playbooks, and I am looking for a way to disable ACS via a playbook. We've previously been using a bash script:

for BDF in `lspci -d "*:*:*" | awk '{print $1}'`; do
  # skip if it doesn't support ACS
  sudo setpci -v -s ${BDF} ECAP_ACS+0x6.w > /dev/null 2>&1
  if [ $? -ne 0 ]; then
    continue
  fi
  sudo setpci -v -s ${BDF} ECAP_ACS+0x6.w=0000
done

Instead of using a playbook to execute the shell script I am trying to move this into the polybook itself. I've got a way to register the devices into a variable. Any ideas for running a command over the variable and running the second command if the first returns non zero status?