| 1 | --- |
| 2 | - name: Host Module Operations on Unity |
| 3 | hosts: localhost |
| 4 | connection: local |
| 5 | vars: |
| 6 | unispherehost: '10.*.*.*' |
| 7 | validate_certs: false |
| 8 | username: 'user' |
| 9 | password: '**' |
| 10 | host_name_1: "ansible-test-host-1" |
| 11 | host_name_2: "ansible-test-host-2" |
| 12 | host_name_3: "ansible-test-host" |
| 13 | new_host_name_1: "ansible-test-host-3" |
| 14 | new_host_name_2: "ansible-test-host-4" |
| 15 | |
| 16 | tasks: |
| 17 | - name: Create empty Host "{{ host_name_1 }}" |
| 18 | register: result |
| 19 | host: |
| 20 | unispherehost: "{{ unispherehost }}" |
| 21 | username: "{{ username }}" |
| 22 | password: "{{ password }}" |
| 23 | validate_certs: "{{ validate_certs }}" |
| 24 | host_name: "{{ host_name_1 }}" |
| 25 | host_os: "Linux" |
| 26 | description: "ansible-test-host-1" |
| 27 | state: "present" |
| 28 | |
| 29 | - name: Set host_id empty host |
| 30 | ansible.builtin.set_fact: |
| 31 | host_id_1: "{{ result.host_details.id }}" |
| 32 | |
| 33 | - name: Create empty Host "{{ host_name_3 }}" |
| 34 | host: |
| 35 | unispherehost: "{{ unispherehost }}" |
| 36 | username: "{{ username }}" |
| 37 | password: "{{ password }}" |
| 38 | validate_certs: "{{ validate_certs }}" |
| 39 | host_name: "{{ host_name_3 }}" |
| 40 | host_os: "Linux" |
| 41 | description: "ansible-test-host" |
| 42 | state: "present" |
| 43 | |
| 44 | - name: Create Host with Initiators "{{ host_name_2 }}" |
| 45 | register: result |
| 46 | host: |
| 47 | unispherehost: "{{ unispherehost }}" |
| 48 | username: "{{ username }}" |
| 49 | password: "{{ password }}" |
| 50 | validate_certs: "{{ validate_certs }}" |
| 51 | host_name: "{{ host_name_2 }}" |
| 52 | host_os: "Linux" |
| 53 | description: "ansible-test-host-2" |
| 54 | initiators: |
| 55 | - "20:00:00:90:FA:13:82:34:10:00:00:90:FA:13:82:34" |
| 56 | - "20:00:00:90:FA:13:81:8C:10:00:00:90:FA:13:81:8C" |
| 57 | initiator_state: "present-in-host" |
| 58 | state: "present" |
| 59 | |
| 60 | - name: Set host_id |
| 61 | ansible.builtin.set_fact: |
| 62 | host_id_2: "{{ result.host_details.id }}" |
| 63 | |
| 64 | - name: Get Host details using host_name. |
| 65 | host: |
| 66 | unispherehost: "{{ unispherehost }}" |
| 67 | username: "{{ username }}" |
| 68 | password: "{{ password }}" |
| 69 | validate_certs: "{{ validate_certs }}" |
| 70 | host_name: "{{ host_name_2 }}" |
| 71 | state: "present" |
| 72 | |
| 73 | - name: Get Host details using host_id. |
| 74 | host: |
| 75 | unispherehost: "{{ unispherehost }}" |
| 76 | username: "{{ username }}" |
| 77 | password: "{{ password }}" |
| 78 | validate_certs: "{{ validate_certs }}" |
| 79 | host_id: "{{ host_id_2 }}" |
| 80 | state: "present" |
| 81 | |
| 82 | - name: Modify Host using host_name |
| 83 | host: |
| 84 | unispherehost: "{{ unispherehost }}" |
| 85 | username: "{{ username }}" |
| 86 | password: "{{ password }}" |
| 87 | validate_certs: "{{ validate_certs }}" |
| 88 | host_name: "{{ host_name_1 }}" |
| 89 | host_os: "Mac OS" |
| 90 | description: "ansible-test-host-1" |
| 91 | state: "present" |
| 92 | |
| 93 | - name: Modify Host using host_id |
| 94 | host: |
| 95 | unispherehost: "{{ unispherehost }}" |
| 96 | username: "{{ username }}" |
| 97 | password: "{{ password }}" |
| 98 | validate_certs: "{{ validate_certs }}" |
| 99 | host_id: "{{ host_id_2 }}" |
| 100 | new_host_name: "{{ new_host_name_1 }}" |
| 101 | host_os: "Mac OS" |
| 102 | description: "ansible-test-host-3" |
| 103 | state: "present" |
| 104 | |
| 105 | - name: Add Initiators to Host. |
| 106 | host: |
| 107 | unispherehost: "{{ unispherehost }}" |
| 108 | username: "{{ username }}" |
| 109 | password: "{{ password }}" |
| 110 | validate_certs: "{{ validate_certs }}" |
| 111 | host_name: "{{ host_name_1 }}" |
| 112 | initiators: |
| 113 | - "20:00:00:90:FA:13:82:35:10:00:00:90:FA:13:82:35" |
| 114 | - "iqn.11-05.com.test:f14a6cef331b" |
| 115 | initiator_state: "present-in-host" |
| 116 | state: "present" |
| 117 | |
| 118 | - name: Modify multiple attributes of Host. |
| 119 | host: |
| 120 | unispherehost: "{{ unispherehost }}" |
| 121 | username: "{{ username }}" |
| 122 | password: "{{ password }}" |
| 123 | validate_certs: "{{ validate_certs }}" |
| 124 | host_name: "{{ host_name_1 }}" |
| 125 | new_host_name: "{{ new_host_name_2 }}" |
| 126 | host_os: "Linux" |
| 127 | description: "ansible-test-host-4" |
| 128 | initiators: |
| 129 | - "iqn.11-05.com.test:24514718452e" |
| 130 | initiator_state: "present-in-host" |
| 131 | state: "present" |
| 132 | |
| 133 | - name: Delete Host. {{ new_host_name_2 }} |
| 134 | host: |
| 135 | unispherehost: "{{ unispherehost }}" |
| 136 | username: "{{ username }}" |
| 137 | password: "{{ password }}" |
| 138 | validate_certs: "{{ validate_certs }}" |
| 139 | host_name: "{{ new_host_name_2 }}" |
| 140 | state: "absent" |
| 141 | |
| 142 | - name: Delete Host. {{ host_name_3 }} |
| 143 | host: |
| 144 | unispherehost: "{{ unispherehost }}" |
| 145 | username: "{{ username }}" |
| 146 | password: "{{ password }}" |
| 147 | validate_certs: "{{ validate_certs }}" |
| 148 | host_name: "{{ host_name_3 }}" |
| 149 | state: "absent" |
| 150 | |
| 151 | - name: Delete Host. {{ new_host_name_1 }} |
| 152 | host: |
| 153 | unispherehost: "{{ unispherehost }}" |
| 154 | username: "{{ username }}" |
| 155 | password: "{{ password }}" |
| 156 | validate_certs: "{{ validate_certs }}" |
| 157 | host_name: "{{ new_host_name_1 }}" |
| 158 | state: "absent" |
| 159 | |
| 160 | - name: Add network address to Host. |
| 161 | host: |
| 162 | unispherehost: "{{ unispherehost }}" |
| 163 | username: "{{ username }}" |
| 164 | password: "{{ password }}" |
| 165 | validate_certs: "{{ validate_certs }}" |
| 166 | host_name: "{{ host_name }}" |
| 167 | network_address: "192.*.*.*" |
| 168 | network_address_state: "present-in-host" |
| 169 | state: "present" |
| 170 | |
| 171 | - name: Delete network address from Host. |
| 172 | host: |
| 173 | unispherehost: "{{ unispherehost }}" |
| 174 | username: "{{ username }}" |
| 175 | password: "{{ password }}" |
| 176 | validate_certs: "{{ validate_certs }}" |
| 177 | host_name: "{{ host_name }}" |
| 178 | network_address: "192.*.*.*" |
| 179 | network_address_state: "absent-in-host" |
| 180 | state: "present" |