|
| 1 | +# Optimizing Playbooks |
| 2 | + |
| 3 | +By using all of the following optimizations together its estimated that playbook execution time can be reduced by up to 60% compared to default behavior. |
| 4 | + |
| 5 | +## Using the ACI HTTPAPI plugin |
| 6 | + |
| 7 | +The Ansible ACI HTTPAPI plugin instructs Ansible how to interact with an APIC's HTTP based API and execute tasks on the APIC. |
| 8 | + |
| 9 | +### Benefits |
| 10 | + |
| 11 | +- The ACI login credentials and ansible variables can stay in the inventory. |
| 12 | +- Logs in once and executes subsequent tasks without requiring additional logins. |
| 13 | +- Automatically refreshes a login if the token expires during the playbook. |
| 14 | +- Assists with overcoming rate limiting on logins. |
| 15 | +- Leverages APIC's high availability by allowing a list of APIC hosts to be defined as a single ansible host. |
| 16 | + |
| 17 | +### Enabling the plugin |
| 18 | + |
| 19 | +The httpapi plugin can be enabled by setting the following variables: |
| 20 | + |
| 21 | +```ini |
| 22 | +ansible_connection=ansible.netcommon.httpapi |
| 23 | +ansible_network_os=cisco.aci.aci |
| 24 | +``` |
| 25 | + |
| 26 | +Instead of using `hostname`, `username` & `password` in the playbook, the following variables can be used in the inventory. |
| 27 | + |
| 28 | +```ini |
| 29 | +ansible_user=admin |
| 30 | +ansible_password="SomeSecretPassword" |
| 31 | +``` |
| 32 | + |
| 33 | +The `ansible_host` variable can contain one or more APIC hosts separated by a comma. If multiple hosts are defined the plugin will try executing tasks on the hosts in the order listed until one completes or they all fail. |
| 34 | + |
| 35 | +```ini |
| 36 | +single_apic ansible_host=apic.host |
| 37 | +cluster_apic ansible_host=apic1.host,apic2.host,apic3.host |
| 38 | +``` |
| 39 | + |
| 40 | +Signature-based authentication can be specified in the inventory. |
| 41 | + |
| 42 | +```ini |
| 43 | +ansible_httpapi_session_key={'admin': "{{ lookup('file', 'admin.key')}}"} |
| 44 | +``` |
| 45 | + |
| 46 | +Note: `ansible_httpapi_session_key` takes precedence over `ansible_password`. |
| 47 | + |
| 48 | +### Full Example Inventory using ACI HTTPAPI plugin |
| 49 | + |
| 50 | +```ini |
| 51 | +[aci] |
| 52 | +single_apic ansible_host=apic.host |
| 53 | +cluster_apic ansible_host=apic1.host,apic2.host,apic3.host |
| 54 | + |
| 55 | +[aci:vars] |
| 56 | +ansible_user=admin |
| 57 | +ansible_password="SomeSecretPassword" |
| 58 | +ansible_connection=ansible.netcommon.httpapi |
| 59 | +ansible_network_os=cisco.aci.aci |
| 60 | +``` |
| 61 | + |
| 62 | +## Using the `suppress_` options |
| 63 | + |
| 64 | +Two options are available to users on all ACI modules to assist with optimizing playbook performance by reducing API calls. These options can increase playbook performance at the expense of suppressing some features of the modules. |
| 65 | + |
| 66 | +### `suppress_previous` |
| 67 | + |
| 68 | +If enabled, a GET call to check previous object state will not be sent before a POST update to APIC. |
| 69 | + |
| 70 | +> [!WARNING] |
| 71 | +> This causes the previous return value to be empty. The previous state of the object will not be checked and POST update calls to APIC will contain all properties specified in the task. |
| 72 | +
|
| 73 | +#### `suppress_previous` Aliases |
| 74 | + |
| 75 | +- `no_previous` |
| 76 | +- `ignore_previous` |
| 77 | + |
| 78 | +#### `suppress_previous` Example |
| 79 | + |
| 80 | +```yml |
| 81 | +- hosts: aci |
| 82 | + gather_facts: no |
| 83 | + |
| 84 | + tasks: |
| 85 | + - name: Add a new EPG |
| 86 | + cisco.aci.aci_epg: |
| 87 | + tenant: production |
| 88 | + ap: intranet |
| 89 | + epg: web_epg |
| 90 | + description: Web Intranet EPG |
| 91 | + bd: prod_bd |
| 92 | + suppress_previous: true |
| 93 | + delegate_to: localhost |
| 94 | +``` |
| 95 | +
|
| 96 | +### `suppress_verification` |
| 97 | + |
| 98 | +If enabled, a verifying GET call to check current object state will not be sent after a POST call to APIC. |
| 99 | + |
| 100 | +> [!WARNING] |
| 101 | +> This causes the current return value to be set to the proposed value. The current object state including default values will be unverifiable until another task executes for the same object. |
| 102 | + |
| 103 | +#### `suppress_verification` Aliases |
| 104 | + |
| 105 | +- `no_verification` |
| 106 | +- `no_verify` |
| 107 | +- `suppress_verify` |
| 108 | + |
| 109 | +#### `suppress_verification` Example |
| 110 | + |
| 111 | +```yml |
| 112 | +- hosts: aci |
| 113 | + gather_facts: no |
| 114 | +
|
| 115 | + tasks: |
| 116 | + - name: Add a new EPG |
| 117 | + cisco.aci.aci_epg: |
| 118 | + tenant: production |
| 119 | + ap: intranet |
| 120 | + epg: web_epg |
| 121 | + description: Web Intranet EPG |
| 122 | + bd: prod_bd |
| 123 | + suppress_verification: true |
| 124 | + delegate_to: localhost |
| 125 | +``` |
0 commit comments