Closed kcapecchi closed 5 years ago
@kcapecchi did you pass in a list of routes to ensure exist on the device? Here is an example https://github.com/networktocode/fortimanager-ansible/blob/master/examples/vars/examples/routes.yml
Hello,
thanks for the reply.
No , because I just want to add a new route on my lab fortigate . Is routes.yml needed before using fortmgr_route.yml ?
regards, Kevin
You can implement the playbook as per your requirements. The example I provided allows you to ensure multiple routes exist on the FortiGate. If you do not want to use the routes
variable, then you will need to remove the with_items
and update the module arguments to use your data, whether that is static data put into the playbook, or variables you pass in.
Hello,
Could you please give me an example ?
I have tried this
name: GET FACTS FROM FORTIMANAGER hosts: FortiManager connection: local gather_facts: false
tasks:
ansible-playbook fortmgr_route.yml
PLAY [GET FACTS FROM FORTIMANAGER] *****
TASK [Add Route] *** fatal: [10.5.21.253]: FAILED! => {"changed": false, "msg": "argument provider is of type <type 'str'> and we were unable to convert to dict: dictionary requested, could not parse JSON or key=value"} to retry, use: --limit @/home/tubalcain/depot/fortimanager-ansible/examples/fortmgr_route.retry
PLAY RECAP ***** 10.5.21.253 : ok=0 changed=0 unreachable=0 failed=1
Visibly the type is the problem but I think I have not filled this file with the good values.
thanks
The provider argument expects a dictionary with the device address and credential information. I will assume your inventory looks like this:
[FortiManager]
fmg1 ansible_host=$YOUR_HOST_ADDRESS ansible_user=$YOUR_FMG_USERNAME ansible_pass=$YOUR_FMG_PASSWORD
I will show the provider in the playbook, but normally this would be done somewhere in group_vars.
- name: GET FACTS FROM FORTIMANAGER
hosts: FortiManager
connection: local
gather_facts: false
tasks:
- set_fact:
fortimanager_provider:
hostname: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_pass }}"
- name: Add Route
fortimgr_route:
provider: "{{ fortimanager_provider }}"
fortigate: "labfg"
vdom: "root"
destination: "0.0.0.0/0"
gateway: "10.5.1.1"
intfc: "wan2"
Hello,
unfortunately it is still the same .
Here is my file :
name: GET FACTS FROM FORTIMANAGER hosts: FortiManager connection: local gather_facts: false
tasks:
set_fact: fortimanager_provider: hostname: "10.5.21.253" username: "admin" password: "fortinet"
name: Add Route fortimgr_route: provider: "{{ fortimanager_provider }}" fortigate: "labfg" vdom: "root" destination: "0.0.0.0/0" gateway: "10.5.1.1" intfc: "wan2"
and the result :
root@tubalcain:/home/tubalcain/depot/fortimanager-ansible/examples# ansible-playbook fortmgr_route.yml
PLAY [GET FACTS FROM FORTIMANAGER] **
TASK [set_fact] ***** ok: [10.5.21.253] ok: [ansible_host=10.5.21.253] ok: [ansible_user=admin] ok: [ansible_pass=fortinet]
TASK [Add Route] **** fatal: [10.5.21.253]: FAILED! => {"changed": false, "msg": "host is required"} fatal: [ansible_user=admin]: FAILED! => {"changed": false, "msg": "host is required"} fatal: [ansible_host=10.5.21.253]: FAILED! => {"changed": false, "msg": "host is required"} fatal: [ansible_pass=fortinet]: FAILED! => {"changed": false, "msg": "host is required"} to retry, use: --limit @/home/tubalcain/depot/fortimanager-ansible/examples/fortmgr_route.retry
PLAY RECAP **
10.5.21.253 : ok=1 changed=0 unreachable=0 failed=1
ansible_host=10.5.21.253 : ok=1 changed=0 unreachable=0 failed=1
ansible_pass=fortinet : ok=1 changed=0 unreachable=0 failed=1
ansible_user=admin : ok=1 changed=0 unreachable=0 failed=1
Hello,
We found the solution , the correct syntax was :
name: GET FACTS FROM FORTIMANAGER hosts: FortiManager connection: local gather_facts: false
tasks:
set_fact: fortimanager_provider: host: "{{ ansible_host }}" username: "{{ ansible_user }}" password: "{{ ansible_pass }}" adom: "root"
name: Add Route fortimgr_route: provider: "{{ fortimanager_provider }}" fortigate: "labfg" vdom: "root" destination: "0.0.0.0/0" gateway: "10.5.1.1" intfc: "wan2" ~
thx
Glad you got it working
hello,
Using the fortmgr_route.yml , I have the following error when executing it :+1:
ansible-playbook fortmgr_route.yml
root@tubalcain:/home/tubalcain/depot/fortimanager-ansible/examples# ansible-playbook fortmgr_route.yml
PLAY [GET FACTS FROM FORTIMANAGER] *****
TASK [Add Route] *** fatal: [10.5.21.253]: FAILED! => {"msg": "'routes' is undefined"} to retry, use: --limit @/home/tubalcain/depot/fortimanager-ansible/examples/fortmgr_route.retry
PLAY RECAP ***** 10.5.21.253 : ok=0 changed=0 unreachable=0 failed=1
thanks