Skip to content

nautobot_server

Collection Note

This module is part of the networktocode.nautobot collection. To install the collection, use:

ansible-galaxy collection install networktocode.nautobot
You need further requirements to be able to use this module, see the Requirements section for details.

Synopsis

  • Manages Nautobot Server using the C(nautobot-server) application frontend to C(django-admin). With the C(virtualenv) parameter
  • all management commands will be executed by the given C(virtualenv) installation.

Requirements

The following Python packages are needed on the host that executes this module:

Parameters

Parameter Data Type Environment Variable Comments
args dict A dictionary of the optional arguments and their values used together with the command.
This translates {"name_arg": "value_arg"} to "--name_arg value_arg".
command
required
str The name of the Nautobot management command to run. Some command fully implemented are: C(createsuperuser),
C(migrate), C(makemigrations), C(post_upgrade) and C(collectstatic).
Other commands can be entered, but will fail if they're unknown to Nautobot or use positional arguments.
The module will perform some basic parameter validation, when applicable, to the commands.
db_password str Database password used in Nautobot.
db_username str Database username used in Nautobot.
flags list A list of flags to append to the command that is passed to C(nautobot-server), so that ["flag1", "flag2"] is translated to "--flag1 --flag2".
positional_args list A list of additional arguments to append to the end of the command that is passed to C(nautobot-server). These are appended to the end of the command, so that ["arg1", "arg2"] is translated to "arg1 arg2".
project_path path The path to the root of the Nautobot application where B(nautobot-server) lives.
pythonpath path A directory to add to the Python path. Typically used to include the settings module if it is located external to the application directory.
settings path The Python path to the application's settings module, such as 'myapp.settings'.
virtualenv path An optional path to a I(virtualenv) installation to use while running the nautobot-server application.

Notes

Note

  • Inspired from Django_manage (U(https://github.com/ansible-collections/community.general/blob/main/plugins/modules/web_infrastructure/django_manage.py)).
  • To be able to use the C(collectstatic) command, you must have enabled staticfiles in your nautbot_config.py.
  • Your C(nautobot-server) application must be executable (rwxr-xr-x), and must have a valid shebang.

Examples

  - name: Createsuperuser
    networktocode.nautobot.nautobot_server:
      command: "createsuperuser"
      args:
        email: "admin93@example.com"
        username: "superadmin7"
      db_password: "{{ db_password }}"
  - name: Collectstatic
    networktocode.nautobot.nautobot_server:
      command: "collectstatic"
      db_password: "{{ db_password }}"
  - name: Post Upgrade
    networktocode.nautobot.nautobot_server:
      command: "post_upgrade"
  - name: Make Migrations for Plugin
    networktocode.nautobot.nautobot_server:
      command: "makemigrations"
      positional_args: ["my_plugin_name"]
      db_password: "{{ db_password }}"
  - name: Migrate Plugin
    networktocode.nautobot.nautobot_server:
      command: "migrate"
      args:
        verbosity: 3
      flags: ["merge"]
      positional_args: ["my_plugin_name"]
      db_username: "{{ db_username }}"
      db_password: "{{ db_password }}"

Return Values

Key Data Type Description Returned
changed bool Boolean that is true if the command changed the state. always
cmd str Full command executed in the Server. always
out str Raw output from the command execution. always
project_path str The path to the root of the Nautobot application where B(nautobot-server) lives. always

Authors

  • Network To Code (@networktocode)