buluma.service

Ansible Role service

Add custom services to your Linux system.

GitHub Version Issues Pull Requests Downloads
github Version Issues PullRequests Ansible Role

Example Playbook

This example comes from molecule/default/converge.yml and is tested with each update.

---
- name: Converge
  hosts: all
  become: true
  gather_facts: true

  vars:
    _service_test_command:
      default: /usr/bin/sleep
      Alpine: /bin/sleep
      Debian: /bin/sleep
      Ubuntu-16: /bin/sleep
      Ubuntu-18: /bin/sleep
    service_test_command: "{{ _service_test_command[ansible_distribution ~ '-' ~ ansible_distribution_major_version] | default(_service_test_command[ansible_os_family] | default(_service_test_command['default'])) }}"  # noqa 204 Just long.

  roles:
    - role: buluma.service
      service_list:
        - name: simple-service
          description: Simple Service
          start_command: "{{ service_test_command }} 3600"
          state: started
          enabled: true
        - name: stopped-service
          description: Simple Service
          start_command: "{{ service_test_command }} 3601"
          state: stopped
          enabled: false
        - name: specific-stop-service
          description: Specific Stop Service
          start_command: "{{ service_test_command }} 1440"
          stop_command: /usr/bin/killall -f "sleep 1440"
        - name: specific-user-group-service
          description: Specific User Group Service
          start_command: "{{ service_test_command }} 28800"
          user_name: root
          group_name: root
        - name: specific-workingdirectory-service
          description: Specific WorkingDirectory Service
          start_command: "{{ service_test_command }} 57600"
          working_directory: /tmp
        - name: specific-pattern-service
          description: Specific Status Pattern Service
          start_command: "{{ service_test_command }} 115200"
          status_pattern: 115200
        - name: variable-service
          description: Service with environment variables
          start_command: "{{ service_test_command }} ${time}"
          environment_variables:
            time: 230400
        - name: pidfile-service
          description: Service with pidfile
          start_command: "{{ service_test_command }} 460800"
          pidfile: /var/run/pidfile-service.pid
        - name: environmentfile-service
          description: Service with environmentfile
          start_command: "{{ service_test_command }} 921600"
          environmentfile: /environmentfile.txt

The machine setup is done beforehand. In CI, this uses molecule/default/prepare.yml:

---
- name: Prepare
  hosts: all
  gather_facts: false
  become: true
  serial: 30%

  roles:
    - role: buluma.bootstrap

  post_tasks:
    - name: place /environmentfile.txt
      ansible.builtin.copy:
        content: "value=variable"
        dest: /environmentfile.txt
        mode: "0644"

For more details, check out the full explanation and example on using these roles.

Role Variables

Default values for variables are found in defaults/main.yml:

---
# defaults file for service

# service_list contains services to add to the system.
# Each item must include:
# - name: The short name of the service, like "tomcat".
# - description: A longer name, like "Tomcat application server".
# - start_command: The command to start the daemon,
#   like "/usr/local/bin/java -jar some.jar"
# Optional items:
# - stop_command: Custom command to stop the service if needed.
# - status_pattern: Program to find when checking status.
# - type: Program starting method; "simple" or "forking".
# - working_directory: Directory to change into before starting the service.
# - environment_variables: List of variables to set, e.g.:
#   environment_variables:
#     variable1: value1
#     variable2: value2
# - after: Start after a mentioned service.
# - restart_mode: How to restart, e.g., "always".
# - restart_seconds: Time to allow for restart.
service_list: []

Requirements

State of Used Roles

The following roles prepare a system. You can use other methods to prepare your system.

Requirement GitHub Version
buluma.bootstrap Ansible Molecule Version

Context

This role is part of many compatible roles. Look at the documentation of these roles for more information.

Here's an overview of related roles:

dependencies

Compatibility

This role has been tested on these container images:

Container Tags
EL 8
Debian all
Fedora all
opensuse all
Ubuntu all
Kali all

You need at least Ansible version 2.12. Tests have been done with:

  • The previous version.
  • The current version.
  • The development version.

If you find problems, please report them on GitHub.

Changelog

Role History.

License

Apache-2.0.

Author Information

Shadow Walker.

Informazioni sul progetto

Add custom services to your Linux system.

Installa
ansible-galaxy install buluma.service
Licenza
apache-2.0
Download
396.8k
Proprietario
DevOps Engineer