internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: ansible/ansible

Issue:
ansible.cache missing from setup.py
Please add ansible.cache to packages list in setup.py

Current devel version gives import error because this is missing.



Discussion:
Actually we reverted this a while back, if you update again you shouldn't see any references to this.

There are still plenty of references to ansible.cache as of 57a6672:

```
[dvl] serge@goldorak:~/ansible$ grep ansible.cache lib/ansible/ -r
lib/ansible/playbook/__init__.py:import ansible.cache
lib/ansible/playbook/__init__.py:   SETUP_CACHE = ansible.cache.FactCache()
lib/ansible/utils/plugins.py:    'ansible.cache',
lib/ansible/runner/__init__.py:from ansible.cache import FactCache
lib/ansible/runner/__init__.py:            self.setup_cache = ansible.cache.FactCache()
```

I opened a new ticket #5611 


Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ec2_ami_find.py b/lib/ansible/modules/cloud/amazon/ec2_ami_find.py
--- a/lib/ansible/modules/cloud/amazon/ec2_ami_find.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_ami_find.py
@@ -357,7 +357,7 @@ def main():
     if hypervisor:
         filter['hypervisor'] = hypervisor
     if is_public:
-        filter['is_public'] = is_public
+        filter['is_public'] = 'true'
     if name:
         filter['name'] = name
     if platform:


Test patch:
Repository: ansible/ansible

Issue:
ec2_facts is not setting ansible_ec2_placement_region correctly for EC2 Canada


##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_facts

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.2.0.0
  config file =
  configured module search path = Default w/o overrides
```

##### CONFIGURATION
Default configuration

##### OS / ENVIRONMENT
N/A

##### SUMMARY
ec2_facts is not setting ansible_ec2_placement_region correctly when an instance is in any availability zone within `ca-central-1`, as it is including the AZ alphanumeric identifier.

##### STEPS TO REPRODUCE
Run ec2_facts on an instance booted in ca-central-1 and observe the value for `ansible_ec2_placement_region`.  It will be the same as `ansible_ec2_placement_availability_zone`

```
ansible localhost -m ec2_facts
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
`ansible_ec2_placement_region` should be `ca-central-1`

##### ACTUAL RESULTS
`ansible_ec2_placement_region` is `ca-central-1a`
ec2_facts is not setting ansible_ec2_placement_region correctly for EC2 Canada


##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_facts

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.2.0.0
  config file =
  configured module search path = Default w/o overrides
```

##### CONFIGURATION
Default configuration

##### OS / ENVIRONMENT
N/A

##### SUMMARY
ec2_facts is not setting ansible_ec2_placement_region correctly when an instance is in any availability zone within `ca-central-1`, as it is including the AZ alphanumeric identifier.

##### STEPS TO REPRODUCE
Run ec2_facts on an instance booted in ca-central-1 and observe the value for `ansible_ec2_placement_region`.  It will be the same as `ansible_ec2_placement_availability_zone`

```
ansible localhost -m ec2_facts
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
`ansible_ec2_placement_region` should be `ca-central-1`

##### ACTUAL RESULTS
`ansible_ec2_placement_region` is `ca-central-1a`


Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ec2_facts.py b/lib/ansible/modules/cloud/amazon/ec2_facts.py
--- a/lib/ansible/modules/cloud/amazon/ec2_facts.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_facts.py
@@ -70,6 +70,7 @@ class Ec2Metadata(object):
                    'ap-southeast-1',
                    'ap-southeast-2',
                    'ap-south-1',
+                   'ca-central-1',
                    'eu-central-1',
                    'eu-west-1',
                    'sa-east-1',


Test patch:
Repository: ansible/ansible

Issue:
systemd module doesn't stop service with ActiveState=activating
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
systemd

##### ANSIBLE VERSION
```
2.2.0.0
```

##### OS / ENVIRONMENT
Ubuntu 16.04

##### SUMMARY
systemd module doesn't stop service with ActiveState=activating.

##### STEPS TO REPRODUCE
1. Create a service **test_svc** which should not start correctly and have to be restarted by systemd infinitely.
1. Start service **test_svc**.
1. Invoke systemd module with service=**test_svc** and state=stopped.
  ```ansible localhost -m systemd -a "service=test_svc state=stopped"```

**test_svc.service:**
```ini
[Service]
Type=notify
ExecStart=/bin/bash -c "sleep 5; exit 1"
Restart=always
```

##### EXPECTED RESULTS
The service should be stopped.

##### ACTUAL RESULTS
```
The service stuck in a restart loop.
```



Discussion:
There is similar bug https://github.com/ansible/ansible-modules-core/issues/2265

Resolving patch:
diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py
--- a/lib/ansible/modules/system/systemd.py
+++ b/lib/ansible/modules/system/systemd.py
@@ -239,6 +239,11 @@
 from ansible.module_utils.service import sysv_exists, sysv_is_enabled, fail_if_missing
 from ansible.module_utils._text import to_native
 
+
+def is_running_service(service_status):
+    return service_status['ActiveState'] in set(['active', 'activating'])
+
+
 # ===========================================
 # Main control flow
 
@@ -382,13 +387,13 @@ def main():
         if 'ActiveState' in result['status']:
             action = None
             if module.params['state'] == 'started':
-                if result['status']['ActiveState'] != 'active':
+                if not is_running_service(result['status']):
                     action = 'start'
             elif module.params['state'] == 'stopped':
-                if result['status']['ActiveState'] == 'active':
+                if is_running_service(result['status']):
                     action = 'stop'
             else:
-                if result['status']['ActiveState'] != 'active':
+                if not is_running_service(result['status']):
                     action = 'start'
                 else:
                     action = module.params['state'][:-2] # remove 'ed' from restarted/reloaded


Test patch:
Repository: ansible/ansible

Issue:
ansible_service_mgr and grsecurity
##### ISSUE TYPE
 - Bug Report
 
##### COMPONENT NAME
ansible_service_mgr detection

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.2.0.0
  config file = /Users/xxx/work/xxx/ansible/ansible.cfg
  configured module search path = Default w/o overrides
```

##### CONFIGURATION
I think nothing in the configuration is relevant to this issure, but here is the ansible.cfg

[defaults]
remote_user = xxx
host_key_checking = False
inventory = inventory/
roles_path = roles.galaxy:roles
vault_password_file = vault.key

[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=15m -F ssh.config -q
scp_if_ssh = True
control_path = /tmp/mux-%%r@%%h:%%p
pipelining = True

##### OS / ENVIRONMENT
Running Ansible from macOS. Managing CentOS 6.x and 7.x hosts with grsecurity patches. 

The server is running the standard kernel from hosting provider OVH, which includes the following settings:

    CONFIG_GRKERNSEC_PROC=y
    CONFIG_GRKERNSEC_PROC_USER=y

##### SUMMARY
When Ansible collects facts, it attempts to read the init system from `/proc/1/comm`
and then with `ps -p 1 -o comm|tail -n 1`. This fails for `CONFIG_GRKERNSEC_PROC_USER=y`

##### STEPS TO REPRODUCE
With the grsecurity patches configured with `CONFIG_GRKERNSEC_PROC_USER=y`, `/proc` is only readable by root, and normal users can only view their own processes. The read of `/proc/1/comm` fails with no file found, which is fine. The ps command, however, returns an "empty" result with just the header "COMMAND", causing `ansible_service_mgr` to be set to `COMMAND`. Here is an example of what ps returns for a regular user and for root. 

    $ ps -p 1 -o comm
    COMMAND

    # ps -p 1 -o comm
    COMMAND
    init

```
ansible foo-server -m setup -a 'filter=ansible_service_mgr'
```

##### EXPECTED RESULTS
`ansible_service_mgr` should be set to e.g. "systemd"

##### ACTUAL RESULTS
`ansible_service_mgr` is "COMMAND"

```
foo-server | SUCCESS => {
    "ansible_facts": {
        "ansible_service_mgr": "COMMAND"
    },
    "changed": false
}
```



Discussion:
@reachfh do you want to resubmit/re open the PR?

Resolving patch:
diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py
--- a/lib/ansible/module_utils/facts.py
+++ b/lib/ansible/module_utils/facts.py
@@ -335,6 +335,10 @@ def get_service_mgr_facts(self):
             if re.match(r' *[0-9]+ ', proc_1):
                 proc_1 = None
 
+        # The ps command above may return "COMMAND" if the user cannot read /proc, e.g. with grsecurity
+        if proc_1 == "COMMAND\n":
+            proc_1 = None
+
         if proc_1 is not None:
             proc_1 = os.path.basename(proc_1)
             proc_1 = to_native(proc_1)


Test patch:
Repository: ansible/ansible

Issue:
Add 'unprivileged container' support to proxmox module
Since proxmox 4.4 it's possible to create unprivileged containers.

##### ISSUE TYPE
 - Feature Idea

##### COMPONENT NAME
proxmox

##### ANSIBLE VERSION

```
ansible 2.3.0 (devel 48dee1b6d0) last updated 2016/12/18 10:46:14 (GMT -300)
```

##### SUMMARY
Add 'unprivileged container' support to proxmox module




Discussion:
cc @UnderGreen
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/misc/proxmox.py b/lib/ansible/modules/cloud/misc/proxmox.py
--- a/lib/ansible/modules/cloud/misc/proxmox.py
+++ b/lib/ansible/modules/cloud/misc/proxmox.py
@@ -180,6 +180,11 @@
       - Public key to add to /root/.ssh/authorized_keys. This was added on Proxmox 4.2, it is ignored for earlier versions
     version_added: "2.3"
     default: null
+  unprivileged:
+    version_added: "2.3"
+    description:
+      - Indicate if the container should be unprivileged
+    default: false
     required: false
 
 notes:
@@ -441,7 +446,8 @@ def main():
           timeout = dict(type='int', default=30),
           force = dict(type='bool', default='no'),
           state = dict(default='present', choices=['present', 'absent', 'stopped', 'started', 'restarted']),
-          pubkey = dict(type='str', default=None)
+          pubkey = dict(type='str', default=None),
+          unprivileged = dict(type='bool', default='no')
           )
   )
 
@@ -517,8 +523,8 @@ def main():
                       nameserver = module.params['nameserver'],
                       searchdomain = module.params['searchdomain'],
                       force = int(module.params['force']),
-                      pubkey = module.params['pubkey']
-                 )
+                      pubkey = module.params['pubkey'],
+                      unprivileged = int(module.params['unprivileged']))
 
       module.exit_json(changed=True, msg="deployed VM %s from template %s"  % (vmid, module.params['ostemplate']))
     except Exception as e:


Test patch:
Repository: ansible/ansible

Issue:
Cron - Module Failure
##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME

cron module

##### SUMMARY
While doing:
```
- name: Crontab Setting for Program
  cron: name="Check Program is running" minute="*/7" user="test"
        job='bash -c "source {{ homedir }}/.bashrc && $TEST_HOME/bin/Program.sh start" > /dev/null'
```
##### ANSIBLE VERSION
```ansible 2.3.0 (devel 39c2249e49)```


##### OS / ENVIRONMENT
CentOS 3.10.0-327.36.2.el7.x86_64


##### ACTUAL RESULTS
It sets the Crontab as:
```
#Ansible: Check Program is running
*/7 * * * * bash -c "source /home/test/.bashrc && $TEST_HOME/ARL/Program.sh start" > /dev/null
```

but returns back with:
```
 FAILED! => {"changed": false, "failed": true, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_vHdMFc/ansible_module_cron.py\", line 773, in <module>\r\n    main()\r\n  File \"/tmp/ansible_vHdMFc/ansible_module_cron.py\", line 741, in main\r\n    crontab.write()\r\n  File \"/tmp/ansible_vHdMFc/ansible_module_cron.py\", line 345, in write\r\n    selinux.selinux_lsetfilecon_default(self.cron_file)\r\nOSError: [Errno 14] Bad address\r\n", "msg": "MODULE FAILURE"
```



Discussion:
cc @dsummersl, @EvanK
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/system/cron.py b/lib/ansible/modules/system/cron.py
--- a/lib/ansible/modules/system/cron.py
+++ b/lib/ansible/modules/system/cron.py
@@ -237,12 +237,6 @@
 import platform
 import pipes
 
-try:
-    import selinux
-    HAS_SELINUX = True
-except ImportError:
-    HAS_SELINUX = False
-
 CRONCMD = "/usr/bin/crontab"
 
 class CronTabError(Exception):
@@ -345,8 +339,8 @@ def write(self, backup_file=None):
                 self.module.fail_json(msg=err)
 
         # set SELinux permissions
-        if HAS_SELINUX:
-            selinux.selinux_lsetfilecon_default(self.cron_file)
+        if self.module.selinux_enabled() and self.cron_file:
+            self.module.set_default_selinux_context(self.cron_file, False)
 
     def do_comment(self, name):
         return "%s%s" % (self.ansible, name)


Test patch:
Repository: ansible/ansible

Issue:
yum_repository does not remove repo cache when removing repo
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Feature Idea

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
yum_repository

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
v2.2

##### SUMMARY
<!--- Explain the problem briefly -->
When removing a yum repository using the yum_repository module, the repository metadata (cache) is left behind in */var/cache/yum*. It would be nice if the module would make sure nothing is left behind.


Discussion:
cc @jtyr
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I usually `notify` a handler from the `yum_repository` task to clear **all** YUM repo caches. That has the advantage that even if you do not remove any repo but only change the URL, the cache will be cleared assuring that you get the right list of packages. Another advantage is that the clear command is called only once even if multiple repos was modified.

If we go the road to clear cache in the module, we would need to cover removal and change of the URL (`baseurl`, `mirrorlist`) which would bring more complexity to the module. We would probably also have to start using the `yum` python module which would add another dependency to the module. Not sure if that's worth the effort.

Resolving patch:
diff --git a/lib/ansible/modules/packaging/os/yum_repository.py b/lib/ansible/modules/packaging/os/yum_repository.py
--- a/lib/ansible/modules/packaging/os/yum_repository.py
+++ b/lib/ansible/modules/packaging/os/yum_repository.py
@@ -398,6 +398,8 @@
   - Parameters in a section are ordered alphabetically in an existing repo
     file.
   - The repo file will be automatically deleted if it contains no repository.
+  - When removing a repository, beware that the metadata cache may still remain
+    on disk until you run C(yum clean all). Use a notification handler for this.
 '''
 
 EXAMPLES = '''
@@ -424,10 +426,18 @@
     mirrorlist: http://mirrorlist.repoforge.org/el7/mirrors-rpmforge
     enabled: no
 
-- name: Remove repository
+# Handler showing how to clean yum metadata cache
+- name: yum-clean-metadata
+  command: yum clean metadata
+  args:
+    warn: no
+
+# Example removing a repository and cleaning up metadata cache
+- name: Remove repository (and clean up left-over metadata)
   yum_repository:
     name: epel
     state: absent
+  notify: yum-clean-all
 
 - name: Remove repository from a specific repo file
   yum_repository:


Test patch:
Repository: ansible/ansible

Issue:
Timezone module cannot set timezone in not systemd based system
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
/ansible/lib/ansible/modules/system/timezone.py

##### ANSIBLE VERSION

```
ansible 2.2.0.0
```

##### CONFIGURATION

##### OS / ENVIRONMENT
Running on MacOS 10.12.2
Managing Ubuntu 12.04.5 LTS

##### SUMMARY
In not systemd based system got
python error "global name 'tzfile' is not defined"

##### STEPS TO REPRODUCE
Run task 
```yaml

- name: "Set timezone to Europe/Moscow"
  timezone: name=Europe/Moscow
  notify: restart crond

```

##### EXPECTED RESULTS
Changing timezone

##### ACTUAL RESULTS

```
TASK [base : Set timezone to Europe/Moscow] ************************************
fatal: [192.168.111.222]: FAILED! => {"changed": false, "failed": true, "module_stderr": "BECOME-SUCCESS-bwdmdhqcljigltaovfhqflvkvyfvdzgl", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_MZQdNh/ansible_module_timezone.py\", line 462, in <module>\r\n    main()\r\n  File \"/tmp/ansible_MZQdNh/ansible_module_timezone.py\", line 435, in main\r\n    tz = Timezone(module)\r\n  File \"/tmp/ansible_MZQdNh/ansible_module_timezone.py\", line 306, in __init__\r\n    self.update_timezone += ' %s /etc/localtime' % tzfile\r\nNameError: global name 'tzfile' is not defined\r\n", "msg": "MODULE FAILURE"}

```



Discussion:
cc @tmshn
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@tyouxa Thanks for report!

With my quick check, I noticed that [this modification](https://github.com/ansible/ansible-modules-extras/pull/3337) has gone 💥  when [ansible/ansible-modules-extras](https://github.com/ansible/ansible-modules-extras) repo has merged.

I'll fix this within a few days 💪 

Resolving patch:
diff --git a/lib/ansible/modules/system/timezone.py b/lib/ansible/modules/system/timezone.py
--- a/lib/ansible/modules/system/timezone.py
+++ b/lib/ansible/modules/system/timezone.py
@@ -229,6 +229,7 @@ def _verify_timezone(self):
         tzfile = '/usr/share/zoneinfo/%s' % tz
         if not os.path.isfile(tzfile):
             self.abort('given timezone "%s" is not available' % tz)
+        return tzfile
 
 
 class SystemdTimezone(Timezone):
@@ -307,7 +308,7 @@ def __init__(self, module):
         super(NosystemdTimezone, self).__init__(module)
         # Validate given timezone
         if 'name' in self.value:
-            self._verify_timezone()
+            tzfile = self._verify_timezone()
             self.update_timezone  = self.module.get_bin_path('cp', required=True)
             self.update_timezone += ' %s /etc/localtime' % tzfile
         self.update_hwclock = self.module.get_bin_path('hwclock', required=True)


Test patch:
Repository: ansible/ansible

Issue:
Fix for #19265
##### ISSUE TYPE
 - Bugfix Pull Request

##### COMPONENT NAME
lib/ansible/module_utils/urls.py
##### ANSIBLE VERSION
```
ansible 2.2.0.0
  config file = /Users/regs/work/pantsibot/ansible.cfg
  configured module search path = ['./library']
```

##### SUMMARY
Renders string output to UTF-8 encoded bytes, appropriate for passing to `os.write()` in Python 3.5.





Discussion:
Fix for issue described in #19265 

Resolving patch:
diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py
--- a/lib/ansible/module_utils/urls.py
+++ b/lib/ansible/module_utils/urls.py
@@ -309,7 +309,7 @@ def match_hostname(cert, hostname):
 # ca cert, regardless of validity, for Python on Mac OS to use the
 # keychain functionality in OpenSSL for validating SSL certificates.
 # See: http://mercurial.selenic.com/wiki/CACertificates#Mac_OS_X_10.6_and_higher
-DUMMY_CA_CERT = """-----BEGIN CERTIFICATE-----
+b_DUMMY_CA_CERT = b("""-----BEGIN CERTIFICATE-----
 MIICvDCCAiWgAwIBAgIJAO8E12S7/qEpMA0GCSqGSIb3DQEBBQUAMEkxCzAJBgNV
 BAYTAlVTMRcwFQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEPMA0GA1UEBxMGRHVyaGFt
 MRAwDgYDVQQKEwdBbnNpYmxlMB4XDTE0MDMxODIyMDAyMloXDTI0MDMxNTIyMDAy
@@ -326,7 +326,7 @@ def match_hostname(cert, hostname):
 qFy+aenWXsC0ZvrikFxbQnX8GVtDADtVznxOi7XzFw7JOxdsVrpXgSN0eh0aMzvV
 zKPZsZ2miVGclicJHzm5q080b1p/sZtuKIEZk6vZqEg=
 -----END CERTIFICATE-----
-"""
+""")
 
 #
 # Exceptions
@@ -603,7 +603,7 @@ def get_ca_certs(self):
 
         # Write the dummy ca cert if we are running on Mac OS X
         if system == 'Darwin':
-            os.write(tmp_fd, DUMMY_CA_CERT)
+            os.write(tmp_fd, b_DUMMY_CA_CERT)
             # Default Homebrew path for OpenSSL certs
             paths_checked.append('/usr/local/etc/openssl')
 


Test patch:
Repository: ansible/ansible

Issue:
cs_iso:  state=absent does not poll the async job API
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
cs_iso

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
2.0, 2.1, 2.2, devel
```

##### CONFIGURATION
"N/A"

##### OS / ENVIRONMENT
"N/A"

##### SUMMARY
 state=absent does not poll the async job API, results in return successful even if the job fails

##### STEPS TO REPRODUCE
cs cli returns an error but cs_iso returns success.

```yaml
cs --region macloud-admin deleteIso id=436eecf2-0690-43ec-b398-0bd3e3d3b66c
Polling result... ^C to abort
{
 "accountid": "dff1f7d8-4e01-11e4-bb66-0050569e64b8",
 "cmd": "org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd",
 "created": "2017-01-09T14:39:27+0100",
 "jobid": "2e21b719-82b2-4e42-a511-dfdc37c19b4a",
 "jobinstanceid": "436eecf2-0690-43ec-b398-0bd3e3d3b66c",
 "jobinstancetype": "Iso",
 "jobprocstatus": 0,
 "jobresult": {
   "errorcode": 530,
   "errortext": "Failed to delete ISO"
 },
 "jobresultcode": 530,
 "jobresulttype": "object",
 "jobstatus": 2,
 "userid": "dff2677c-4e01-11e4-bb66-0050569e64b8"
}
```

reported by @onitake


Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/cloud/cloudstack/cs_iso.py b/lib/ansible/modules/cloud/cloudstack/cs_iso.py
--- a/lib/ansible/modules/cloud/cloudstack/cs_iso.py
+++ b/lib/ansible/modules/cloud/cloudstack/cs_iso.py
@@ -109,6 +109,12 @@
     required: false
     default: 'present'
     choices: [ 'present', 'absent' ]
+  poll_async:
+    description:
+      - Poll async jobs until job has finished.
+    required: false
+    default: true
+    version_added: "2.3"
 extends_documentation_fragment: cloudstack
 '''
 
@@ -244,6 +250,8 @@ def register_iso(self):
             self.result['changed'] = True
             if not self.module.check_mode:
                 res = self.cs.registerIso(**args)
+                if 'errortext' in res:
+                    self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
                 iso = res['iso'][0]
         return iso
 
@@ -288,6 +296,11 @@ def remove_iso(self):
 
             if not self.module.check_mode:
                 res = self.cs.deleteIso(**args)
+                if 'errortext' in res:
+                    self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
+                poll_async = self.module.params.get('poll_async')
+                if poll_async:
+                    self.poll_job(res, 'iso')
         return iso
 
 
@@ -309,6 +322,7 @@ def main():
         is_featured = dict(type='bool', default=False),
         is_dynamically_scalable = dict(type='bool', default=False),
         state = dict(choices=['present', 'absent'], default='present'),
+        poll_async = dict(type='bool', default=True),
     ))
 
     module = AnsibleModule(


Test patch: