We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ios_command module : can not use "configure revert" commands
##### ISSUE TYPE 
- Bug Report

##### COMPONENT NAME
- ios_command

##### ANSIBLE VERSION
- 2.x

##### SUMMARY: ios_command module should not filter out all configure commands

ios_command is a wonderful module, however i found a minor issue :

On line 165 there is a sanity check that verify that the user is not sending a configuration command
 ` elif item['command'].startswith('conf'):` 

With this test, it is not possible to send the following commands :
  - configure revert timer 5
  - configure confirm
  - configure replace
  - configure network
which ARE valid exec commands and do NOT enter in configuration mode.

Hopefully (for me), a basic workaround is to insert a space (may be it is intented) :
  - [space] configure revert timer 5

I propose to change the test and use something like  (sorry i am not familiar with python) :
`   elif re.match("^\s*conf\S*\s+t", item['command']) `
just to ensure that the user has NOT entered one of various configure terminal flavors.


##### STEPS TO REPRODUCE

Use the following playbook : 

<pre> 
---
- name: try
  hosts: all
  connection: local
  gather_facts: no

  vars:
      cli:
        host: "{{ inventory_hostname }}"
        username: cisco
        password: cisco
        transport: cli

  - name: This work (note the space at the beginning of the command line)
    ios_command:
          commands:
             - clear configuration lock
             - " configure revert timer 8"

  - name: This will not work (but should)
    ios_command:
          commands:
             - clear configuration lock
             - "configure revert timer 8"
</pre> 


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/ansible/modules/network/ios/ios_command.py`
Content:
```
1 #!/usr/bin/python
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 
19 ANSIBLE_METADATA = {'metadata_version': '1.1',
20                     'status': ['preview'],
21                     'supported_by': 'network'}
22 
23 
24 DOCUMENTATION = """
25 ---
26 module: ios_command
27 version_added: "2.1"
28 author: "Peter Sprygada (@privateip)"
29 short_description: Run commands on remote devices running Cisco IOS
30 description:
31   - Sends arbitrary commands to an ios node and returns the results
32     read from the device. This module includes an
33     argument that will cause the module to wait for a specific condition
34     before returning or timing out if the condition is not met.
35   - This module does not support running commands in configuration mode.
36     Please use M(ios_config) to configure IOS devices.
37 extends_documentation_fragment: ios
38 notes:
39   - Tested against IOS 15.6
40 options:
41   commands:
42     description:
43       - List of commands to send to the remote ios device over the
44         configured provider. The resulting output from the command
45         is returned. If the I(wait_for) argument is provided, the
46         module is not returned until the condition is satisfied or
47         the number of retries has expired.
48     required: true
49   wait_for:
50     description:
51       - List of conditions to evaluate against the output of the
52         command. The task will wait for each condition to be true
53         before moving forward. If the conditional is not true
54         within the configured number of retries, the task fails.
55         See examples.
56     required: false
57     default: null
58     aliases: ['waitfor']
59     version_added: "2.2"
60   match:
61     description:
62       - The I(match) argument is used in conjunction with the
63         I(wait_for) argument to specify the match policy.  Valid
64         values are C(all) or C(any).  If the value is set to C(all)
65         then all conditionals in the wait_for must be satisfied.  If
66         the value is set to C(any) then only one of the values must be
67         satisfied.
68     required: false
69     default: all
70     choices: ['any', 'all']
71     version_added: "2.2"
72   retries:
73     description:
74       - Specifies the number of retries a command should by tried
75         before it is considered failed. The command is run on the
76         target device every retry and evaluated against the
77         I(wait_for) conditions.
78     required: false
79     default: 10
80   interval:
81     description:
82       - Configures the interval in seconds to wait between retries
83         of the command. If the command does not pass the specified
84         conditions, the interval indicates how long to wait before
85         trying the command again.
86     required: false
87     default: 1
88 """
89 
90 EXAMPLES = """
91 tasks:
92   - name: run show version on remote devices
93     ios_command:
94       commands: show version
95 
96   - name: run show version and check to see if output contains IOS
97     ios_command:
98       commands: show version
99       wait_for: result[0] contains IOS
100 
101   - name: run multiple commands on remote nodes
102     ios_command:
103       commands:
104         - show version
105         - show interfaces
106 
107   - name: run multiple commands and evaluate the output
108     ios_command:
109       commands:
110         - show version
111         - show interfaces
112       wait_for:
113         - result[0] contains IOS
114         - result[1] contains Loopback0
115 """
116 
117 RETURN = """
118 stdout:
119   description: The set of responses from the commands
120   returned: always apart from low level errors (such as action plugin)
121   type: list
122   sample: ['...', '...']
123 stdout_lines:
124   description: The value of stdout split into a list
125   returned: always apart from low level errors (such as action plugin)
126   type: list
127   sample: [['...', '...'], ['...'], ['...']]
128 failed_conditions:
129   description: The list of conditionals that have failed
130   returned: failed
131   type: list
132   sample: ['...', '...']
133 """
134 import time
135 
136 from ansible.module_utils.network.ios.ios import run_commands
137 from ansible.module_utils.network.ios.ios import ios_argument_spec, check_args
138 from ansible.module_utils.basic import AnsibleModule
139 from ansible.module_utils.network.common.utils import ComplexList
140 from ansible.module_utils.network.common.parsing import Conditional
141 from ansible.module_utils.six import string_types
142 
143 
144 def to_lines(stdout):
145     for item in stdout:
146         if isinstance(item, string_types):
147             item = str(item).split('\n')
148         yield item
149 
150 
151 def parse_commands(module, warnings):
152     command = ComplexList(dict(
153         command=dict(key=True),
154         prompt=dict(),
155         answer=dict()
156     ), module)
157     commands = command(module.params['commands'])
158     for item in list(commands):
159         if module.check_mode and not item['command'].startswith('show'):
160             warnings.append(
161                 'only show commands are supported when using check mode, not '
162                 'executing `%s`' % item['command']
163             )
164             commands.remove(item)
165         elif item['command'].startswith('conf'):
166             module.fail_json(
167                 msg='ios_command does not support running config mode '
168                     'commands.  Please use ios_config instead'
169             )
170     return commands
171 
172 
173 def main():
174     """main entry point for module execution
175     """
176     argument_spec = dict(
177         commands=dict(type='list', required=True),
178 
179         wait_for=dict(type='list', aliases=['waitfor']),
180         match=dict(default='all', choices=['all', 'any']),
181 
182         retries=dict(default=10, type='int'),
183         interval=dict(default=1, type='int')
184     )
185 
186     argument_spec.update(ios_argument_spec)
187 
188     module = AnsibleModule(argument_spec=argument_spec,
189                            supports_check_mode=True)
190 
191     result = {'changed': False}
192 
193     warnings = list()
194     check_args(module, warnings)
195     commands = parse_commands(module, warnings)
196     result['warnings'] = warnings
197 
198     wait_for = module.params['wait_for'] or list()
199     conditionals = [Conditional(c) for c in wait_for]
200 
201     retries = module.params['retries']
202     interval = module.params['interval']
203     match = module.params['match']
204 
205     while retries > 0:
206         responses = run_commands(module, commands)
207 
208         for item in list(conditionals):
209             if item(responses):
210                 if match == 'any':
211                     conditionals = list()
212                     break
213                 conditionals.remove(item)
214 
215         if not conditionals:
216             break
217 
218         time.sleep(interval)
219         retries -= 1
220 
221     if conditionals:
222         failed_conditions = [item.raw for item in conditionals]
223         msg = 'One or more conditional statements have not be satisfied'
224         module.fail_json(msg=msg, failed_conditions=failed_conditions)
225 
226     result.update({
227         'changed': False,
228         'stdout': responses,
229         'stdout_lines': list(to_lines(responses))
230     })
231 
232     module.exit_json(**result)
233 
234 
235 if __name__ == '__main__':
236     main()
237
```
--- 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/lib/ansible/modules/network/ios/ios_command.py b/lib/ansible/modules/network/ios/ios_command.py
--- a/lib/ansible/modules/network/ios/ios_command.py
+++ b/lib/ansible/modules/network/ios/ios_command.py
@@ -131,6 +131,7 @@
   type: list
   sample: ['...', '...']
 """
+import re
 import time
 
 from ansible.module_utils.network.ios.ios import run_commands
@@ -156,13 +157,14 @@
     ), module)
     commands = command(module.params['commands'])
     for item in list(commands):
+        configure_type = re.match(r'conf(?:\w*)(?:\s+(\w+))?', item['command'])
         if module.check_mode and not item['command'].startswith('show'):
             warnings.append(
                 'only show commands are supported when using check mode, not '
                 'executing `%s`' % item['command']
             )
             commands.remove(item)
-        elif item['command'].startswith('conf'):
+        elif configure_type and configure_type.group(1) not in ('confirm', 'replace', 'revert', 'network'):
             module.fail_json(
                 msg='ios_command does not support running config mode '
                     'commands.  Please use ios_config instead'

{"golden_diff": "diff --git a/lib/ansible/modules/network/ios/ios_command.py b/lib/ansible/modules/network/ios/ios_command.py\n--- a/lib/ansible/modules/network/ios/ios_command.py\n+++ b/lib/ansible/modules/network/ios/ios_command.py\n@@ -131,6 +131,7 @@\n   type: list\n   sample: ['...', '...']\n \"\"\"\n+import re\n import time\n \n from ansible.module_utils.network.ios.ios import run_commands\n@@ -156,13 +157,14 @@\n     ), module)\n     commands = command(module.params['commands'])\n     for item in list(commands):\n+        configure_type = re.match(r'conf(?:\\w*)(?:\\s+(\\w+))?', item['command'])\n         if module.check_mode and not item['command'].startswith('show'):\n             warnings.append(\n                 'only show commands are supported when using check mode, not '\n                 'executing `%s`' % item['command']\n             )\n             commands.remove(item)\n-        elif item['command'].startswith('conf'):\n+        elif configure_type and configure_type.group(1) not in ('confirm', 'replace', 'revert', 'network'):\n             module.fail_json(\n                 msg='ios_command does not support running config mode '\n                     'commands.  Please use ios_config instead'\n", "issue": "ios_command module : can not use \"configure revert\" commands\n##### ISSUE TYPE \r\n- Bug Report\r\n\r\n##### COMPONENT NAME\r\n- ios_command\r\n\r\n##### ANSIBLE VERSION\r\n- 2.x\r\n\r\n##### SUMMARY: ios_command module should not filter out all configure commands\r\n\r\nios_command is a wonderful module, however i found a minor issue :\r\n\r\nOn line 165 there is a sanity check that verify that the user is not sending a configuration command\r\n ` elif item['command'].startswith('conf'):` \r\n\r\nWith this test, it is not possible to send the following commands :\r\n  - configure revert timer 5\r\n  - configure confirm\r\n  - configure replace\r\n  - configure network\r\nwhich ARE valid exec commands and do NOT enter in configuration mode.\r\n\r\nHopefully (for me), a basic workaround is to insert a space (may be it is intented) :\r\n  - [space] configure revert timer 5\r\n\r\nI propose to change the test and use something like  (sorry i am not familiar with python) :\r\n`   elif re.match(\"^\\s*conf\\S*\\s+t\", item['command']) `\r\njust to ensure that the user has NOT entered one of various configure terminal flavors.\r\n\r\n\r\n##### STEPS TO REPRODUCE\r\n\r\nUse the following playbook : \r\n\r\n<pre> \r\n---\r\n- name: try\r\n  hosts: all\r\n  connection: local\r\n  gather_facts: no\r\n\r\n  vars:\r\n      cli:\r\n        host: \"{{ inventory_hostname }}\"\r\n        username: cisco\r\n        password: cisco\r\n        transport: cli\r\n\r\n  - name: This work (note the space at the beginning of the command line)\r\n    ios_command:\r\n          commands:\r\n             - clear configuration lock\r\n             - \" configure revert timer 8\"\r\n\r\n  - name: This will not work (but should)\r\n    ios_command:\r\n          commands:\r\n             - clear configuration lock\r\n             - \"configure revert timer 8\"\r\n</pre> \r\n\n", "before_files": [{"content": "#!/usr/bin/python\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\nANSIBLE_METADATA = {'metadata_version': '1.1',\n                    'status': ['preview'],\n                    'supported_by': 'network'}\n\n\nDOCUMENTATION = \"\"\"\n---\nmodule: ios_command\nversion_added: \"2.1\"\nauthor: \"Peter Sprygada (@privateip)\"\nshort_description: Run commands on remote devices running Cisco IOS\ndescription:\n  - Sends arbitrary commands to an ios node and returns the results\n    read from the device. This module includes an\n    argument that will cause the module to wait for a specific condition\n    before returning or timing out if the condition is not met.\n  - This module does not support running commands in configuration mode.\n    Please use M(ios_config) to configure IOS devices.\nextends_documentation_fragment: ios\nnotes:\n  - Tested against IOS 15.6\noptions:\n  commands:\n    description:\n      - List of commands to send to the remote ios device over the\n        configured provider. The resulting output from the command\n        is returned. If the I(wait_for) argument is provided, the\n        module is not returned until the condition is satisfied or\n        the number of retries has expired.\n    required: true\n  wait_for:\n    description:\n      - List of conditions to evaluate against the output of the\n        command. The task will wait for each condition to be true\n        before moving forward. If the conditional is not true\n        within the configured number of retries, the task fails.\n        See examples.\n    required: false\n    default: null\n    aliases: ['waitfor']\n    version_added: \"2.2\"\n  match:\n    description:\n      - The I(match) argument is used in conjunction with the\n        I(wait_for) argument to specify the match policy.  Valid\n        values are C(all) or C(any).  If the value is set to C(all)\n        then all conditionals in the wait_for must be satisfied.  If\n        the value is set to C(any) then only one of the values must be\n        satisfied.\n    required: false\n    default: all\n    choices: ['any', 'all']\n    version_added: \"2.2\"\n  retries:\n    description:\n      - Specifies the number of retries a command should by tried\n        before it is considered failed. The command is run on the\n        target device every retry and evaluated against the\n        I(wait_for) conditions.\n    required: false\n    default: 10\n  interval:\n    description:\n      - Configures the interval in seconds to wait between retries\n        of the command. If the command does not pass the specified\n        conditions, the interval indicates how long to wait before\n        trying the command again.\n    required: false\n    default: 1\n\"\"\"\n\nEXAMPLES = \"\"\"\ntasks:\n  - name: run show version on remote devices\n    ios_command:\n      commands: show version\n\n  - name: run show version and check to see if output contains IOS\n    ios_command:\n      commands: show version\n      wait_for: result[0] contains IOS\n\n  - name: run multiple commands on remote nodes\n    ios_command:\n      commands:\n        - show version\n        - show interfaces\n\n  - name: run multiple commands and evaluate the output\n    ios_command:\n      commands:\n        - show version\n        - show interfaces\n      wait_for:\n        - result[0] contains IOS\n        - result[1] contains Loopback0\n\"\"\"\n\nRETURN = \"\"\"\nstdout:\n  description: The set of responses from the commands\n  returned: always apart from low level errors (such as action plugin)\n  type: list\n  sample: ['...', '...']\nstdout_lines:\n  description: The value of stdout split into a list\n  returned: always apart from low level errors (such as action plugin)\n  type: list\n  sample: [['...', '...'], ['...'], ['...']]\nfailed_conditions:\n  description: The list of conditionals that have failed\n  returned: failed\n  type: list\n  sample: ['...', '...']\n\"\"\"\nimport time\n\nfrom ansible.module_utils.network.ios.ios import run_commands\nfrom ansible.module_utils.network.ios.ios import ios_argument_spec, check_args\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible.module_utils.network.common.utils import ComplexList\nfrom ansible.module_utils.network.common.parsing import Conditional\nfrom ansible.module_utils.six import string_types\n\n\ndef to_lines(stdout):\n    for item in stdout:\n        if isinstance(item, string_types):\n            item = str(item).split('\\n')\n        yield item\n\n\ndef parse_commands(module, warnings):\n    command = ComplexList(dict(\n        command=dict(key=True),\n        prompt=dict(),\n        answer=dict()\n    ), module)\n    commands = command(module.params['commands'])\n    for item in list(commands):\n        if module.check_mode and not item['command'].startswith('show'):\n            warnings.append(\n                'only show commands are supported when using check mode, not '\n                'executing `%s`' % item['command']\n            )\n            commands.remove(item)\n        elif item['command'].startswith('conf'):\n            module.fail_json(\n                msg='ios_command does not support running config mode '\n                    'commands.  Please use ios_config instead'\n            )\n    return commands\n\n\ndef main():\n    \"\"\"main entry point for module execution\n    \"\"\"\n    argument_spec = dict(\n        commands=dict(type='list', required=True),\n\n        wait_for=dict(type='list', aliases=['waitfor']),\n        match=dict(default='all', choices=['all', 'any']),\n\n        retries=dict(default=10, type='int'),\n        interval=dict(default=1, type='int')\n    )\n\n    argument_spec.update(ios_argument_spec)\n\n    module = AnsibleModule(argument_spec=argument_spec,\n                           supports_check_mode=True)\n\n    result = {'changed': False}\n\n    warnings = list()\n    check_args(module, warnings)\n    commands = parse_commands(module, warnings)\n    result['warnings'] = warnings\n\n    wait_for = module.params['wait_for'] or list()\n    conditionals = [Conditional(c) for c in wait_for]\n\n    retries = module.params['retries']\n    interval = module.params['interval']\n    match = module.params['match']\n\n    while retries > 0:\n        responses = run_commands(module, commands)\n\n        for item in list(conditionals):\n            if item(responses):\n                if match == 'any':\n                    conditionals = list()\n                    break\n                conditionals.remove(item)\n\n        if not conditionals:\n            break\n\n        time.sleep(interval)\n        retries -= 1\n\n    if conditionals:\n        failed_conditions = [item.raw for item in conditionals]\n        msg = 'One or more conditional statements have not be satisfied'\n        module.fail_json(msg=msg, failed_conditions=failed_conditions)\n\n    result.update({\n        'changed': False,\n        'stdout': responses,\n        'stdout_lines': list(to_lines(responses))\n    })\n\n    module.exit_json(**result)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "lib/ansible/modules/network/ios/ios_command.py"}], "after_files": [{"content": "#!/usr/bin/python\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\nANSIBLE_METADATA = {'metadata_version': '1.1',\n                    'status': ['preview'],\n                    'supported_by': 'network'}\n\n\nDOCUMENTATION = \"\"\"\n---\nmodule: ios_command\nversion_added: \"2.1\"\nauthor: \"Peter Sprygada (@privateip)\"\nshort_description: Run commands on remote devices running Cisco IOS\ndescription:\n  - Sends arbitrary commands to an ios node and returns the results\n    read from the device. This module includes an\n    argument that will cause the module to wait for a specific condition\n    before returning or timing out if the condition is not met.\n  - This module does not support running commands in configuration mode.\n    Please use M(ios_config) to configure IOS devices.\nextends_documentation_fragment: ios\nnotes:\n  - Tested against IOS 15.6\noptions:\n  commands:\n    description:\n      - List of commands to send to the remote ios device over the\n        configured provider. The resulting output from the command\n        is returned. If the I(wait_for) argument is provided, the\n        module is not returned until the condition is satisfied or\n        the number of retries has expired.\n    required: true\n  wait_for:\n    description:\n      - List of conditions to evaluate against the output of the\n        command. The task will wait for each condition to be true\n        before moving forward. If the conditional is not true\n        within the configured number of retries, the task fails.\n        See examples.\n    required: false\n    default: null\n    aliases: ['waitfor']\n    version_added: \"2.2\"\n  match:\n    description:\n      - The I(match) argument is used in conjunction with the\n        I(wait_for) argument to specify the match policy.  Valid\n        values are C(all) or C(any).  If the value is set to C(all)\n        then all conditionals in the wait_for must be satisfied.  If\n        the value is set to C(any) then only one of the values must be\n        satisfied.\n    required: false\n    default: all\n    choices: ['any', 'all']\n    version_added: \"2.2\"\n  retries:\n    description:\n      - Specifies the number of retries a command should by tried\n        before it is considered failed. The command is run on the\n        target device every retry and evaluated against the\n        I(wait_for) conditions.\n    required: false\n    default: 10\n  interval:\n    description:\n      - Configures the interval in seconds to wait between retries\n        of the command. If the command does not pass the specified\n        conditions, the interval indicates how long to wait before\n        trying the command again.\n    required: false\n    default: 1\n\"\"\"\n\nEXAMPLES = \"\"\"\ntasks:\n  - name: run show version on remote devices\n    ios_command:\n      commands: show version\n\n  - name: run show version and check to see if output contains IOS\n    ios_command:\n      commands: show version\n      wait_for: result[0] contains IOS\n\n  - name: run multiple commands on remote nodes\n    ios_command:\n      commands:\n        - show version\n        - show interfaces\n\n  - name: run multiple commands and evaluate the output\n    ios_command:\n      commands:\n        - show version\n        - show interfaces\n      wait_for:\n        - result[0] contains IOS\n        - result[1] contains Loopback0\n\"\"\"\n\nRETURN = \"\"\"\nstdout:\n  description: The set of responses from the commands\n  returned: always apart from low level errors (such as action plugin)\n  type: list\n  sample: ['...', '...']\nstdout_lines:\n  description: The value of stdout split into a list\n  returned: always apart from low level errors (such as action plugin)\n  type: list\n  sample: [['...', '...'], ['...'], ['...']]\nfailed_conditions:\n  description: The list of conditionals that have failed\n  returned: failed\n  type: list\n  sample: ['...', '...']\n\"\"\"\nimport re\nimport time\n\nfrom ansible.module_utils.network.ios.ios import run_commands\nfrom ansible.module_utils.network.ios.ios import ios_argument_spec, check_args\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible.module_utils.network.common.utils import ComplexList\nfrom ansible.module_utils.network.common.parsing import Conditional\nfrom ansible.module_utils.six import string_types\n\n\ndef to_lines(stdout):\n    for item in stdout:\n        if isinstance(item, string_types):\n            item = str(item).split('\\n')\n        yield item\n\n\ndef parse_commands(module, warnings):\n    command = ComplexList(dict(\n        command=dict(key=True),\n        prompt=dict(),\n        answer=dict()\n    ), module)\n    commands = command(module.params['commands'])\n    for item in list(commands):\n        configure_type = re.match(r'conf(?:\\w*)(?:\\s+(\\w+))?', item['command'])\n        if module.check_mode and not item['command'].startswith('show'):\n            warnings.append(\n                'only show commands are supported when using check mode, not '\n                'executing `%s`' % item['command']\n            )\n            commands.remove(item)\n        elif configure_type and configure_type.group(1) not in ('confirm', 'replace', 'revert', 'network'):\n            module.fail_json(\n                msg='ios_command does not support running config mode '\n                    'commands.  Please use ios_config instead'\n            )\n    return commands\n\n\ndef main():\n    \"\"\"main entry point for module execution\n    \"\"\"\n    argument_spec = dict(\n        commands=dict(type='list', required=True),\n\n        wait_for=dict(type='list', aliases=['waitfor']),\n        match=dict(default='all', choices=['all', 'any']),\n\n        retries=dict(default=10, type='int'),\n        interval=dict(default=1, type='int')\n    )\n\n    argument_spec.update(ios_argument_spec)\n\n    module = AnsibleModule(argument_spec=argument_spec,\n                           supports_check_mode=True)\n\n    result = {'changed': False}\n\n    warnings = list()\n    check_args(module, warnings)\n    commands = parse_commands(module, warnings)\n    result['warnings'] = warnings\n\n    wait_for = module.params['wait_for'] or list()\n    conditionals = [Conditional(c) for c in wait_for]\n\n    retries = module.params['retries']\n    interval = module.params['interval']\n    match = module.params['match']\n\n    while retries > 0:\n        responses = run_commands(module, commands)\n\n        for item in list(conditionals):\n            if item(responses):\n                if match == 'any':\n                    conditionals = list()\n                    break\n                conditionals.remove(item)\n\n        if not conditionals:\n            break\n\n        time.sleep(interval)\n        retries -= 1\n\n    if conditionals:\n        failed_conditions = [item.raw for item in conditionals]\n        msg = 'One or more conditional statements have not be satisfied'\n        module.fail_json(msg=msg, failed_conditions=failed_conditions)\n\n    result.update({\n        'changed': False,\n        'stdout': responses,\n        'stdout_lines': list(to_lines(responses))\n    })\n\n    module.exit_json(**result)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "lib/ansible/modules/network/ios/ios_command.py"}]}