We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pkgutil: the values of update_catalog get always translated to true or false, but the module expects yes or no.
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

packaging/os/pkgutil.py
##### ANSIBLE VERSION

```
ansible 2.1.0.0-RC1
ansible 2.1.0.0 (detached HEAD 5954a82dd6) last updated 2016/05/02 13:45:40 (GMT +200)
  lib/ansible/modules/core: (detached HEAD ce79e7c72d) last updated 2016/05/02 13:46:30 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 156a8cd0b3) last updated 2016/05/02 13:46:30 (GMT +200)
```
##### CONFIGURATION
##### OS / ENVIRONMENT

Running on MacOS X 10.11.4 against Solaris 10
##### SUMMARY

Argument update_catalog gets wrong values false and true instead of no and yes 
##### STEPS TO REPRODUCE

```
ansible myhost -m pkgutil -a "name=CSWgnupg state=present" -u root
myhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "name": "CSWgnupg", 
            "state": "present", 
            "update_catalog": false
        }, 
        "module_name": "pkgutil"
    }, 
    "msg": "value of update_catalog must be one of: yes,no, got: False"
}
```
##### EXPECTED RESULTS

CSW package gnupg should be installed.
##### ACTUAL RESULTS

The values of update_catalog get always translated to true or false, but the module expects yes or no.

```
ansible myhost -m pkgutil -a "name=CSWgnupg state=present" -u root
myhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "name": "CSWgnupg", 
            "state": "present", 
            "update_catalog": false
        }, 
        "module_name": "pkgutil"
    }, 
    "msg": "value of update_catalog must be one of: yes,no, got: False"
}

ansible myhost -m pkgutil -a "name=CSWgnupg state=present update_catalog=no" -u root
myhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "name": "CSWgnupg", 
            "state": "present", 
            "update_catalog": false
        }, 
        "module_name": "pkgutil"
    }, 
    "msg": "value of update_catalog must be one of: yes,no, got: False"
}

ansible myhost -m pkgutil -a "name=CSWgnupg state=present update_catalog=false" -u root
myhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "name": "CSWgnupg", 
            "state": "present", 
            "update_catalog": false
        }, 
        "module_name": "pkgutil"
    }, 
    "msg": "value of update_catalog must be one of: yes,no, got: False"
}

ansible myhost -m pkgutil -a "name=CSWgnupg state=present update_catalog=yes" -u root
myhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "name": "CSWgnupg", 
            "state": "present", 
            "update_catalog": true
        }, 
        "module_name": "pkgutil"
    }, 
    "msg": "value of update_catalog must be one of: yes,no, got: True"
}

ansible myhost -m pkgutil -a "name=CSWgnupg state=present update_catalog=true" -u root 
myhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "msg": "value of update_catalog must be one of: yes,no, got: True"
}
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `packaging/os/pkgutil.py`
Content:
```
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 
4 # (c) 2013, Alexander Winkler <mail () winkler-alexander.de>
5 # based on svr4pkg by
6 #  Boyd Adamson <boyd () boydadamson.com> (2012)
7 #
8 # This file is part of Ansible
9 #
10 # Ansible is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Ansible is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
22 #
23 
24 DOCUMENTATION = '''
25 ---
26 module: pkgutil 
27 short_description: Manage CSW-Packages on Solaris
28 description:
29     - Manages CSW packages (SVR4 format) on Solaris 10 and 11.
30     - These were the native packages on Solaris <= 10 and are available
31       as a legacy feature in Solaris 11.
32     - Pkgutil is an advanced packaging system, which resolves dependency on installation.
33       It is designed for CSW packages.
34 version_added: "1.3"
35 author: "Alexander Winkler (@dermute)"
36 options:
37   name:
38     description:
39       - Package name, e.g. (C(CSWnrpe))
40     required: true
41   site:
42     description:
43       - Specifies the repository path to install the package from.
44       - Its global definition is done in C(/etc/opt/csw/pkgutil.conf).
45     required: false
46   state:
47     description:
48       - Whether to install (C(present)), or remove (C(absent)) a package.
49       - The upgrade (C(latest)) operation will update/install the package to the latest version available.
50       - "Note: The module has a limitation that (C(latest)) only works for one package, not lists of them."
51     required: true
52     choices: ["present", "absent", "latest"]
53   update_catalog:
54     description:
55       - If you want to refresh your catalog from the mirror, set this to (C(yes)).
56     required: false
57     choices: ["yes", "no"]
58     default: no
59     version_added: "2.1"
60 '''
61 
62 EXAMPLES = '''
63 # Install a package
64 pkgutil: name=CSWcommon state=present
65 
66 # Install a package from a specific repository
67 pkgutil: name=CSWnrpe site='ftp://myinternal.repo/opencsw/kiel state=latest'
68 '''
69 
70 import os
71 import pipes
72 
73 def package_installed(module, name):
74     cmd = ['pkginfo']
75     cmd.append('-q')
76     cmd.append(name)
77     rc, out, err = run_command(module, cmd)
78     if rc == 0:
79         return True
80     else:
81         return False
82 
83 def package_latest(module, name, site):
84     # Only supports one package
85     cmd = [ 'pkgutil', '-U', '--single', '-c' ]
86     if site is not None:
87         cmd += [ '-t', site]
88     cmd.append(name)
89     rc, out, err = run_command(module, cmd)
90     # replace | tail -1 |grep -v SAME
91     # use -2, because splitting on \n create a empty line
92     # at the end of the list
93     return 'SAME' in out.split('\n')[-2]
94 
95 def run_command(module, cmd, **kwargs):
96     progname = cmd[0]
97     cmd[0] = module.get_bin_path(progname, True, ['/opt/csw/bin'])
98     return module.run_command(cmd, **kwargs)
99 
100 def package_install(module, state, name, site, update_catalog):
101     cmd = [ 'pkgutil', '-iy' ]
102     if update_catalog:
103         cmd += [ '-U' ]
104     if site is not None:
105         cmd += [ '-t', site ]
106     if state == 'latest':
107         cmd += [ '-f' ] 
108     cmd.append(name)
109     (rc, out, err) = run_command(module, cmd)
110     return (rc, out, err)
111 
112 def package_upgrade(module, name, site, update_catalog):
113     cmd = [ 'pkgutil', '-ufy' ]
114     if update_catalog:
115         cmd += [ '-U' ]
116     if site is not None:
117         cmd += [ '-t', site ]
118     cmd.append(name)
119     (rc, out, err) = run_command(module, cmd)
120     return (rc, out, err)
121 
122 def package_uninstall(module, name):
123     cmd = [ 'pkgutil', '-ry', name]
124     (rc, out, err) = run_command(module, cmd)
125     return (rc, out, err)
126 
127 def main():
128     module = AnsibleModule(
129         argument_spec = dict(
130             name = dict(required = True),
131             state = dict(required = True, choices=['present', 'absent','latest']),
132             site = dict(default = None),
133             update_catalog = dict(required = False, default = "no", type='bool', choices=["yes","no"]),
134         ),
135         supports_check_mode=True
136     )
137     name = module.params['name']
138     state = module.params['state']
139     site = module.params['site']
140     update_catalog = module.params['update_catalog']
141     rc = None
142     out = ''
143     err = ''
144     result = {}
145     result['name'] = name
146     result['state'] = state
147 
148     if state == 'present':
149         if not package_installed(module, name):
150             if module.check_mode:
151                 module.exit_json(changed=True)
152             (rc, out, err) = package_install(module, state, name, site, update_catalog)
153             # Stdout is normally empty but for some packages can be
154             # very long and is not often useful
155             if len(out) > 75:
156                 out = out[:75] + '...'
157             if rc != 0:
158                 if err:
159                     msg = err
160                 else:
161                     msg = out
162                 module.fail_json(msg=msg)
163 
164     elif state == 'latest':
165         if not package_installed(module, name):
166             if module.check_mode:
167                 module.exit_json(changed=True)
168             (rc, out, err) = package_install(module, state, name, site, update_catalog)
169             if len(out) > 75:
170                 out = out[:75] + '...'
171             if rc != 0:
172                 if err:
173                     msg = err
174                 else:
175                     msg = out
176                 module.fail_json(msg=msg)
177 
178         else:
179             if not package_latest(module, name, site):
180                 if module.check_mode:
181                     module.exit_json(changed=True) 
182                 (rc, out, err) = package_upgrade(module, name, site, update_catalog)
183                 if len(out) > 75:
184                     out = out[:75] + '...'
185                 if rc != 0:
186                     if err:
187                         msg = err
188                     else:
189                         msg = out
190                     module.fail_json(msg=msg)
191 
192     elif state == 'absent':
193         if package_installed(module, name):
194             if module.check_mode:
195                 module.exit_json(changed=True)
196             (rc, out, err) = package_uninstall(module, name)
197             if len(out) > 75:
198                 out = out[:75] + '...'
199             if rc != 0:
200                 if err:
201                     msg = err
202                 else:
203                     msg = out
204                 module.fail_json(msg=msg)
205 
206     if rc is None:
207         # pkgutil was not executed because the package was already present/absent
208         result['changed'] = False
209     elif rc == 0:
210         result['changed'] = True
211     else:
212         result['changed'] = False
213         result['failed'] = True
214 
215     if out:
216         result['stdout'] = out
217     if err:
218         result['stderr'] = err
219 
220     module.exit_json(**result)
221 
222 # import module snippets
223 from ansible.module_utils.basic import *
224 main()
225
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/packaging/os/pkgutil.py b/packaging/os/pkgutil.py
--- a/packaging/os/pkgutil.py
+++ b/packaging/os/pkgutil.py
@@ -54,8 +54,7 @@
     description:
       - If you want to refresh your catalog from the mirror, set this to (C(yes)).
     required: false
-    choices: ["yes", "no"]
-    default: no
+    default: False
     version_added: "2.1"
 '''
 
@@ -130,7 +129,7 @@
             name = dict(required = True),
             state = dict(required = True, choices=['present', 'absent','latest']),
             site = dict(default = None),
-            update_catalog = dict(required = False, default = "no", type='bool', choices=["yes","no"]),
+            update_catalog = dict(required = False, default = False, type='bool'),
         ),
         supports_check_mode=True
     )

{"golden_diff": "diff --git a/packaging/os/pkgutil.py b/packaging/os/pkgutil.py\n--- a/packaging/os/pkgutil.py\n+++ b/packaging/os/pkgutil.py\n@@ -54,8 +54,7 @@\n     description:\n       - If you want to refresh your catalog from the mirror, set this to (C(yes)).\n     required: false\n-    choices: [\"yes\", \"no\"]\n-    default: no\n+    default: False\n     version_added: \"2.1\"\n '''\n \n@@ -130,7 +129,7 @@\n             name = dict(required = True),\n             state = dict(required = True, choices=['present', 'absent','latest']),\n             site = dict(default = None),\n-            update_catalog = dict(required = False, default = \"no\", type='bool', choices=[\"yes\",\"no\"]),\n+            update_catalog = dict(required = False, default = False, type='bool'),\n         ),\n         supports_check_mode=True\n     )\n", "issue": "pkgutil: the values of update_catalog get always translated to true or false, but the module expects yes or no.\n##### ISSUE TYPE\n- Bug Report\n##### COMPONENT NAME\n\npackaging/os/pkgutil.py\n##### ANSIBLE VERSION\n\n```\nansible 2.1.0.0-RC1\nansible 2.1.0.0 (detached HEAD 5954a82dd6) last updated 2016/05/02 13:45:40 (GMT +200)\n  lib/ansible/modules/core: (detached HEAD ce79e7c72d) last updated 2016/05/02 13:46:30 (GMT +200)\n  lib/ansible/modules/extras: (detached HEAD 156a8cd0b3) last updated 2016/05/02 13:46:30 (GMT +200)\n```\n##### CONFIGURATION\n##### OS / ENVIRONMENT\n\nRunning on MacOS X 10.11.4 against Solaris 10\n##### SUMMARY\n\nArgument update_catalog gets wrong values false and true instead of no and yes \n##### STEPS TO REPRODUCE\n\n```\nansible myhost -m pkgutil -a \"name=CSWgnupg state=present\" -u root\nmyhost | FAILED! => {\n    \"changed\": false, \n    \"failed\": true, \n    \"invocation\": {\n        \"module_args\": {\n            \"name\": \"CSWgnupg\", \n            \"state\": \"present\", \n            \"update_catalog\": false\n        }, \n        \"module_name\": \"pkgutil\"\n    }, \n    \"msg\": \"value of update_catalog must be one of: yes,no, got: False\"\n}\n```\n##### EXPECTED RESULTS\n\nCSW package gnupg should be installed.\n##### ACTUAL RESULTS\n\nThe values of update_catalog get always translated to true or false, but the module expects yes or no.\n\n```\nansible myhost -m pkgutil -a \"name=CSWgnupg state=present\" -u root\nmyhost | FAILED! => {\n    \"changed\": false, \n    \"failed\": true, \n    \"invocation\": {\n        \"module_args\": {\n            \"name\": \"CSWgnupg\", \n            \"state\": \"present\", \n            \"update_catalog\": false\n        }, \n        \"module_name\": \"pkgutil\"\n    }, \n    \"msg\": \"value of update_catalog must be one of: yes,no, got: False\"\n}\n\nansible myhost -m pkgutil -a \"name=CSWgnupg state=present update_catalog=no\" -u root\nmyhost | FAILED! => {\n    \"changed\": false, \n    \"failed\": true, \n    \"invocation\": {\n        \"module_args\": {\n            \"name\": \"CSWgnupg\", \n            \"state\": \"present\", \n            \"update_catalog\": false\n        }, \n        \"module_name\": \"pkgutil\"\n    }, \n    \"msg\": \"value of update_catalog must be one of: yes,no, got: False\"\n}\n\nansible myhost -m pkgutil -a \"name=CSWgnupg state=present update_catalog=false\" -u root\nmyhost | FAILED! => {\n    \"changed\": false, \n    \"failed\": true, \n    \"invocation\": {\n        \"module_args\": {\n            \"name\": \"CSWgnupg\", \n            \"state\": \"present\", \n            \"update_catalog\": false\n        }, \n        \"module_name\": \"pkgutil\"\n    }, \n    \"msg\": \"value of update_catalog must be one of: yes,no, got: False\"\n}\n\nansible myhost -m pkgutil -a \"name=CSWgnupg state=present update_catalog=yes\" -u root\nmyhost | FAILED! => {\n    \"changed\": false, \n    \"failed\": true, \n    \"invocation\": {\n        \"module_args\": {\n            \"name\": \"CSWgnupg\", \n            \"state\": \"present\", \n            \"update_catalog\": true\n        }, \n        \"module_name\": \"pkgutil\"\n    }, \n    \"msg\": \"value of update_catalog must be one of: yes,no, got: True\"\n}\n\nansible myhost -m pkgutil -a \"name=CSWgnupg state=present update_catalog=true\" -u root \nmyhost | FAILED! => {\n    \"changed\": false, \n    \"failed\": true, \n    \"msg\": \"value of update_catalog must be one of: yes,no, got: True\"\n}\n```\n\n", "before_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n# (c) 2013, Alexander Winkler <mail () winkler-alexander.de>\n# based on svr4pkg by\n#  Boyd Adamson <boyd () boydadamson.com> (2012)\n#\n# This file is part of Ansible\n#\n# Ansible is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# Ansible is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n#\n\nDOCUMENTATION = '''\n---\nmodule: pkgutil \nshort_description: Manage CSW-Packages on Solaris\ndescription:\n    - Manages CSW packages (SVR4 format) on Solaris 10 and 11.\n    - These were the native packages on Solaris <= 10 and are available\n      as a legacy feature in Solaris 11.\n    - Pkgutil is an advanced packaging system, which resolves dependency on installation.\n      It is designed for CSW packages.\nversion_added: \"1.3\"\nauthor: \"Alexander Winkler (@dermute)\"\noptions:\n  name:\n    description:\n      - Package name, e.g. (C(CSWnrpe))\n    required: true\n  site:\n    description:\n      - Specifies the repository path to install the package from.\n      - Its global definition is done in C(/etc/opt/csw/pkgutil.conf).\n    required: false\n  state:\n    description:\n      - Whether to install (C(present)), or remove (C(absent)) a package.\n      - The upgrade (C(latest)) operation will update/install the package to the latest version available.\n      - \"Note: The module has a limitation that (C(latest)) only works for one package, not lists of them.\"\n    required: true\n    choices: [\"present\", \"absent\", \"latest\"]\n  update_catalog:\n    description:\n      - If you want to refresh your catalog from the mirror, set this to (C(yes)).\n    required: false\n    choices: [\"yes\", \"no\"]\n    default: no\n    version_added: \"2.1\"\n'''\n\nEXAMPLES = '''\n# Install a package\npkgutil: name=CSWcommon state=present\n\n# Install a package from a specific repository\npkgutil: name=CSWnrpe site='ftp://myinternal.repo/opencsw/kiel state=latest'\n'''\n\nimport os\nimport pipes\n\ndef package_installed(module, name):\n    cmd = ['pkginfo']\n    cmd.append('-q')\n    cmd.append(name)\n    rc, out, err = run_command(module, cmd)\n    if rc == 0:\n        return True\n    else:\n        return False\n\ndef package_latest(module, name, site):\n    # Only supports one package\n    cmd = [ 'pkgutil', '-U', '--single', '-c' ]\n    if site is not None:\n        cmd += [ '-t', site]\n    cmd.append(name)\n    rc, out, err = run_command(module, cmd)\n    # replace | tail -1 |grep -v SAME\n    # use -2, because splitting on \\n create a empty line\n    # at the end of the list\n    return 'SAME' in out.split('\\n')[-2]\n\ndef run_command(module, cmd, **kwargs):\n    progname = cmd[0]\n    cmd[0] = module.get_bin_path(progname, True, ['/opt/csw/bin'])\n    return module.run_command(cmd, **kwargs)\n\ndef package_install(module, state, name, site, update_catalog):\n    cmd = [ 'pkgutil', '-iy' ]\n    if update_catalog:\n        cmd += [ '-U' ]\n    if site is not None:\n        cmd += [ '-t', site ]\n    if state == 'latest':\n        cmd += [ '-f' ] \n    cmd.append(name)\n    (rc, out, err) = run_command(module, cmd)\n    return (rc, out, err)\n\ndef package_upgrade(module, name, site, update_catalog):\n    cmd = [ 'pkgutil', '-ufy' ]\n    if update_catalog:\n        cmd += [ '-U' ]\n    if site is not None:\n        cmd += [ '-t', site ]\n    cmd.append(name)\n    (rc, out, err) = run_command(module, cmd)\n    return (rc, out, err)\n\ndef package_uninstall(module, name):\n    cmd = [ 'pkgutil', '-ry', name]\n    (rc, out, err) = run_command(module, cmd)\n    return (rc, out, err)\n\ndef main():\n    module = AnsibleModule(\n        argument_spec = dict(\n            name = dict(required = True),\n            state = dict(required = True, choices=['present', 'absent','latest']),\n            site = dict(default = None),\n            update_catalog = dict(required = False, default = \"no\", type='bool', choices=[\"yes\",\"no\"]),\n        ),\n        supports_check_mode=True\n    )\n    name = module.params['name']\n    state = module.params['state']\n    site = module.params['site']\n    update_catalog = module.params['update_catalog']\n    rc = None\n    out = ''\n    err = ''\n    result = {}\n    result['name'] = name\n    result['state'] = state\n\n    if state == 'present':\n        if not package_installed(module, name):\n            if module.check_mode:\n                module.exit_json(changed=True)\n            (rc, out, err) = package_install(module, state, name, site, update_catalog)\n            # Stdout is normally empty but for some packages can be\n            # very long and is not often useful\n            if len(out) > 75:\n                out = out[:75] + '...'\n            if rc != 0:\n                if err:\n                    msg = err\n                else:\n                    msg = out\n                module.fail_json(msg=msg)\n\n    elif state == 'latest':\n        if not package_installed(module, name):\n            if module.check_mode:\n                module.exit_json(changed=True)\n            (rc, out, err) = package_install(module, state, name, site, update_catalog)\n            if len(out) > 75:\n                out = out[:75] + '...'\n            if rc != 0:\n                if err:\n                    msg = err\n                else:\n                    msg = out\n                module.fail_json(msg=msg)\n\n        else:\n            if not package_latest(module, name, site):\n                if module.check_mode:\n                    module.exit_json(changed=True) \n                (rc, out, err) = package_upgrade(module, name, site, update_catalog)\n                if len(out) > 75:\n                    out = out[:75] + '...'\n                if rc != 0:\n                    if err:\n                        msg = err\n                    else:\n                        msg = out\n                    module.fail_json(msg=msg)\n\n    elif state == 'absent':\n        if package_installed(module, name):\n            if module.check_mode:\n                module.exit_json(changed=True)\n            (rc, out, err) = package_uninstall(module, name)\n            if len(out) > 75:\n                out = out[:75] + '...'\n            if rc != 0:\n                if err:\n                    msg = err\n                else:\n                    msg = out\n                module.fail_json(msg=msg)\n\n    if rc is None:\n        # pkgutil was not executed because the package was already present/absent\n        result['changed'] = False\n    elif rc == 0:\n        result['changed'] = True\n    else:\n        result['changed'] = False\n        result['failed'] = True\n\n    if out:\n        result['stdout'] = out\n    if err:\n        result['stderr'] = err\n\n    module.exit_json(**result)\n\n# import module snippets\nfrom ansible.module_utils.basic import *\nmain()\n", "path": "packaging/os/pkgutil.py"}], "after_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n# (c) 2013, Alexander Winkler <mail () winkler-alexander.de>\n# based on svr4pkg by\n#  Boyd Adamson <boyd () boydadamson.com> (2012)\n#\n# This file is part of Ansible\n#\n# Ansible is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# Ansible is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n#\n\nDOCUMENTATION = '''\n---\nmodule: pkgutil \nshort_description: Manage CSW-Packages on Solaris\ndescription:\n    - Manages CSW packages (SVR4 format) on Solaris 10 and 11.\n    - These were the native packages on Solaris <= 10 and are available\n      as a legacy feature in Solaris 11.\n    - Pkgutil is an advanced packaging system, which resolves dependency on installation.\n      It is designed for CSW packages.\nversion_added: \"1.3\"\nauthor: \"Alexander Winkler (@dermute)\"\noptions:\n  name:\n    description:\n      - Package name, e.g. (C(CSWnrpe))\n    required: true\n  site:\n    description:\n      - Specifies the repository path to install the package from.\n      - Its global definition is done in C(/etc/opt/csw/pkgutil.conf).\n    required: false\n  state:\n    description:\n      - Whether to install (C(present)), or remove (C(absent)) a package.\n      - The upgrade (C(latest)) operation will update/install the package to the latest version available.\n      - \"Note: The module has a limitation that (C(latest)) only works for one package, not lists of them.\"\n    required: true\n    choices: [\"present\", \"absent\", \"latest\"]\n  update_catalog:\n    description:\n      - If you want to refresh your catalog from the mirror, set this to (C(yes)).\n    required: false\n    default: False\n    version_added: \"2.1\"\n'''\n\nEXAMPLES = '''\n# Install a package\npkgutil: name=CSWcommon state=present\n\n# Install a package from a specific repository\npkgutil: name=CSWnrpe site='ftp://myinternal.repo/opencsw/kiel state=latest'\n'''\n\nimport os\nimport pipes\n\ndef package_installed(module, name):\n    cmd = ['pkginfo']\n    cmd.append('-q')\n    cmd.append(name)\n    rc, out, err = run_command(module, cmd)\n    if rc == 0:\n        return True\n    else:\n        return False\n\ndef package_latest(module, name, site):\n    # Only supports one package\n    cmd = [ 'pkgutil', '-U', '--single', '-c' ]\n    if site is not None:\n        cmd += [ '-t', site]\n    cmd.append(name)\n    rc, out, err = run_command(module, cmd)\n    # replace | tail -1 |grep -v SAME\n    # use -2, because splitting on \\n create a empty line\n    # at the end of the list\n    return 'SAME' in out.split('\\n')[-2]\n\ndef run_command(module, cmd, **kwargs):\n    progname = cmd[0]\n    cmd[0] = module.get_bin_path(progname, True, ['/opt/csw/bin'])\n    return module.run_command(cmd, **kwargs)\n\ndef package_install(module, state, name, site, update_catalog):\n    cmd = [ 'pkgutil', '-iy' ]\n    if update_catalog:\n        cmd += [ '-U' ]\n    if site is not None:\n        cmd += [ '-t', site ]\n    if state == 'latest':\n        cmd += [ '-f' ] \n    cmd.append(name)\n    (rc, out, err) = run_command(module, cmd)\n    return (rc, out, err)\n\ndef package_upgrade(module, name, site, update_catalog):\n    cmd = [ 'pkgutil', '-ufy' ]\n    if update_catalog:\n        cmd += [ '-U' ]\n    if site is not None:\n        cmd += [ '-t', site ]\n    cmd.append(name)\n    (rc, out, err) = run_command(module, cmd)\n    return (rc, out, err)\n\ndef package_uninstall(module, name):\n    cmd = [ 'pkgutil', '-ry', name]\n    (rc, out, err) = run_command(module, cmd)\n    return (rc, out, err)\n\ndef main():\n    module = AnsibleModule(\n        argument_spec = dict(\n            name = dict(required = True),\n            state = dict(required = True, choices=['present', 'absent','latest']),\n            site = dict(default = None),\n            update_catalog = dict(required = False, default = False, type='bool'),\n        ),\n        supports_check_mode=True\n    )\n    name = module.params['name']\n    state = module.params['state']\n    site = module.params['site']\n    update_catalog = module.params['update_catalog']\n    rc = None\n    out = ''\n    err = ''\n    result = {}\n    result['name'] = name\n    result['state'] = state\n\n    if state == 'present':\n        if not package_installed(module, name):\n            if module.check_mode:\n                module.exit_json(changed=True)\n            (rc, out, err) = package_install(module, state, name, site, update_catalog)\n            # Stdout is normally empty but for some packages can be\n            # very long and is not often useful\n            if len(out) > 75:\n                out = out[:75] + '...'\n            if rc != 0:\n                if err:\n                    msg = err\n                else:\n                    msg = out\n                module.fail_json(msg=msg)\n\n    elif state == 'latest':\n        if not package_installed(module, name):\n            if module.check_mode:\n                module.exit_json(changed=True)\n            (rc, out, err) = package_install(module, state, name, site, update_catalog)\n            if len(out) > 75:\n                out = out[:75] + '...'\n            if rc != 0:\n                if err:\n                    msg = err\n                else:\n                    msg = out\n                module.fail_json(msg=msg)\n\n        else:\n            if not package_latest(module, name, site):\n                if module.check_mode:\n                    module.exit_json(changed=True) \n                (rc, out, err) = package_upgrade(module, name, site, update_catalog)\n                if len(out) > 75:\n                    out = out[:75] + '...'\n                if rc != 0:\n                    if err:\n                        msg = err\n                    else:\n                        msg = out\n                    module.fail_json(msg=msg)\n\n    elif state == 'absent':\n        if package_installed(module, name):\n            if module.check_mode:\n                module.exit_json(changed=True)\n            (rc, out, err) = package_uninstall(module, name)\n            if len(out) > 75:\n                out = out[:75] + '...'\n            if rc != 0:\n                if err:\n                    msg = err\n                else:\n                    msg = out\n                module.fail_json(msg=msg)\n\n    if rc is None:\n        # pkgutil was not executed because the package was already present/absent\n        result['changed'] = False\n    elif rc == 0:\n        result['changed'] = True\n    else:\n        result['changed'] = False\n        result['failed'] = True\n\n    if out:\n        result['stdout'] = out\n    if err:\n        result['stderr'] = err\n\n    module.exit_json(**result)\n\n# import module snippets\nfrom ansible.module_utils.basic import *\nmain()\n", "path": "packaging/os/pkgutil.py"}]}