1# Ansible Role: enos_command - Exceutes any CLI command on switch and results are displayed. 2--- 3<add role description below> 4 5 Sends arbitrary commands to an ENOS node and returns the results 6 read from the device. The C(enos_command) module includes an 7 argument that will cause the module to wait for a specific condition 8 before returning or timing out if the condition is not met. 9 10## Requirements 11--- 12<add role requirements information below> 13 14- Ansible version 2.4 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html)) 15- Lenovo switches running ENOS version 8.4.1.0 or later 16- an SSH connection to the Lenovo switch (SSH must be enabled on the network device) 17 18 19## Role Variables 20--- 21<add role variables information below> 22Available variables are listed below, along with description. 23 24The following are mandatory inventory variables: 25 26Variable | Description 27--- | --- 28`ansible_connection` | Has to be `network_cli` 29`ansible_network_os` | Has to be `enos` 30`ansible_ssh_user` | Specifies the username used to log into the switch 31`ansible_ssh_pass` | Specifies the password used to log into the switch 32 33These are the various options the customer have in executing the enos_command modules: 34 35Variable | Description 36--- | --- 37`commands` | List of commands to send to the remote device over the configured provider. The resulting output from the command is returned. If the I(wait_for) argument is provided, the module is not returned until the condition is satisfied or the number of retires as expired. 38`wait_for` | List of conditions to evaluate against the output of the command. The task will wait for each condition to be true before moving forward. If the conditional is not true within the configured number of retries, the task fails. See examples. 39`match` | The I(match) argument is used in conjunction with the I(wait_for) argument to specify the match policy. Valid values are C(all) or C(any). If the value is set to C(all) then all conditionals in the wait_for must be satisfied. If the value is set to C(any) then only one of the values must be satisfied. 40`retries` | Specifies the number of retries a command should by tried before it is considered failed. The command is run on the target device every retry and evaluated against the I(wait_for) conditions. 41`interval` | Configures the interval in seconds to wait between retries of the command. If the command does not pass the specified conditions, the interval indicates how long to wait before trying the command again. 42 43Need to specify these variables in vars/main.yml under variable `cli` 44 45Variable | Description 46--- | --- 47`host` | Has to be "{{ inventory_hostname }}" 48`port` | Has to be`22` 49`username` | User Name of switch 50`password` | Password of switch 51`timeout` | time out value for CLI 52`authorixe` | Whether u have to enter enable mode for data collection. 53`auth_pass`| Enable Password if required 54 55 56## Dependencies 57--- 58<add dependencies information below> 59 60- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access. 61- username.common - Performs common server configuration. 62- enos_command.py - This module file will be located at lib/ansible/modules/network/enos/ of Ansible installation. 63- enos.py - This module util file will be located at lib/ansible/module_utils/network/enos of Ansible installation. 64- enos.py - This module plugin file will be located at lib/ansible/plugins/action of Ansible installation. 65- enos.py - This module plugin file will be located at lib/ansible/plugins/cliconf of Ansible installation. 66- enos.py - This module plugin file will be located at lib/ansible/plugins/cliconf of Ansible installation. 67- /usr/local/etc/ansible/hosts - You must edit the */usr/local/etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_command_sample_hosts* for a sample configuration. 68 69Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up. 70 71Open the */usr/local/etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */usr/local/etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory. 72 73``` 74[enos_command] 7510.241.105.24 ansible_connection=network_cli ansible_network_os=enos ansible_ssh_user=<username> ansible_ssh_pass=<password> 76``` 77 78**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices. 79 80 81## Example Playbook 82--- 83<add playbook samples below> 84 85To execute an Ansible playbook, use the following command: 86 87``` 88ansible-playbook enos_command_sample.yml -vvv 89``` 90 91`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution. 92 93``` 94 - name: Module to do some CLI Command configurations 95 hosts: enos_command 96 gather_facts: no 97 connection: network_cli 98 roles: 99 - enos_command 100``` 101 102## License 103--- 104<add license information below> 105Copyright (C) 2017 Lenovo, Inc. 106 107This file is part of Ansible 108 109Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, eithe 110r version 3 of the License, or (at your option) any later version. 111 112Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PU 113RPOSE. See the GNU General Public License for more details. 114 115You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>. 116