Git Product home page Git Product logo

ansible-collection-gns3's Introduction

Ansible Module for GNS3

Ansible-Galaxy collections repository for GNS3 Server REST API using gns3fy - see the docs.

Installation

For the module to be used you need to have installed gns3fy

pip install gns3fy

This collections is packaged under ansible-galaxy, so to install it you need mazer from Ansible Projects:

mazer install davidban77.gns3

Features

  • Open/closes projects.
  • Starts/stops all nodes inside a project, or it can be done sequentially with a delay factor.
  • Creates/Updates projects with nodes and links specified as variables in a playbook.
  • Deletes projects safely by stopping nodes, if there are any, then closing the project and finally deleting it.
  • Creates/Deletes/Restores snapshots of projects.
  • Retrieves information about available emulators on the GNS3 server compute, as well as available images, console ports, version, etc..
  • Idempotency is present in all actions. An example could be reflected in a playbook that creates a project with nodes and links, these settings will not be executed again on a rerun (and by settings I mean projects settings, nodes and links)/

Modules

These are the modules provided with this collection:

  • gns3_version: Retrieves GNS3 server version. (TO BE DEPRECATED with the gns3_facts module)
  • gns3_facts: Retrieves the compute(s) information of a GNS3 server
  • gns3_project: Module to interact with GNS3 server projects
    • It opens/closes projects and performs basic turnup/teradown operations on nodes.
    • It creates/updates or deletes projects, with the respective nodes and links specified
  • gns3_project_file: Updates/creates a file on a project directory.
  • gns3_snapshot: Module that interacts with snapshots of a project on GNS3 server.
  • gns3_node: Module to operate a node in a GNS3 server project.
  • gns3_node_file: Updates/creates a file on a node directory.
  • gns3_nodes_inventory: Retrieves GNS3 a project nodes console information.

Examples: using the module

Here are some examples of how to use the module.

Get server version

---
- host: localhost
  # Call the collections to use the respective modules
  collections:
    - davidban77.gns3
  vars:
    gns3_url: http://localhost
  tasks:
    - name: Get the server facts
      gns3_facts:
        url: "{{ gns3_url }}"
        port: 3080
        get_images: all
        get_compute_ports: yes
      register: result

    - debug: var=result

Get nodes_inventory information from a project

---
- host: localhost
  # Call the collections to use the respective modules
  collections:
    - davidban77.gns3
  vars:
    gns3_url: http://localhost
  tasks:
    - name: Get the server version
      gns3_nodes_inventory:
        url: "{{ gns3_url }}"
        project_name: lab_example
      register: result

    - debug: var=result

Manipulate GNS3 projects

---
# Open a GNS3 project
- name: Start lab
  gns3_project:
    url: "{{ gns3_url }}"
    state: opened
    project_name: lab_example

# Stop all nodes inside an open project
- name: Stop nodes
  gns3_project:
    url: "{{ gns3_url }}"
    state: opened
    project_name: lab_example
    nodes_state: stopped
    nodes_strategy: all
    poll_wait_time: 5

# Open a GNS3 project and start nodes one by one with a delay of 10sec between them
- name: Start nodes one by one
  gns3_project:
    url: "{{ gns3_url }}"
    state: opened
    project_name: lab_example
    nodes_state: started
    nodes_strategy: one_by_one
    nodes_delay: 10

# Close a GNS3 project
- name: Stop lab
  gns3_project:
    url: "{{ gns3_url }}"
    state: closed
    project_id: "UUID-SOMETHING-1234567"

Create and delete projects

---
# Create a GNS3 project given nodes and links specifications
- name: Create a project
  gns3_project:
    url: "{{ gns3_url }}"
    state: present
    project_name: new_lab
    nodes_spec:
        - name: alpine-1
          template: alpine
        - name: alpine-2
          template: alpine
    links_spec:
        - ['alpine-1', 'eth0', 'alpine-2', 'eth1']

# Delete a GNS3 project
- name: Delete project
  gns3_project:
    url: "{{ gns3_url }}"
    state: absent
    project_name: new_lab

Examples: using the roles

There are also some convinient roles that you can use to manage your labs. Here is an example playbook:

main.yml

- hosts: localhost
  tasks:
    - import_role:
        name: create_lab
      when: execute == "create"
    - import_role:
        name: delete_lab
      when: execute == "delete"

This way you can call and switch the behaviour of the playbook:

Create the lab

ansible-playbook main.yml -e execute=create

Or delete the lab

ansible-playbook main.yml -e execute=delete

Here is the example variable file which specifies the naming convention used. You can see that the variable names come from the module itself with only gns3_

---
gns3_url: "http://dev_gns3server"
gns3_project_name: test_ansible
gns3_nodes_spec:
    - name: veos-1
      template: "vEOS-4.21.5F"
    - name: veos-2
      template: "vEOS-4.21.5F"
    - name: ios-1
      template: "IOU-15.4"
    - name: ios-2
      template: "IOU-15.4"
gns3_nodes_strategy: one_by_one
gns3_links_spec:
    - ["veos-1", "Ethernet1", "veos-2", "Ethernet1"]
    - ["veos-1", "Ethernet2", "ios-1", "Ethernet1/0"]
    - ["veos-2", "Ethernet2", "ios-2", "Ethernet1/0"]
    - ["ios-1", "Ethernet1/2", "ios-2", "Ethernet1/2"]

More examples

For more examples like create an /etc/network/interfaces file for an alpine docker node to configure its network interfaces, or restore a project to an specific snapshot, you can go to the test/playbooks directory.

ansible-collection-gns3's People

Contributors

davidban77 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ansible-collection-gns3's Issues

Error while installing davidban77.gns3

This happened to me while trying use the first example:
what I did:
pip install gns3fy mazer
this was installed normally

but this one didn't:
mazer install davidban77.gns3
Error loading configuration file /root/.ansible/mazer.yml:
mapping values are not allowed here
in "/root/.ansible/mazer.yml", line 4, column 16
Thanks.

Error when trying to creat nodes and projects

I can get server facts from my GNS3VM through ansible when I run my plays but when I try to run aplay to creat a new project I get a similar error to this. I get this error when I run a play to create a node on an existing project yet it still creates the node. I am lost on how to correct this error.

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: requests.exceptions.HTTPError: 400: JSON schema error with API request '/v2/projects/1b47f47f-54f0-42ec-ac5f-f33ea23bd119/nodes/d8123552-b459-4e0a-aba2-3928c30c6015' and JSON data '{'name': 'Ethernet switch', 'compute_id': 'local', 'pydantic_initialised': True}': Additional properties are not allowed ('pydantic_initialised' was unexpected)
fatal: [GNS]: FAILED! => {"changed": false, "msg": "400: JSON schema error with API request '/v2/projects/1b47f47f-54f0-42ec-ac5f-f33ea23bd119/nodes/d8123552-b459-4e0a-aba2-3928c30c6015' and JSON data '{'name': 'Ethernet switch', 'compute_id': 'local', 'pydantic_initialised': True}': Additional properties are not allowed ('pydantic_initialised' was unexpected)"}

drawings

Hi,

Is there anyway of creating the drawings (svgs) with the playbook?

thanks

David

Project does not fully stop nodes for builtin nodes

By default in GNS3 builtin nodes are always on. Meaning that you cannot start/stop the when they are added to your topology.

The problem is that the ansible module gns3_project marks as changed when trying to shutdown these nodes. The idea would be to skip these nodes from the check so the action ba fully idempotent.

For this I need some kind of builtin attribute set on the Node object in gns3fy

ValueErrors not being correctly handled

When creating links the exceptions raised that are ValueError are not being properly handled, because it finishes the play and no warnings are displayed.

I think it would be good to at least have a warning/fail with these exceptions:

ValueError: node_a: iou-1 not found

Or

ValueError: port_a: Ethernet2 not found

Because the project IS going to get created but the links with these type of errors are not.

"msg": "__init__() got an unexpected keyword argument 'link_style'"

Trying to create/state a topology on GNS3 2.2.29

get the following error

fatal: [localhost]: FAILED! => { "changed": false, "invocation": { "module_args": { "links_spec": null, "nodes_delay": 10, "nodes_spec": null, "nodes_state": "started", "nodes_strategy": "all", "password": null, "poll_wait_time": 5, "port": 80, "project_id": null, "project_name": "test_ansible_55", "state": "opened", "url": "http://192.168.78.129", "user": null } }, "msg": "__init__() got an unexpected keyword argument 'link_style'" }

I have the lastest gns3fy installed as below:

pip install --upgrade gns3fy Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: gns3fy in /home/craig/.local/lib/python3.8/site-packages (0.7.1) Requirement already satisfied: requests<3.0,>=2.22 in /usr/lib/python3/dist-packages (from gns3fy) (2.22.0) Requirement already satisfied: pydantic<2.0,>=1.0 in /home/craig/.local/lib/python3.8/site-packages (from gns3fy) (1.9.0) Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.8/dist-packages (from pydantic<2.0,>=1.0->gns3fy) (4.0.1)

main.yaml playbook as below:

`- hosts: localhost
collections:
- davidban77.gns3
tasks:
- name: Get server version
gns3_facts:
url: "{{ gns3_url }}"
port: 80
get_images: all
get_compute_ports: yes
register: resultado

- debug: var=resultado
- name: Creation/Active section
  when: execute == "create"
  block:
    - import_role:
        name: create_lab

    - name: Get nodes inventory
      gns3_nodes_inventory:
        url: "{{ gns3_url }}"
        port: 80
        project_name: "{{ gns3_project_name }}"
      register: nodes_inventory

    - debug: var=nodes_inventory

- import_role:
    name: delete_lab
  when: execute == "delete"

`

can anyone help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.