Operations 6 min read

Automating MariaDB Deployment with Ansible Playbooks and Jenkins Pipelines

This guide demonstrates how to write parameterized Ansible playbooks for MariaDB installation and configure Jenkins pipelines to execute those playbooks, securely passing credentials and extra variables to achieve fully automated, repeatable database deployments.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Automating MariaDB Deployment with Ansible Playbooks and Jenkins Pipelines

Ansible enables automated installation and configuration of software on servers, whether they run on virtual machines, physical hosts, or containers. By writing YAML‑based playbooks that list roles and variables, you can version‑control the deployment logic and customize parameters such as MariaDB version, root password, databases, and users.

- hosts: "monserveur.tld"
  vars:
    mariadb_version: '10.1'
    mariadb_root_password:
      - 'monpass'
    mariadb_bind_address:
      - '0.0.0.0'
    mariadb_databases:
      - name: 'mydb'
    mariadb_users:
      - name: 'mydbuser'
        password: 'mydbpass'
        priv: 'mydb.*:ALL,GRANT'
        host: '192.10.%.%'
  roles:
    - role: bertvv.mariadb

Jenkins can run these playbooks directly from a pipeline using the ansiblePlaybook step. By defining a stage such as Deploiement Ansible and specifying the playbook path, Jenkins executes the Ansible run as part of the CI/CD workflow.

stage('Deploiement Ansible') {
    ansiblePlaybook(
      colorized: true,
      become: true,
      playbook: 'ansible-playbooks/mariadb.yml'
    )
}

To make the playbooks reusable, extra variables can be passed at runtime, allowing selection of target hosts and configuration values. This is done with the --extra-vars option.

$ ansible-playbook monplaybook --extra-vars "my var"

Further parameterization is achieved by templating variables inside the playbook, e.g., {{ variable_host }} or {{ variable_dbrootpassword }}, so the same playbook can deploy to different environments.

- hosts: "{{ variable_host | default('monserveur.tld') }}"
  vars:
    mariadb_version: '10.1'
    mariadb_root_password:
      - '{{ variable_dbrootpassword }}'
    mariadb_databases:
      - name: '{{ variable_dbname }}'
    mariadb_users:
      - name: '{{ variable_dbuser }}'
        password: '{{ variable_dbpass }}'
        priv: '{{ variable_dbname }}.*:ALL,GRANT'
        host: '192.10.%.%'
  roles:
    - role: bertvv.mariadb

Jenkins’ Extensible Choice Parameter plugin provides a dropdown of target machines, making it easy for users to select the host when triggering a build. After installing the plugin, the choice list is configured under Manage Jenkins → Configure System → Extensible Choice: Available Choice Providers .

Credentials needed for Ansible to SSH into the target host are stored securely using Jenkins Credentials Manager. By adding a usernamePassword credential and referencing it in the pipeline, the playbook receives the SSH user and password without exposing them in the job configuration.

stage('Deploiement Ansible') {
    withCredentials([usernamePassword(credentialsId: '${SUDOERIDENTIFIER}', passwordVariable: 'SUDOERPASS', usernameVariable: 'SUDOERLOGIN')]) {
        ansiblePlaybook(
          colorized: true,
          become: true,
          playbook: 'ansible-playbooks/mariadb.yml',
          extras: '--extra-vars "variable_host=${HOSTNAME} variable_dbrootpassword=${ROOTPASSWORD} variable_dbname=${DBNAME} variable_dbuser=${DBUSER} variable_dbpass=${DBPASS} ansible_ssh_user=$SUDOERLOGIN ansible_ssh_pass=$SUDOERPASS ansible_sudo_pass=$SUDOERPASS"'
        )
    }
}

When the build is started with “Build with Parameters”, Jenkins runs the Ansible playbook, automatically installing MariaDB, setting the root password, creating the specified database, and provisioning a user with the defined privileges—all without manual password entry. The console output mirrors the standard Ansible command output, confirming successful deployment.

In summary, by combining Ansible playbooks with Jenkins pipelines, you obtain a repeatable, parameter‑driven deployment process for MariaDB that can be executed on any referenced machine through a graphical interface, eliminating the need for manual credential handling.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdautomationJenkinsInfrastructure as CodeAnsibleMariaDB
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.