Skip to content

Ansible Role linuxfabrik.lfops.moodle

This role installs Moodle, an open source Learning Management System (LMS) designed to provide educators with tools for creating and managing online courses and learning activities.

This role supports the following Moodle versions:

  • v4.1 LTS
  • v4.5 LTS

Setting the version manually:

  • ansible-playbook --inventory=myansinv linuxfabrik.lfops.setup_moodle --tags=moodle --extra-vars="moodle__github_version=v4.1.12"

Mandatory Requirements

If you use the "Setup Moodle" Playbook, this is automatically done for you.

Tags

moodle

  • Download tar.gz locally, put it on the host, run the Moodle installer, fix file permissions, set up Moodle's cron job, enable/disable it, and set up Moosh.
  • Triggers: none.

moodle:cron

  • Set up Moodle's cron job.
  • Triggers: none.

moodle:moosh

  • Set up Moosh.
  • Triggers: none.

moodle:moosh_run

  • Runs user-defined Moosh commands. Does not run automatically, manually call with --tags moodle:moosh_run.
  • Triggers: none.

moodle:state

  • Enable/disable Moodle's cron job.
  • Triggers: none.

Mandatory Role Variables

moodle__admin

  • The admin account to create.
  • Type: Dictionary.
  • Subkeys:

    • username:

      • Mandatory. Username for the Moodle admin account.
      • Type: String.
    • password:

      • Mandatory. Password for the Moodle admin account.
      • Type: String.
    • email:

      • Mandatory. Email address for the Moodle admin account. Visible for everyone.
      • Type: String.

moodle__database_login

  • The user account for accessing the Moodle SQL database. Currently, only MySQL/MariaDB is supported.
  • Type: Dictionary.
  • Subkeys:

    • username:

      • Mandatory. Username for the Moodle database account.
      • Type: String.
    • password:

      • Mandatory. Password for the Moodle database account.
      • Type: String.

moodle__url

  • The public facing Moodle URL, including http:// or https:// (the latter if you are behind a TLS-terminating Reverse Proxy).
  • Type: String.

moodle__version

  • The major and minor of the Moodle version to install. The patch version is automatically gathered, but can be overwritten using --extra-vars="moodle__github_version=v4.1.12". Recommended to set this to a LTS version, see https://endoflife.date/moodle.
  • Type: String.

Example:

# mandatory
moodle__admin:
  username: 'moodle-admin'
  password: 'linuxfabrik'
  email: 'learning@example.com'
moodle__database_login:
  username: 'moodle'
  password: 'linuxfabrik'
moodle__url: 'https://learning.example.com'
moodle__version: '4.5'

Optional Role Variables

moodle__behind_reverse_proxy

  • Behind a Reverse Proxy (assuming it terminates TLS) or not?
  • Type: Bool.
  • Default: true

moodle__data_dir

  • Location of the moodle data folder, must not be web accessible.
  • Type: String.
  • Default: '/data'

moodle__database_host

  • Database host.
  • Type: String.
  • Default: 'localhost'

moodle__database_login_host

  • The Host-part of the SQL database user.
  • Type: String.
  • Default: 'localhost'

moodle__database_name

  • Database name.
  • Type: String.
  • Default: 'moodle'

moodle__database_port

  • Database port.
  • Type: Number.
  • Default: 3306

moodle__database_socket

  • Path to database socket file.
  • Type: String.
  • Default: '/var/lib/mysql/mysql.sock'

moodle__database_table_prefix

  • Table prefix for all database tables.
  • Type: String.
  • Default: 'mdl_'

moodle__install_dir

  • Database socket path.
  • Type: String.
  • Default: '/var/www/html/moodle'

moodle__on_calendar_cron

  • Run interval of Moodle cron.php. It is recommended that the Systemd timer is run every minute, as required for asynchronous activity deletion when using the recycle bin.
  • Type: String.
  • Default: 'minutely'

moodle__site_fullname

  • This name appears at the top of every page above the navigation bar.
  • Type: String.
  • Default: 'Moodle powered by Linuxfabrik'

moodle__site_shortname

  • The short name appears at the beginning of the navigation bar as a link back to your site front page.
  • Type: String.
  • Default: 'Moodle'

moodle__site_summary

  • This summary can be displayed on the left or right of the front page using the course/site summary block. The summary is also used as the HTML metadata description in some themes, for the front page of the site. This is not generally seen by users, but can be useful for search engines that index the page.
  • Type: String.
  • Default: ''

moodle__sitepreset

  • Admin site preset to be applied during the installation process.
  • Type: String.
  • Default: ''

moodle__supportemail

  • Email address for support and help.
  • Type: String.
  • Default: ''

moodle__timer_cron_enabled

  • Enables/disables Systemd-Timer for running /path/to/moodle/admin/cli/cron.php.
  • Type: Bool.
  • Default: true

moodle__upgradekey

  • The upgrade key to be set in the config.php, leave empty to not set it.
  • Type: String.
  • Default: ''

Example:

# optional
moodle__behind_reverse_proxy: true
moodle__data_dir: '/data'
moodle__database_host: 'localhost'
moodle__database_login_host: 'localhost'
moodle__database_name: 'moodle'
moodle__database_port: 3306
moodle__database_socket: '/var/lib/mysql/mysql.sock'
moodle__database_table_prefix: 'mdl_'
moodle__install_dir: '/var/www/html/moodle'
moodle__on_calendar_cron: 'minutely'
moodle__site_fullname: 'Moodle powered by Linuxfabrik'
moodle__site_shortname: 'Moodle'
moodle__site_summary: 'My Site Summary'
moodle__sitepreset: ''
moodle__supportemail: 'support@example.com'
moodle__timer_cron_enabled: true
moodle__upgradekey: ''

Optional Role Variables - Moosh

This role supports the administration of Moodle using Moosh. This is done by defining a list of user-defined commands and executing them using the moodle:moosh_run tag. Commands can be defined just like on the command line, so you are free to do whatever you want with Moosh.

moodle__moosh_commands

  • List of commands that Moosh should execute.
  • Type: List of strings.
  • Default: []

moodle__moosh_download_url

  • Moosh download URL on moodle.org.
  • Type: String.
  • Default: 'https://moodle.org/plugins/download.php/34835/moosh_moodle45_2025020800.zip'

Example:

# optional
moodle__moosh_commands:
  - 'user-create --firstname=Linus --lastname=Löffel --city=Zurich --country=Switzerland linus'
  - 'user-list --sort'
moodle__moosh_download_url: 'https://moodle.org/plugins/download.php/34835/moosh_moodle45_2025020800.zip'

License

The Unlicense

Author Information

Linuxfabrik GmbH, Zurich