summaryrefslogtreecommitdiffstats
path: root/ansible_collections/cisco/ise/playbooks/trustsec_nbarapp.yml
blob: 98937292c9fb141c0ea828fdee9525150a346ab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
- hosts: ise_servers
  gather_facts: false

  vars:
    ise_login: &ise_login
      ise_hostname: "{{ ise_hostname }}"
      ise_username: "{{ ise_username }}"
      ise_password: "{{ ise_password }}"
      ise_verify: "{{ ise_verify }}"
      ise_debug: "{{ ise_debug }}"

  tasks:
    # - name: '[Get Nbar Apps]'
    #   cisco.ise.trustsec_nbar_app_info:
    #     <<: *ise_login
    #     page: 1
    #     size: 100
    #   register: nbar_app_all

    # - name: '[Print Nbar Apps]'
    #   ansible.builtin.debug:
    #     var: nbar_app_all

    - name: Get Nbar App filtered by name
      cisco.ise.trustsec_nbar_app_info:
        <<: *ise_login
        filter: name.EQ.hyperwave-isp
      register: nbar_app_filtered

    - name: Get Nbar App by id
      cisco.ise.trustsec_nbar_app_info:
        <<: *ise_login
        id: "{{ nbar_app_filtered.ise_responses[0].id }}"
      when:
        - nbar_app_filtered is defined
        - nbar_app_filtered.ise_responses is defined
        - nbar_app_filtered.ise_responses | length > 0
      register: nbar_app_by_id

    - name: Print Nbar App by id
      ansible.builtin.debug:
        var: nbar_app_by_id

    - name: Create Nbar App duplicate
      cisco.ise.trustsec_nbar_app:
        <<: *ise_login
        state: present
        name: "{{ nbar_app_by_id.ise_response[0].name}}-2"
        description: "{{ nbar_app_by_id.ise_response[0].description|int + 1 }}"
        networkIdentities:
          - ports: "{{ nbar_app_by_id.ise_response[0].networkIdentities[0].ports|int +1 }}"
            protocol: "{{ nbar_app_by_id.ise_response[0].networkIdentities[0].protocol }}"
          - ports: "{{ nbar_app_by_id.ise_response[0].networkIdentities[1].ports|int +1 }}"
            protocol: "{{ nbar_app_by_id.ise_response[0].networkIdentities[1].protocol }}"
      when:
        - nbar_app_by_id is defined
        - nbar_app_by_id.ise_response is defined
        - nbar_app_by_id.ise_response | length == 1
      register: nbar_app_manage

    - name: Print Create Nbar
      ansible.builtin.debug:
        var: nbar_app_manage

    - name: Update Nbar App duplicate
      cisco.ise.trustsec_nbar_app:
        <<: *ise_login
        state: present
        name: "{{ nbar_app_by_id.ise_response[0].name}}-2"
        description: "{{ nbar_app_by_id.ise_response[0].description|int + 1 }}"
        networkIdentities:
          - ports: "{{ nbar_app_by_id.ise_response[0].networkIdentities[0].ports|int +2 }}"
            protocol: "{{ nbar_app_by_id.ise_response[0].networkIdentities[0].protocol }}"
          - ports: "{{ nbar_app_by_id.ise_response[0].networkIdentities[1].ports|int +2 }}"
            protocol: "{{ nbar_app_by_id.ise_response[0].networkIdentities[1].protocol }}"
      when:
        - nbar_app_by_id is defined
        - nbar_app_by_id.ise_response is defined
        - nbar_app_by_id.ise_response | length == 1
      register: nbar_app_manage

    - name: Print Update Nbar
      ansible.builtin.debug:
        var: nbar_app_manage

    - name: Delete Nbar App duplicate
      cisco.ise.trustsec_nbar_app:
        <<: *ise_login
        state: absent
        name: "{{ nbar_app_by_id.ise_response[0].name}}-2"
        description: "{{ nbar_app_by_id.ise_response[0].description|int + 1 }}"
        networkIdentities:
          - ports: "{{ nbar_app_by_id.ise_response[0].networkIdentities[0].ports|int +1 }}"
            protocol: "{{ nbar_app_by_id.ise_response[0].networkIdentities[0].protocol }}"
          - ports: "{{ nbar_app_by_id.ise_response[0].networkIdentities[1].ports|int +1 }}"
            protocol: "{{ nbar_app_by_id.ise_response[0].networkIdentities[1].protocol }}"
      when:
        - nbar_app_by_id is defined
        - nbar_app_by_id.ise_response is defined
        - nbar_app_by_id.ise_response | length == 1
      register: nbar_app_manage

    - name: "Print Delete Nbar"
      ansible.builtin.debug:
        var: nbar_app_manage