-
Notifications
You must be signed in to change notification settings - Fork 104
FortiOS: update logic in the initial playbook #3336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Changes in Release 26.05 | ||
|
|
||
| ```eval_rst | ||
| .. contents:: Table of Contents | ||
| :depth: 2 | ||
| :local: | ||
| ``` | ||
|
|
||
| (release-26.05)= | ||
| ## New Functionality | ||
|
|
||
| * Something new | ||
|
|
||
| **Minor improvements** | ||
|
|
||
| * Something new | ||
|
|
||
| (release-26.05-device-features)= | ||
| ## New Device Features | ||
|
|
||
| FortiOS: | ||
| * Generate API token during initial device configuration | ||
| * Streamline and speed up the initial device configuration (which could be a [breaking change](release-26.05-breaking-fortios) if you use an old FortiOS version without a license). | ||
|
|
||
| (release-26.05-device-fixes)= | ||
| ## Fixes in Configuration Templates | ||
|
|
||
| Arista EOS: | ||
| * Something new | ||
|
|
||
| (release-26.05-breaking)= | ||
| ## Breaking changes | ||
|
|
||
| (release-26.05-breaking-fortios)= | ||
| We made major changes to the **fortinet** initial device configuration playbook: | ||
|
|
||
| * The playbook generates an API token for the **netlab** user (which should have been added during the Vagrant box creation process). Set `netlab_generate_api_token` node/group variable to `False` to disable this step. | ||
| * The configuration deployment process uses HTTPS instead of HTTP (which just redirects to HTTPS in most cases). This might not work if you're using a Fortinet device without a license. Set the following node/group variables to use HTTP: | ||
|
|
||
| ``` | ||
| ansible_httpapi_use_ssl: false | ||
| ansible_httpapi_port: 80 | ||
| ``` | ||
|
|
||
| * The playbook tries to reach the FortiOS HTTPS server immediately after switching to multi-VDOM mode and will retry several times. When needed, use [these node/group variables](caveats-fortios-70) to increase the wait time. | ||
|
|
||
| (bug-fixes-26.05)= | ||
| ## Bug Fixes | ||
|
|
||
| * Bugs were fixed | ||
|
|
||
| (doc-fixes-26.05)= | ||
| ## Documentation Fixes | ||
|
|
||
| * Docs were fixed |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,52 +3,78 @@ | |
| ansible.builtin.set_fact: | ||
| netlab_vdom_is_enabled: "{{ netlab_vdom is defined and netlab_vdom != vdom }}" | ||
|
|
||
| - name: Enable api-user authentication | ||
| block: | ||
| - name: Generate api-user token | ||
| delegate_to: localhost | ||
| expect: | ||
| command: >- | ||
| sshpass -p '{{ ansible_ssh_pass }}' | ||
| ssh -o UserKnownHostsFile=/dev/null | ||
| -o StrictHostKeyChecking=no | ||
| {{ ansible_user }}@{{ ansible_host }} | ||
| responses: | ||
| "password": "{{ ansible_ssh_pass }}" | ||
| "#": | ||
| - config global | ||
| - config system api-user | ||
| - edit "netlab" | ||
| - set accprofile "super_admin" | ||
| - next | ||
| - end | ||
| - execute api-user generate-key netlab | ||
| - exit | ||
|
Comment on lines
+16
to
+26
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. responses:
"password": "{{ ansible_ssh_pass }}"
"#":
- config system api-user
- edit "netlab"
- set accprofile "super_admin"
- next
- end
- config global
- execute api-user generate-key netlab
- exitI've just tested with this, and I've got the famous: it works for me!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logically I do not see much difference between admin user and netlab api-user. If one is set in a vagrant box the other could be configured at the same time. Screen scraping works, but it has its drawbacks. On the other end of the spectrum one could prebuild the whole config including both both users and feed it via cloud-image along with a license. Or use admin-scp. But in any case API token is sort of a problem, because it is expendable. In my setup API keys are generated by a licensing script, so intend to set |
||
| register: raw_token | ||
|
|
||
| - name: Extract api-user token | ||
| set_fact: | ||
| ansible_httpapi_session_key: | ||
| access_token: "{{ raw_token.stdout | regex_search('New API key: (\\w+)', '\\1') | first }}" | ||
|
|
||
| - name: Create auth.yml in host_vars | ||
| delegate_to: localhost | ||
| copy: | ||
| dest: "{{ inventory_dir }}/host_vars/{{ inventory_hostname }}/auth.yml" | ||
| content: | | ||
| --- | ||
| ansible_httpapi_session_key: | ||
| access_token: "{{ ansible_httpapi_session_key.access_token }}" | ||
| when: netlab_generate_api_token|default(true) | ||
|
|
||
| - name: Enable multi-VDOM mode if a traffic VDOM is defined | ||
| fortinet.fortios.fortios_system_global: | ||
| vdom: "{{ vdom }}" | ||
| system_global: | ||
| management_vdom: "{{ vdom }}" | ||
| vdom_mode: multi-vdom | ||
| hostname: '{{ inventory_hostname.replace("_","-") }}' | ||
| vdom_mode: "{{ 'multi-vdom' if netlab_vdom_is_enabled else 'no-vdom' }}" | ||
| register: vdom_mode_result | ||
| when: netlab_vdom_is_enabled | ||
|
|
||
| - name: Ensure FortiGate is ready after VDOM mode change | ||
| block: | ||
| - name: Wait 60 seconds after VDOM mode change | ||
| ansible.builtin.wait_for: | ||
| host: "{{ ansible_host }}" | ||
| port: 443 | ||
| timeout: 180 | ||
| sleep: 10 # time in seconds between checks | ||
| delay: 60 # Initial delay in seconds before first check | ||
| state: started | ||
| - name: Test FortiGate API readiness after VDOM mode change | ||
| fortinet.fortios.fortios_system_global: | ||
| vdom: "{{ vdom }}" | ||
| system_global: | ||
| hostname: '{{ inventory_hostname.replace("_","-") }}' | ||
| register: hostname_result | ||
| retries: 5 | ||
| delay: 10 # Initial delay and waiting time between retries | ||
| until: hostname_result is not failed and hostname_result.meta.http_status == 200 | ||
| when: >- | ||
| vdom_mode_result.meta is defined and | ||
| (vdom_mode_result.meta.http_status == 200 and vdom_mode_result.meta.revision_changed) | ||
| vars: | ||
| wait: | ||
| delay: "{{ netlab_check_delay | default(5) | int }}" | ||
| retries: "{{ netlab_check_retries | default(20) | int }}" | ||
| timer: "{{ netlab_vdom_timer | default(0) | int }}" | ||
| ansible.builtin.wait_for: | ||
| host: "{{ ansible_host }}" | ||
| port: "{{ ansible_httpapi_port }}" | ||
| timeout: "{{ wait.delay | int * wait.retries | int + wait.timer | int }}" | ||
| sleep: "{{ wait.delay }}" | ||
| delay: "{{ wait.timer }}" | ||
| state: started | ||
| when: | ||
| - wait.timer | int > 0 | ||
| - vdom_mode_result.meta.http_status == 200 | ||
| - vdom_mode_result.meta.revision_changed | ||
|
|
||
| - name: Ensure `{{ vdom }}` VDOM is set as admin | ||
| fortinet.fortios.fortios_system_settings: | ||
| vdom: "{{ vdom }}" | ||
| system_settings: | ||
| vdom_type: admin | ||
| when: netlab_vdom_is_enabled | ||
|
|
||
| - name: Configure `{{ netlab_vdom }}` virtual domain | ||
| fortinet.fortios.fortios_system_vdom: | ||
| vdom: "{{ vdom }}" | ||
| state: present | ||
| system_vdom: | ||
| name: "{{ netlab_vdom }}" | ||
| register: api_result | ||
| retries: "{{ netlab_check_retries | default(20) }}" | ||
| delay: "{{ netlab_check_delay | default(5) }}" | ||
| until: api_result.meta.http_status == 200 | ||
| when: netlab_vdom_is_enabled | ||
|
|
||
| - name: Deploy initial configuration from template | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line fails as there is no api user
netlabwhen I tested:If I manually configure the API user like this, it then works:
And also (I would need to test further without having to do this step manually) it seems that I no longer need to wait 60s when configuring multi-vdom mode.
It's looking very good, we just need to add the api-user. Is this something you have built in as part of your vagrant box?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be part of vagrant-box if it was built with cloud-init image.
https://github.com/a-v-popov/netlab/blob/205a09a6cde536a3adbe2b781ae1bfb4ccaaeea5/netsim/install/libvirt/fortios/openstack/latest/user_data#L28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, my issue is that I haven't used the cloud-init image to create my vagrant boxes.
I'd be keen to add the creation of the api-user
netlabas part of the task