|  | 
|  | 1 | +--- | 
|  | 2 | +- name: Test juniper_junos_rpc module | 
|  | 3 | +  hosts: all | 
|  | 4 | +  connection: local | 
|  | 5 | +  gather_facts: no | 
|  | 6 | +  roles: | 
|  | 7 | +    - Juniper.junos | 
|  | 8 | + | 
|  | 9 | +  tasks: | 
|  | 10 | +################# | 
|  | 11 | +    - name: "Execute single RPC get-software-information without any kwargs" | 
|  | 12 | +      juniper_junos_rpc: | 
|  | 13 | +        host: "{{ ansible_ssh_host }}" | 
|  | 14 | +        port: "{{ ansible_ssh_port }}" | 
|  | 15 | +        user: "{{ ansible_ssh_user }}" | 
|  | 16 | +        passwd: "{{ ansible_ssh_pass }}" | 
|  | 17 | +        rpcs: | 
|  | 18 | +          - "get-software-information" | 
|  | 19 | +      register: test1 | 
|  | 20 | +      ignore_errors: True | 
|  | 21 | +      tags: [ test1 ] | 
|  | 22 | + | 
|  | 23 | +    - name: Check TEST 1 | 
|  | 24 | +      assert: | 
|  | 25 | +        that: | 
|  | 26 | +          - test1.msg == "The RPC executed successfully." | 
|  | 27 | +      tags: [ test1 ] | 
|  | 28 | + | 
|  | 29 | +################# | 
|  | 30 | +    - name: "Get Device Configuration with dest" | 
|  | 31 | +      juniper_junos_rpc: | 
|  | 32 | +        host: "{{ ansible_ssh_host }}" | 
|  | 33 | +        port: "{{ ansible_ssh_port }}" | 
|  | 34 | +        user: "{{ ansible_ssh_user }}" | 
|  | 35 | +        passwd: "{{ ansible_ssh_pass }}" | 
|  | 36 | +        rpc: get-config | 
|  | 37 | +        dest: get_config.conf | 
|  | 38 | +      register: test2 | 
|  | 39 | +      ignore_errors: True | 
|  | 40 | +      tags: [ test2 ] | 
|  | 41 | + | 
|  | 42 | +    - name: Check that the get_config.conf exists | 
|  | 43 | +      stat: | 
|  | 44 | +        path: get_config.conf | 
|  | 45 | +      register: stat_result | 
|  | 46 | + | 
|  | 47 | +    - name: Check TEST 2 | 
|  | 48 | +      assert: | 
|  | 49 | +        that: | 
|  | 50 | +          - test2.msg == "The \"get-config\" RPC executed successfully." | 
|  | 51 | +          - stat_result.stat.exists == True | 
|  | 52 | +      tags: [ test2 ] | 
|  | 53 | + | 
|  | 54 | +    - name: Clean up TEST 2 | 
|  | 55 | +      file: | 
|  | 56 | +        path: get_config.conf | 
|  | 57 | +        state: absent | 
|  | 58 | +################# | 
|  | 59 | + | 
|  | 60 | +    - name: "Get Device Configuration in text" | 
|  | 61 | +      juniper_junos_rpc: | 
|  | 62 | +        host: "{{ ansible_ssh_host }}" | 
|  | 63 | +        port: "{{ ansible_ssh_port }}" | 
|  | 64 | +        user: "{{ ansible_ssh_user }}" | 
|  | 65 | +        passwd: "{{ ansible_ssh_pass }}" | 
|  | 66 | +        rpc: get-interface-information | 
|  | 67 | +        kwargs: "interface_name=em0" | 
|  | 68 | +        format: text | 
|  | 69 | +      register: test3 | 
|  | 70 | +      ignore_errors: True | 
|  | 71 | +      tags: [ test3 ] | 
|  | 72 | + | 
|  | 73 | +    - name: Check TEST 3 | 
|  | 74 | +      assert: | 
|  | 75 | +        that: | 
|  | 76 | +          - test3.msg == "The RPC executed successfully." | 
|  | 77 | +      tags: [ test3 ] | 
|  | 78 | + | 
|  | 79 | +################# | 
|  | 80 | + | 
|  | 81 | +    - name: "Execute multiple RPCs without any kwargs" | 
|  | 82 | +      juniper_junos_rpc: | 
|  | 83 | +        host: "{{ ansible_ssh_host }}" | 
|  | 84 | +        port: "{{ ansible_ssh_port }}" | 
|  | 85 | +        user: "{{ ansible_ssh_user }}" | 
|  | 86 | +        passwd: "{{ ansible_ssh_pass }}" | 
|  | 87 | +        rpcs: | 
|  | 88 | +          - "get-software-information" | 
|  | 89 | +          - "get-interface-information" | 
|  | 90 | +        dest: get_config.conf | 
|  | 91 | +      register: test4 | 
|  | 92 | +      ignore_errors: True | 
|  | 93 | +      tags: [ test4 ] | 
|  | 94 | + | 
|  | 95 | +    - name: Check TEST 4 | 
|  | 96 | +      assert: | 
|  | 97 | +        that: | 
|  | 98 | +          - test4.results[0].msg == "The RPC executed successfully." | 
|  | 99 | +          - test4.results[1].msg == "The RPC executed successfully." | 
|  | 100 | +      tags: [ test4 ] | 
|  | 101 | + | 
|  | 102 | +    - name: Clean up TEST 4 | 
|  | 103 | +      file: | 
|  | 104 | +        path: get_config.conf | 
|  | 105 | +        state: absent | 
|  | 106 | + | 
|  | 107 | +################# | 
|  | 108 | + | 
|  | 109 | +    - name: "Execute multiple RPCs with multiple kwargs" | 
|  | 110 | +      juniper_junos_rpc: | 
|  | 111 | +        host: "{{ ansible_ssh_host }}" | 
|  | 112 | +        port: "{{ ansible_ssh_port }}" | 
|  | 113 | +        user: "{{ ansible_ssh_user }}" | 
|  | 114 | +        passwd: "{{ ansible_ssh_pass }}" | 
|  | 115 | +        rpcs: | 
|  | 116 | +          - "get-software-information" | 
|  | 117 | +          - "get-interface-information" | 
|  | 118 | +        kwargs: | 
|  | 119 | +          - {} | 
|  | 120 | +          - "interface_name=em0" | 
|  | 121 | +      register: test5 | 
|  | 122 | +      ignore_errors: True | 
|  | 123 | +      tags: [ test5 ] | 
|  | 124 | + | 
|  | 125 | +    - name: Check TEST 5 | 
|  | 126 | +      assert: | 
|  | 127 | +        that: | 
|  | 128 | +          - test5.results[0].msg == "The RPC executed successfully." | 
|  | 129 | +          - test5.results[1].msg == "The RPC executed successfully." | 
|  | 130 | +      tags: [ test5 ] | 
|  | 131 | + | 
|  | 132 | +################# | 
|  | 133 | +    - name: Creates directory | 
|  | 134 | +      file: | 
|  | 135 | +        path: out | 
|  | 136 | +        state: directory | 
|  | 137 | + | 
|  | 138 | +    - name: "Execute multiple RPCs with multiple kwargs and dest-dir" | 
|  | 139 | +      juniper_junos_rpc: | 
|  | 140 | +        host: "{{ ansible_ssh_host }}" | 
|  | 141 | +        port: "{{ ansible_ssh_port }}" | 
|  | 142 | +        user: "{{ ansible_ssh_user }}" | 
|  | 143 | +        passwd: "{{ ansible_ssh_pass }}" | 
|  | 144 | +        rpcs: | 
|  | 145 | +          - "get-software-information" | 
|  | 146 | +          - "get-interface-information" | 
|  | 147 | +        kwargs: | 
|  | 148 | +          - {} | 
|  | 149 | +          - "interface_name=em0" | 
|  | 150 | +        dest_dir: "out" | 
|  | 151 | +      register: test6 | 
|  | 152 | +      ignore_errors: True | 
|  | 153 | +      tags: [ test6 ] | 
|  | 154 | + | 
|  | 155 | +    - name: Check get-interface-information.xml exists | 
|  | 156 | +      stat: | 
|  | 157 | +        path: "out/{{ ansible_ssh_host }}_get-interface-information.xml" | 
|  | 158 | +      register: stat_result_1 | 
|  | 159 | + | 
|  | 160 | +    - name: Check get-software-information.xml exists | 
|  | 161 | +      stat: | 
|  | 162 | +        path: "out/{{ ansible_ssh_host }}_get-software-information.xml" | 
|  | 163 | +      register: stat_result_2 | 
|  | 164 | + | 
|  | 165 | +    - name: Check TEST 6 | 
|  | 166 | +      assert: | 
|  | 167 | +        that: | 
|  | 168 | +          - test6.results[0].msg == "The RPC executed successfully." | 
|  | 169 | +          - test6.results[1].msg == "The RPC executed successfully." | 
|  | 170 | +          - stat_result_1.stat.exists == True | 
|  | 171 | +          - stat_result_2.stat.exists == True | 
|  | 172 | +      tags: [ test6 ] | 
|  | 173 | + | 
|  | 174 | +    - name: Clean up TEST 6 | 
|  | 175 | +      file: | 
|  | 176 | +        path: out | 
|  | 177 | +        state: absent | 
|  | 178 | + | 
|  | 179 | +################# | 
|  | 180 | +    - name: Get Device Configuration for interface | 
|  | 181 | +      juniper_junos_rpc: | 
|  | 182 | +        host: "{{ ansible_ssh_host }}" | 
|  | 183 | +        port: "{{ ansible_ssh_port }}" | 
|  | 184 | +        user: "{{ ansible_ssh_user }}" | 
|  | 185 | +        passwd: "{{ ansible_ssh_pass }}" | 
|  | 186 | +        rpc: get-config | 
|  | 187 | +        filter_xml: "<configuration><interfaces/></configuration>" | 
|  | 188 | +      register: test7 | 
|  | 189 | +      ignore_errors: True | 
|  | 190 | +      tags: [ test7 ] | 
|  | 191 | + | 
|  | 192 | +    - name: Check TEST 7 | 
|  | 193 | +      assert: | 
|  | 194 | +        that: | 
|  | 195 | +          - test7.msg == "The \"get-config\" RPC executed successfully." | 
|  | 196 | +      tags: [ test7 ] | 
|  | 197 | + | 
|  | 198 | +################# | 
|  | 199 | +    - name: "Execute wrong RPC to generate RPC error" | 
|  | 200 | +      juniper_junos_rpc: | 
|  | 201 | +        host: "{{ ansible_ssh_host }}" | 
|  | 202 | +        port: "{{ ansible_ssh_port }}" | 
|  | 203 | +        user: "{{ ansible_ssh_user }}" | 
|  | 204 | +        passwd: "{{ ansible_ssh_pass }}" | 
|  | 205 | +        rpcs: | 
|  | 206 | +          - "wrong-rpc" | 
|  | 207 | +      register: test8 | 
|  | 208 | +      ignore_errors: True | 
|  | 209 | +      tags: [ test8 ] | 
|  | 210 | + | 
|  | 211 | +    - name: Check TEST 8 | 
|  | 212 | +      assert: | 
|  | 213 | +        that: | 
|  | 214 | +          - '"Unable to execute the RPC" in test8.msg' | 
|  | 215 | +      tags: [ test8 ] | 
|  | 216 | + | 
|  | 217 | +################# | 
0 commit comments