fortinet-ansible-dev / ansible-galaxy-fortios-collection

GNU General Public License v3.0
84 stars 48 forks source link

Parameter output_path in fortios_export_config_playbook has no effect #227

Closed oelu closed 8 months ago

oelu commented 1 year ago

Hi all,

the parameter output_path in fortios_export_config_playbook has no effect, or is not respected. The output is always saved in the current folder. Looks like a bug to me.

We tested with the following playbook:

- name: Export playbooks.
  hosts: fortigates
  connection: httpapi
  collections:
    - fortinet.fortios
  vars:
    ansible_httpapi_use_ssl: true
    ansible_httpapi_port: 443
    vdom: "root"
  tasks:
    - name: Export multiple palybooks
      fortinet.fortios.fortios_export_config_playbook:
        vdom: "{{ vdom }}"
        access_token: "{{ fortios_access_token }}"
        selectors:
          - selector: firewall_policy
        output_path: "./config"

Best regards Olivier

jgun-at-redhat commented 1 year ago

Just to add - this is not environment specific. I've recreated the problem across several ansible/AAP/AWX environments.

Looking at the python source, the variable storing the output path parameter is just not used anywhere after being validated.

MaxxLiu22 commented 1 year ago

Hi @oelu @jgun-at-redhat ,

Thank you for raising this issue, I can reproduce this problem and have reported it to the development team. Here is a workaround solution for temporary reference. I will let you know if that is fixed.

- name: Export playbooks.
  hosts: fortigates
  connection: httpapi
  collections:
    - fortinet.fortios
  vars:
    module_name: firewall_policy
    vdom: root
    ansible_httpapi_use_ssl: 'yes'
    ansible_httpapi_validate_certs: 'no'
    ansible_httpapi_port: 443
  tasks:
    - name: Export multiple palybooks
      fortinet.fortios.fortios_export_config_playbook:
        vdom: "root"
        access_token: "3jGnNqbsdfww47btqw1H5rr7d78dcN"
        selectors:
          - selector: "{{ module_name }}"
        output_path : ""
    - name: move file
      shell: mv {{'./' + module_name + '_playbook.yml'}} {{'./config/' + module_name +'_playbook.yml'}}

Thanks, Maxx

jgun-at-redhat commented 1 year ago

Thanks @MaxxLiu22

Quick note for anyone who's running ansible within a container (ie ansible-navigator or other EE) - you will want to use the copy module to get the generated files out to another system.

As well, if running this task across multiple fortigates, the generated file will be overwritten, one time for each host in the batch. workaround for that is to run this in a separate play that has "serial: 1" set.

JieX19 commented 8 months ago

Hi @oelu

We've fixed the issue in the collection. Please try it again; it's now possible to assign any valid directory path. If you encounter any further difficulties or have additional questions, feel free to let us know.