# FILEPATH: /Users/bramvandendaele/Documents/aperam/ansible/automation/aruba_first-playbook.yml # This playbook prepares a switch for REST API, copies the primary image to the secondary slot, # checks the boot info after the copy, downloads a new image to the primary slot, and reboots the switch. # This section of the playbook is responsible for downloading a new firmware image to the primary slot of the switch. # The `arubaoss_file_transfer` module is used to download the firmware from a specified URL. # The `file_type` is set to "FTT_FIRMWARE" indicating that the file being transferred is a firmware image. # The `action` is set to "FTA_DOWNLOAD" to download the file. # SSL is used for the file transfer (`use_ssl: true`) but certificate validation is disabled (`validate_certs: false`). # The file is downloaded to the primary boot image slot (`boot_image: BI_PRIMARY_IMAGE`). # This task is only executed if the current boot image is the primary image, the switch type is "YC", and the primary version is not "16.11.0016". # If the task fails, the playbook continues due to `ignore_errors: true`. # The next section of the playbook disables the REST interface on the switch and clears the certificate for upgrade. # The `arubaoss_command` module is used to execute a series of commands on the switch. # These tasks are only executed if the current boot image is the primary image. # The playbook then retrieves the boot information after the new firmware has been downloaded using the `aruba_get-boot-info` role. # Finally, the playbook saves the running configuration to memory using the `write memory` command. # The switch is scheduled to reload at a specified time and date. # This task is only executed if the current boot image is the primary image, the primary version is "16.11.0016", and the NTP status is "Synchronized". # The output of this task is saved to the `output` variable. --- - name: Setup hosts #become: true #become_user: root #become_method: su hosts: localhost roles: - awx_import-hosts-from-list ### PREPARE SWITCH FOR REST API + OUTPUT BOOT INFO" - hosts: aruba_hosts gather_facts: false collections: - arubanetworks.aos_switch - ansible.netcommon vars: ansible_connection: network_cli ansible_command_timeout: 180 # ansible_connection: local environment: NETWORK_GROUP_MODULES: arubaoss ANSIBLE_CONFIG: config/ansible.cfg roles: - aruba_prepare-rest - aruba_get-boot-info - aruba_get-ntp-info tasks: - name: Copy primary to secondary arubaoss_command: commands: ['config', 'copy flash flash Secondary'] when: boot == "Primary" and primary_version != "16.11.0016" # This task copies the primary configuration to the secondary device # if the boot mode is set to "Primary" and the primary version is not "16.11.0016" ###CHECK BOOT INFO AFTER COPY OF PRIMARY TO SECONDARY### - hosts: all gather_facts: false collections: - arubanetworks.aos_switch - ansible.netcommon vars: ansible_connection: network_cli # ansible_connection: local environment: NETWORK_GROUP_MODULES: arubaoss tasks: - name: Get boot info after copy primary to secondary ansible.builtin.include_role: name: aruba_get-boot-info - name: save running config arubaoss_command: commands: ['write memory'] when: boot == "Primary" ###DOWNLOAD NEW IMAGE TO PRIMARY SLOT AND REBOOT### - hosts: all collections: - arubanetworks.aos_switch - ansible.netcommon vars: ansible_connection: local ansible_command_timeout: 180 environment: NETWORK_GROUP_MODULES: arubaoss tasks: - name: Download and install YA firmware to primary arubaoss_file_transfer: file_url: "http://10.245.3.54/test/YA_16_11_0016.swi" file_type: "FTT_FIRMWARE" action: "FTA_DOWNLOAD" use_ssl: true validate_certs: false port: 443 boot_image: BI_PRIMARY_IMAGE ignore_errors: true when: boot == "Primary" and type == "YA" and primary_version != "16.11.0016" - name: Download and install YB firmware to primary arubaoss_file_transfer: file_url: "http://10.245.3.54/test/YB_16_11_0016.swi" file_type: "FTT_FIRMWARE" action: "FTA_DOWNLOAD" use_ssl: true validate_certs: false port: 443 boot_image: BI_PRIMARY_IMAGE ignore_errors: true when: boot == "Primary" and type == "YB" and primary_version != "16.11.0016" - name: Download and install YC firmware to primary arubaoss_file_transfer: file_url: "http://10.245.3.54/test/YC_16_11_0016.swi" file_type: "FTT_FIRMWARE" action: "FTA_DOWNLOAD" use_ssl: true validate_certs: false port: 443 retries: 3 boot_image: BI_PRIMARY_IMAGE ignore_errors: true when: boot == "Primary" and type == "YC" and primary_version != "16.11.0016" - hosts: all gather_facts: false collections: - arubanetworks.aos_switch - ansible.netcommon vars: ansible_connection: network_cli ansible_command_timeout: 180 environment: NETWORK_GROUP_MODULES: arubaoss tasks: - name: disable rest arubaoss_command: commands: [ 'conf', 'no rest-interface', 'no web-management ssl', 'aaa authentication rest login local none', 'aaa authentication rest enable local none'] when: boot == "Primary" - name: clear cert arubaoss_command: commands: - command: "conf" - command: 'crypto pki clear certificate-name upgrade' prompt: - '.*Continue.*' answer: - y when: boot == "Primary" - name: Get boot info after download of new firmware ansible.builtin.include_role: name: aruba_get-boot-info - name: write config to memory and reload on specified timeslot arubaoss_command: commands: - command: 'write memory' # - command: 'reload after {{reload_time}} {{ reload_date }}' - command: 'reload at {{reload_time}} {{ reload_date }}' prompt: - '.*reboot.*' answer: - y # - command: 'no reload' when: boot == "Primary" and primary_version == "16.11.0016" and ntp_status == "Synchronized" register: output # changed_when: boot == "Primary" and primary_version != "16.11.0016" #when: boot == "Primary" and primary_version != "16.11.0016"