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

Issue:
fstab parameter of mount module won't work
##### Issue Type:
- Bug Report
##### Ansible Version:

ansible 2.0.0.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = /usr/share/ansible
##### Ansible Configuration:
##### Environment:

Ubuntu 14.04 64Bit
##### Summary:

set fstab=**/tmp/fstab** in mount module result in 'can't find mount point in **/etc/fstab**'
##### Steps To Reproduce:

```
./test-module -m ../lib/ansible/modules/core/system/mount.py -a "src=/dev/sda9 name=/tmp/mnt fstype=ext3 state=mounted **fstab=/tmp/fstab**"
```
##### Expected Results:

```
changed: ok
```

and a line in /tmp/fstab and 'mount -a' should show the mounted device
##### Actual Results:

```
***********************************
PARSED OUTPUT
{
    "failed": true, 
    "invocation": {
        "module_args": {
            "dump": null, 
            "fstab": **"/tmp/fstab"**, 
            "fstype": "ext3", 
            "name": "/tmp/mnt", 
            "opts": null, 
            "passno": null, 
            "src": "/dev/sda9", 
            "state": "mounted"
        }
    }, 
    "msg": "Error mounting /tmp/mnt: mount: /tmp/mnt konnte nicht in **/etc/fstab oder /etc/mtab** gefunden werden\n"
}
```



Discussion:

Resolving patch:
diff --git a/system/mount.py b/system/mount.py
--- a/system/mount.py
+++ b/system/mount.py
@@ -240,6 +240,9 @@ def mount(module, **kwargs):
     if get_platform().lower() == 'freebsd':
         cmd += [ '-F', args['fstab'], ]
 
+    if get_platform().lower() == 'linux':
+        cmd += [ '-T', args['fstab'], ]
+
     cmd += [ name, ]
 
     rc, out, err = module.run_command(cmd)


Test patch:
Repository: ansible/ansible-modules-core

Issue:
size parameter required set to be no when state is absent in os_volume
##### Issue Type:
- Documentation Report
##### Plugin Name:

os_volume 
##### Ansible Version:

```
2.4
```
##### Ansible Configuration:

<!-- Please mention any settings you've changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables). -->
##### Environment:

centos 6
##### Summary:

def _absent_volume(module, cloud):
    try:
        cloud.delete_volume(
            name_or_id=module.params['display_name'],
            wait=module.params['wait'],
            timeout=module.params['timeout'])

No need to add size parameter while calling os_volume as delete_volume function does not need size parameter .   http://docs.ansible.com/ansible/os_volume_module.html  this document needs to be modified. 
size parameter required set to be 'NO' when state is absent in os_volume  
##### Steps To Reproduce:

<!-- For bugs, please show exactly how to reproduce the problem.
For new features, show how the feature would be used.  -->

``````
<!-- (Paste example playbooks or commands here)  -->
``` - name: "Delete Volumes attached"
      os_volume:
        state: "absent"
        display_name: "{{ item.id }}"
        timeout: "360"
        auth:
          auth_url: "{{ openstack_auth_url }}"
          username: "{{ openstack_username }}"
          password: "{{ openstack_password }}"
          project_name: "{{ openstack_tenant }}"
      environment:
        OS_VOLUME_API_VERSION: "1"
        OS_IMAGE_API_VERSION: "1"
        security_groups: default

<!-- You can also paste gist.github.com links for larger files.  -->

##### Expected Results:

<!-- What did you expect to happen when running the steps above?  -->

##### Actual Results:

<!-- What actually happened? If possible run with high verbosity (-vvvv) -->

``````

<!-- (Paste verbatim command output here)  -->

```
```



Discussion:
cc @emonty @Shrews 

@bcoca This isn't actually a problem with the os_volume module. In the module, we have 'required' value set to "only when state is 'present'". The generated docs seem to turn this into a "yes" value, for some reason.


Resolving patch:
diff --git a/cloud/openstack/os_volume.py b/cloud/openstack/os_volume.py
--- a/cloud/openstack/os_volume.py
+++ b/cloud/openstack/os_volume.py
@@ -35,8 +35,9 @@
 options:
    size:
      description:
-        - Size of volume in GB
-     required: only when state is 'present'
+        - Size of volume in GB. This parameter is required when the
+          I(state) parameter is 'present'.
+     required: false
      default: None
    display_name:
      description:


Test patch:
Repository: ansible/ansible-modules-core

Issue:
ops_template.py: Take care of json src variable
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

ops_template.py
##### ANSIBLE VERSION

```
air$ ansible-playbook --version
ansible-playbook 2.1.0
  config file = /usr/local/git/github.com/dc-on-docker/ansible.cfg
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

As mentioned in [ansible/ansible #15133](https://github.com/ansible/ansible/issues/15133), configuring OpenSwitch through the [OpenSwitch switch role](https://github.com/keinohguchi/ops-switch-role).
##### OS / ENVIRONMENT

Reproduced on ArchLinux control machine, just like [ansible/ansible #15133](https://github.com/ansible/ansible/issues/15133).
##### SUMMARY

Call `module.from_json` in case of `dc` or `rest` transport case.
##### STEPS TO REPRODUCE

```

---
- name: fabric switches
  hosts: fabrics
  gather_facts: yes
  vars:
    ansible_user: admin
    ops_system_hostname: "{{ inventory_hostname }}"
    ops_debug: no
  roles:
    - role: switch
      ops_intf_admin_state: up

- name: spine switches
  hosts: spines
  gather_facts: yes
  vars:
    ansible_user: admin
    ops_system_hostname: "{{ inventory_hostname }}"
    ops_debug: no
  roles:
    - role: switch
      ops_intf_admin_state: up

- name: leaf switches
  hosts: leaves
  gather_facts: yes
  vars:
    ansible_user: admin
    ops_system_hostname: "{{ inventory_hostname }}"
    ops_debug: no
  roles:
    - role: switch
      ops_intf_admin_state: up
```
##### EXPECTED RESULTS

Configure the OPS switch both through DC or REST APIs.
##### ACTUAL RESULTS

```
air$ play site.yaml

PLAY [fabric switches] *********************************************************

TASK [setup] *******************************************************************
ok: [fab1]

TASK [switch : print JSON input for this play] *********************************
skipping: [fab1]

TASK [switch : configure the switch] *******************************************
fatal: [fab1]: FAILED! => {"changed": false, "failed": true, "msg": "argument src is of type <type 'str'> and we were unable to convert
to dict"}
```



Discussion:

Resolving patch:
diff --git a/network/openswitch/ops_template.py b/network/openswitch/ops_template.py
--- a/network/openswitch/ops_template.py
+++ b/network/openswitch/ops_template.py
@@ -168,7 +168,7 @@ def main():
     """
 
     argument_spec = dict(
-        src=dict(type='dict'),
+        src=dict(type='str'),
         force=dict(default=False, type='bool'),
         backup=dict(default=False, type='bool'),
         config=dict(type='dict'),
@@ -180,8 +180,6 @@ def main():
                         mutually_exclusive=mutually_exclusive,
                         supports_check_mode=True)
 
-    src = module.params['src']
-
     result = dict(changed=False)
 
     contents = get_config(module)
@@ -189,6 +187,7 @@ def main():
 
     if module.params['transport'] in ['ssh', 'rest']:
         config = contents
+        src = module.from_json(module.params['src'])
 
         changeset = diff(src, config)
         candidate = merge(changeset, config)


Test patch:
Repository: ansible/ansible-modules-core

Issue:
Virtual apt package is always marked as changed
<!--- Verify first that your issue/request is not already reported in GitHub -->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Bug Report
##### COMPONENT NAME

<!--- Name of the plugin/module/task -->
- apt module
##### ANSIBLE VERSION

2.0+
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

N/A
##### OS / ENVIRONMENT

<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->

Debian / apt specific
##### SUMMARY

<!--- Explain the problem briefly -->

Virtual apt packages are marked as changed even when there isn't actually any change.
This is related to https://github.com/ansible/ansible-modules-core/pull/1348/commits/adf34a6ccde75f32403d3d28a24f28ed9281c52a 
##### STEPS TO REPRODUCE

<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

```
$ ansible-playbook -i hosts playbook.yml --ask-pass --become --ask-become-pass

- hosts: all
  tasks:
    - package: name=libpng-dev state=latest

```

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

<!--- What did you expect to happen when running the steps above? -->

The task is not marked as changed after repeated runs (idempotency)
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with high verbosity (-vvvv) -->

The task is always marked as changed



Discussion:

Resolving patch:
diff --git a/packaging/os/apt.py b/packaging/os/apt.py
--- a/packaging/os/apt.py
+++ b/packaging/os/apt.py
@@ -269,7 +269,7 @@ def package_status(m, pkgname, version, cache, state):
                         installed, upgradable, has_files = package_status(m, package.name, version, cache, state='install')
                         if installed:
                             is_installed = True
-                    return is_installed, True, False
+                    return is_installed, upgradable, False
                 m.fail_json(msg="No package matching '%s' is available" % pkgname)
             except AttributeError:
                 # python-apt version too old to detect virtual packages


Test patch:
Repository: ansible/ansible-modules-core

Issue:
Filter also branch info in has_local_mods
##### ISSUE TYPE
- Bugfix Pull Request
##### COMPONENT NAME

git
##### ANSIBLE VERSION

```
ansible 2.0.1.0
```
##### SUMMARY

Filter also branch info in has_local_mods

If you have in the git configuration show branch enabled there will be always a change. 
The output of git status is for example:

  ## master...origin/master
  ?? untracked.file
   M changed.file



Discussion:
Thanks @martin-v for this PR. This module is maintained by the Ansible core team, so it can take a while for patches to be reviewed. Thanks for your patience.

Core team: please review according to guidelines (http://docs.ansible.com/ansible/developing_modules.html#module-checklist) and comment with 'needs_revision' or merge as appropriate.

[This message brought to you by your friendly Ansibull-bot.]


Resolving patch:
diff --git a/source_control/git.py b/source_control/git.py
--- a/source_control/git.py
+++ b/source_control/git.py
@@ -356,7 +356,7 @@ def has_local_mods(module, git_path, dest, bare):
     if bare:
         return False
 
-    cmd = "%s status -s" % (git_path)
+    cmd = "%s status --porcelain" % (git_path)
     rc, stdout, stderr = module.run_command(cmd, cwd=dest)
     lines = stdout.splitlines()
     lines = filter(lambda c: not re.search('^\\?\\?.*$', c), lines)


Test patch:
Repository: ansible/ansible-modules-core

Issue:
os_floating_ip errors if an ip is attached.
##### Issue Type:

Regression (so inevitably a feature idea).
##### Ansible Version:

ansible 2.0.0
##### Ansible Configuration:

```
< lookup_plugins = ./lookup_plugins:~/.ansible/plugins/lookup_plugins/:/usr/share/ansible_plugins/
< timeout = 120

---
> timeout = 10
```
##### Environment:

OSX -> Ubuntu
##### Summary:

If you add an ip with os_floating_ip to a server, when you rerun your play, it errors.
##### Steps To Reproduce:

```
- os_floating_ip:
    cloud: envvars
    state: present
    reuse: yes
    server: cwp-goserver-1
    network: vlan3320
    fixed_address: "{{ lookup('os_private_ip', 'cwp-goserver-1') }}"
    wait: true
    timeout: 180
```
##### Expected Results:

If the server already has a floating ip from the network, expect the task to pass, as unchanged.
##### Actual Results:

```
unable to bind a floating ip to server f23ce73c-82ad-490a-bf0e-7e3d23dce449: Cannot associate floating IP 10.12.71.112 (57a5b6e0-2843-4ec5-9388-408a098cdcc7) with port f2c6e8bb-b500-4ea0-abc8-980b34fc200f using fixed IP 192.168.101.36, as that fixed IP already has a floating IP on external network 8b3e1a76-f16c-461b-a5b5-f5987936426d
```



Discussion:
We also meet this issue. I think that the operation should be idempotent and if the floating address was already assigned, then it is not actually executed.
In my use case, I need to assign a constant floating ip to our load balancer. I couldn't find a solution yet (I don't know how to find if the floating ip was assigned because hostvars does not provide this information).

We are hitting this issue as well.
Trying to upgrade our playbooks to use 2.0, they fail on second run.

We've hit this as well. I dug into the code a bit, and there's nothing in `os_floating_ip` itself that tries to see if the task requested has already been completed, and there doesn't appear to be anything in Shade either to make this happen.

Given the complexities of this module, and the many different ways floating IPs can be requested/added/etc, it's not a simple matter of a few lines of code to check this.


Resolving patch:
diff --git a/cloud/openstack/os_floating_ip.py b/cloud/openstack/os_floating_ip.py
--- a/cloud/openstack/os_floating_ip.py
+++ b/cloud/openstack/os_floating_ip.py
@@ -163,6 +163,10 @@ def main():
                 msg="server {0} not found".format(server_name_or_id))
 
         if state == 'present':
+            fip_address = cloud.get_server_public_ip(server)
+            f_ip = _get_floating_ip(cloud, fip_address)
+            if f_ip:
+                module.exit_json(changed=False, floating_ip=f_ip)
             server = cloud.add_ips_to_server(
                 server=server, ips=floating_ip_address, ip_pool=network,
                 reuse=reuse, fixed_address=fixed_address, wait=wait,


Test patch:
Repository: ansible/ansible-modules-core

Issue:
Fix unarchive bug when unzipping an archive that has one or more file (#3792)
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->

Bugfix Pull Request
##### COMPONENT NAME

<!--- Name of the plugin/module/task  -->

unarchive
##### ANSIBLE VERSION

```
ansible 2.1.0.0
```
##### SUMMARY

<!--- Describe the change, including rationale and design decisions -->

Fixes #3792 

In the unarchive module within the ZipArchive class, there is an issue with the method `is_unarchived`. It is parsing the output of `unzip -ZT <source>` and breaking on files that have a space in them. The current method is to split each line at the space character and if the length of the array is not 8, it will assume it is the header or footer of the command's output. Instead, I removed the header and footer explicitly so we know each line represents a file in the archive. Furthermore, the final path is determined by removing the elements before it in the array, which will retain any spaces in the path.



Discussion:
Thanks @ethryx. To the current maintainers, @dagwieers, @pileofrogs please review according to guidelines (http://docs.ansible.com/ansible/developing_modules.html#module-checklist) and comment with text 'shipit', 'needs_revision' or 'close_me' as appropriate.

[This message brought to you by your friendly Ansibull-bot.]

Thanks for reporting this. Your analysis is correct, but your fix has the following issues:
- it assumes that the header and footer are only one line (my test just yet gave a 2-line header)
- it will only work for files with no more than one subsequent space

@dagwieers Thanks for the feedback. I'll revise the PR in a little bit to be able to handle those situations. In my testing, I only saw a 1-line header/footer -- sorry I didn't catch that.


Resolving patch:
diff --git a/files/unarchive.py b/files/unarchive.py
--- a/files/unarchive.py
+++ b/files/unarchive.py
@@ -312,13 +312,16 @@ def is_unarchived(self):
         for line in old_out.splitlines():
             change = False
 
-            pcs = line.split()
-            if len(pcs) != 8: continue
+            pcs = line.split(None, 7)
+
+            # Check first and seventh field in order to skip header/footer
+            if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue
+            if len(pcs[6]) != 15: continue
 
             ztype = pcs[0][0]
             permstr = pcs[0][1:10]
-            version = pcs[0][1]
-            ostype = pcs[0][2]
+            version = pcs[1]
+            ostype = pcs[2]
             size = int(pcs[3])
             path = pcs[7]
 


Test patch:
Repository: ansible/ansible-modules-core

Issue:
Bug in regex checker for azure_rm_virtualnetwork
##### ISSUE TYPE
- Feature Idea
##### COMPONENT NAME

azure_rm_virtualnetwork
##### ANSIBLE VERSION

2.2.0
##### CONFIGURATION

N/A
##### OS / ENVIRONMENT

Ubuntu 14.04
##### SUMMARY

azure_rm_virtualnetwork contains code to check for the validity of the "name" parameter (https://github.com/ansible/ansible-modules-core/blob/devel/cloud/azure/azure_rm_virtualnetwork.py#L148). That regex does not take into account that the "." character is valid, as long as it's neither at the start or end of the name string.
##### STEPS TO REPRODUCE

```
- name: Create virtual network
  azure_rm_virtualnetwork:
    name: My.Sweet.Network
```
##### EXPECTED RESULTS

The network should get created, since it has a valid name
##### ACTUAL RESULTS

msg": "Parameter error: name must begin with a letter or number, end with a letter, number or underscore and may contain only letters, numbers, periods, underscores or hyphens."}



Discussion:

Resolving patch:
diff --git a/cloud/azure/azure_rm_virtualnetwork.py b/cloud/azure/azure_rm_virtualnetwork.py
--- a/cloud/azure/azure_rm_virtualnetwork.py
+++ b/cloud/azure/azure_rm_virtualnetwork.py
@@ -145,7 +145,7 @@
     pass
 
 
-NAME_PATTERN = re.compile(r"^[a-zA-Z0-9_]{1,61}[a-z0-9_]$")
+NAME_PATTERN = re.compile(r"^[a-zA-Z0-9]+[a-zA-Z0-9\._-]+[a-zA-Z0-9_]+$")
 
 
 def virtual_network_to_dict(vnet):


Test patch:
Repository: ansible/ansible-modules-core

Issue:
junos_facts - config parameter should have a default value
##### COMPONENT NAME

module : junos_facts

```
network/junos_facts.py
```
##### ANSIBLE VERSION

2.1.0.0
##### OS / ENVIRONMENT

Mac OS 10.11.5
##### SUMMARY

Currently the parameter `config` for junos_facts is mandatory and do not have a default value
I think it would be better to set a default value to `false` and not make this parameter mandatory.

Playbooks will be simplified

I'm happy to send a pull request for it, but I wanted to discuss this change before



Discussion:
The commit https://github.com/ansible/ansible-modules-core/commit/a6dc526570f6b4bfddcb106998a25d5dc150e4f3 seems to have changed this.

It's a little hard to say, but since the commit message doesn't mention changing if 'config' is required or not, I suspect that may be unintended.

@privateip should 'config' be required here?


Resolving patch:
diff --git a/network/junos/junos_facts.py b/network/junos/junos_facts.py
--- a/network/junos/junos_facts.py
+++ b/network/junos/junos_facts.py
@@ -37,8 +37,8 @@
         is then included in return facts.  By default, the configuration
         is returned as text.  The C(config_format) can be used to return
         different Junos configuration formats.
-    required: true
-    default: false
+    required: false
+    default: null
   config_format:
     description:
       - The C(config_format) argument is used to specify the desired
@@ -90,7 +90,7 @@ def main():
     """ Main entry point for AnsibleModule
     """
     spec = dict(
-        config=dict(required=True, type='bool'),
+        config=dict(type='bool'),
         config_format=dict(default='text', choices=['xml', 'set', 'text']),
         transport=dict(default='netconf', choices=['netconf'])
     )
@@ -108,7 +108,7 @@ def main():
 
     facts['version_info'] = dict(facts['version_info'])
 
-    if module.params['config']:
+    if module.params['config'] is True:
         config_format = module.params['config_format']
         resp_config = module.get_config( config_format=config_format)
 


Test patch:
Repository: ansible/ansible-modules-core

Issue:
docker_image in ansible 2.1 forcefully tries to push image
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

docker_image
##### ANSIBLE VERSION

```
ansible 2.1.0.0
```
##### CONFIGURATION

Default
##### OS / ENVIRONMENT

Docker daemon:

```
Server:
 Version:      1.11.1
 API version:  1.23
```
##### SUMMARY

When building an image, docker_image always try to push image to repo.
##### STEPS TO REPRODUCE

```
- name: Build image
  docker_image:
    path: "/containers/test_container/build"
    name: "my/test_container"
    state: present
    pull: yes
```
##### EXPECTED RESULTS

Image `my/test_container:latest` is built locally. Period!
##### ACTUAL RESULTS

Image is built, but task fails when trying to upload it.

```
FAILED! => {"changed": false, "failed": true, "msg": "Error: configuration for docker.io not found. Try logging into docker.io first."}
```

Line of code in question: https://github.com/ansible/ansible-modules-core/blob/04a871d0070719a870286e22eb0a4a3bde8ecb4d/cloud/docker/docker_image.py#L270



Discussion:
I just hit this myself.  Looking at the linked file on line 278 it also looks as if it force a push even when it is loading an image from an archive.


Resolving patch:
diff --git a/cloud/docker/docker_image.py b/cloud/docker/docker_image.py
--- a/cloud/docker/docker_image.py
+++ b/cloud/docker/docker_image.py
@@ -191,11 +191,12 @@
     name: registry.ansible.com/chouseknecht/sinatra
     tag: v1
     load_path: my_sinatra.tar
+    push: True
 '''
 
 RETURN = '''
 image:
-    description: Image inspection results for the affected image. 
+    description: Image inspection results for the affected image.
     returned: success
     type: complex
     sample: {}
@@ -236,7 +237,7 @@ def __init__(self, client, results):
         self.state = parameters.get('state')
         self.tag = parameters.get('tag')
         self.http_timeout = parameters.get('http_timeout')
-        self.debug = parameters.get('debug') 
+        self.debug = parameters.get('debug')
         self.push = False
 
         if self.state in ['present', 'build']:
@@ -267,7 +268,6 @@ def present(self):
                 self.log("Building image %s" % image_name)
                 self.results['actions'].append("Built image %s from %s" % (image_name, self.path))
                 self.results['changed'] = True
-                self.push = True
                 if not self.check_mode:
                     self.results['image'] = self.build_image()
             elif self.load_path:
@@ -275,7 +275,6 @@ def present(self):
                 if not os.path.isfile(self.load_path):
                     self.fail("Error loading image %s. Specified path %s does not exist." % (self.name,
                                                                                              self.load_path))
-                self.push = True
                 image_name = self.name
                 if self.tag:
                     image_name = "%s:%s" % (self.name, self.tag)


Test patch: