Repository: ansible/ansible

Issue:
composer config --dry-run
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
composer

##### ANSIBLE VERSION
```
ansible 2.4.0.0
```

##### CONFIGURATION
composer 1.5.2
Ansible 2.4.0.0


##### SUMMARY
composer only partially support check-mode.
`composer`' command `config` does not

##### STEPS TO REPRODUCE
```yaml
  composer:
    global_command: yes
    command: config
    arguments: "gitlab-oauth.gitlab.com XXX"
```

and run in **check-mode**

##### EXPECTED RESULTS
ok, the value should be updated

##### ACTUAL RESULTS
```
    "invocation": {
        "module_args": {
            "arguments": "gitlab-oauth.gitlab.com XXX", 
            "command": "config", 
            "executable": null, 
            "global_command": true, 
            "ignore_platform_reqs": false, 
            "no_dev": true, 
            "no_plugins": false, 
            "no_scripts": false, 
            "optimize_autoloader": true, 
            "prefer_dist": false, 
            "prefer_source": false, 
            "working_dir": null
        }
    }, 
    "msg": "Changed current directory to /home/blah/.composer [Symfony\\Component\\Console\\Exception\\RuntimeException] The \"--dry-run\" option does not exist. config [-g|--global] [-e|--editor] [-a|--auth] [--unset] [-l|--list] [-f|--file FILE] [--absolute] [--] [<setting-key>] [<setting-value>]...", 
    "stdout": "Changed current directory to /home/blah/.composer\n\n                                                          \n  [Symfony\\Component\\Console\\Exception\\RuntimeException]  \n  The \"--dry-run\" option does not exist.                  \n                                                          \n\nconfig [-g|--global] [-e|--editor] [-a|--auth] [--unset] [-l|--list] [-f|--file FILE] [--absolute] [--] [<setting-key>] [<setting-value>]...\n\n", 
    "stdout_lines": [
        "Changed current directory to /home/blah/.composer", 
        "", 
        "                                                          ", 
        "  [Symfony\\Component\\Console\\Exception\\RuntimeException]  ", 
        "  The \"--dry-run\" option does not exist.                  ", 
        "                                                          ", 
        "", 
        "config [-g|--global] [-e|--editor] [-a|--auth] [--unset] [-l|--list] [-f|--file FILE] [--absolute] [--] [<setting-key>] [<setting-value>]...", 
        ""
    ]

```


Discussion:
cc @dmtrs @resmo
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
This isn't an issue with the Ansible [composer module](https://github.com/ansible/ansible/blob/stable-2.4/lib/ansible/modules/packaging/language/composer.py) but with the fact that __Composer__ doesn't have an option - "--dry-run" for the "config" command. 
"--dry-run" option exists for "install" and "update" commands based on the latest [Composer documentation](https://getcomposer.org/doc/03-cli.md) 
Thanks @singareddyb, we are going to handle this in a proper way.

Resolving patch:
diff --git a/lib/ansible/modules/packaging/language/composer.py b/lib/ansible/modules/packaging/language/composer.py
--- a/lib/ansible/modules/packaging/language/composer.py
+++ b/lib/ansible/modules/packaging/language/composer.py
@@ -31,89 +31,74 @@
         version_added: "1.8"
         description:
             - Composer command like "install", "update" and so on.
-        required: false
         default: install
     arguments:
         version_added: "2.0"
         description:
             - Composer arguments like required package, version and so on.
-        required: false
-        default: null
     executable:
         version_added: "2.4"
         description:
-            - Path to PHP Executable on the remote host, if PHP is not in PATH
-        required: false
-        default: null
-        aliases: [ "php_path" ]
+            - Path to PHP Executable on the remote host, if PHP is not in PATH.
+        aliases: [ php_path ]
     working_dir:
         description:
             - Directory of your project (see --working-dir). This is required when
               the command is not run globally.
             - Will be ignored if C(global_command=true).
-        required: false
-        default: null
-        aliases: [ "working-dir" ]
+        aliases: [ working-dir ]
     global_command:
         version_added: "2.4"
         description:
             - Runs the specified command globally.
-        required: false
         choices: [ true, false]
         default: false
-        aliases: [ "global-command" ]
+        aliases: [ global-command ]
     prefer_source:
         description:
             - Forces installation from package sources when possible (see --prefer-source).
-        required: false
         default: false
         choices: [ true, false]
-        aliases: [ "prefer-source" ]
+        aliases: [ prefer-source ]
     prefer_dist:
         description:
             - Forces installation from package dist even for dev versions (see --prefer-dist).
-        required: false
         default: false
         choices: [ true, false]
-        aliases: [ "prefer-dist" ]
+        aliases: [ prefer-dist ]
     no_dev:
         description:
             - Disables installation of require-dev packages (see --no-dev).
-        required: false
         default: true
         choices: [ true, false]
-        aliases: [ "no-dev" ]
+        aliases: [ no-dev ]
     no_scripts:
         description:
             - Skips the execution of all scripts defined in composer.json (see --no-scripts).
-        required: false
         default: false
         choices: [ true, false]
-        aliases: [ "no-scripts" ]
+        aliases: [ no-scripts ]
     no_plugins:
         description:
             - Disables all plugins ( see --no-plugins ).
-        required: false
         default: false
         choices: [ true, false]
-        aliases: [ "no-plugins" ]
+        aliases: [ no-plugin ]
     optimize_autoloader:
         description:
             - Optimize autoloader during autoloader dump (see --optimize-autoloader).
             - Convert PSR-0/4 autoloading to classmap to get a faster autoloader.
             - Recommended especially for production, but can take a bit of time to run.
-        required: false
         default: true
         choices: [ true, false]
-        aliases: [ "optimize-autoloader" ]
+        aliases: [ optimize-autoloader ]
     ignore_platform_reqs:
         version_added: "2.0"
         description:
             - Ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these.
-        required: false
         default: false
         choices: [ true, false]
-        aliases: [ "ignore-platform-reqs" ]
+        aliases: [ ignore-platform-reqs ]
 requirements:
     - php
     - composer installed in bin path (recommended /usr/local/bin)
@@ -148,7 +133,6 @@
 '''
 
 import re
-
 from ansible.module_utils.basic import AnsibleModule
 
 
@@ -188,9 +172,9 @@ def composer_command(module, command, arguments="", options=None, global_command
 def main():
     module = AnsibleModule(
         argument_spec=dict(
-            command=dict(default="install", type="str", required=False),
-            arguments=dict(default="", type="str", required=False),
-            executable=dict(type="path", required=False, aliases=["php_path"]),
+            command=dict(default="install", type="str"),
+            arguments=dict(default="", type="str"),
+            executable=dict(type="path", aliases=["php_path"]),
             working_dir=dict(type="path", aliases=["working-dir"]),
             global_command=dict(default=False, type="bool", aliases=["global-command"]),
             prefer_source=dict(default=False, type="bool", aliases=["prefer-source"]),
@@ -247,7 +231,10 @@ def main():
             options.append(option)
 
     if module.check_mode:
-        options.append('--dry-run')
+        if 'dry-run' in available_options:
+            options.append('--dry-run')
+        else:
+            module.exit_json(skipped=True, msg="command '%s' does not support check mode, skipping" % command)
 
     rc, out, err = composer_command(module, command, arguments, options, global_command)
 


Test patch: