Repository: ansible/ansible

Issue:
ios_linkagg add member interfaces is failing
##### SUMMARY
The assignment of the interfaces to a port-channel fails.

The port-channel will be created. Tested on 

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ios_linkagg

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.6.1
  config file = /home/ansible/ansible/develop/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.5 (default, Apr 10 2018, 17:08:37) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
```

##### CONFIGURATION
...
ansible-config dump --only-changed
DEFAULT_ROLES_PATH(/home/ansible/ansible/develop/ansible.cfg) = ['/home/ansible/ansible/develop/roles', '/home/ansible/ansible/common/roles']
DEFAULT_VAULT_PASSWORD_FILE(/home/ansible/ansible/develop/ansible.cfg) = /home/ansible/.ssh/ansible-vault
...

##### OS / ENVIRONMENT
...
$ uname -a
Linux scvnetmgmt01 3.10.0-862.3.2.el7.x86_64 #1 SMP Mon May 21 23:36:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
...

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

<!--- Paste example playbooks or commands between quotes below -->
```
---

- hosts: ios
  gather_facts: no
  become: yes

  tasks:

    - name: "Set Port-Channel 10 configuration"
      ios_linkagg:
        group: 10
        state: present
        purge: no


    - name: "Add member ports to Port-Channel 10, LACP"
      ios_linkagg:
        group: 10
        mode: active
        members: 
          - TenGigabitEthernet1/1/4
          - TenGigabitEthernet2/1/4
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
member interfaces should be added to port-channel

interface TenGigabitEthernet1/1/4
 channel-group 1 mode active


##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ATKPACSE002#
fatal: [ATKPACSE002]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_e3L3dM/ansible_module_ios_linkagg.py\", line 316, in <module>\n    main()\n  File \"/tmp/ansible_e3L3dM/ansible_module_ios_linkagg.py\", line 310, in main\n    load_config(module, commands)\n  File \"/tmp/ansible_e3L3dM/ansible_modlib.zip/ansible/module_utils/network/ios/ios.py\", line 168, in load_config\n  File \"/tmp/ansible_e3L3dM/ansible_modlib.zip/ansible/module_utils/connection.py\", line 149, in __rpc__\nansible.module_utils.connection.ConnectionError: interface TenGigabitEthernet2/1/4\r\n              ^\r\n% Invalid input detected at '^' marker.\r\n\r\nATKPACSE002#\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}
        to retry, use: --limit @/home/ansible/ansible/develop/tasks/test_ios_linkagg.retry
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/network/ios/ios_linkagg.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/network/ios/ios_linkagg.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @privateip @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Hello,

You have something new on this bug, we encounter the same problem.

Thanks,

Resolving patch:
diff --git a/lib/ansible/modules/network/ios/ios_linkagg.py b/lib/ansible/modules/network/ios/ios_linkagg.py
--- a/lib/ansible/modules/network/ios/ios_linkagg.py
+++ b/lib/ansible/modules/network/ios/ios_linkagg.py
@@ -130,7 +130,7 @@ def map_obj_to_commands(updates, module):
 
         elif state == 'present':
             cmd = ['interface port-channel {0}'.format(group),
-                   'end']
+                   'exit']
             if not obj_in_have:
                 if not group:
                     module.fail_json(msg='group is a required option')


Test patch: