Giter Club home page Giter Club logo

ansible-role-systemd-service's Introduction

Build Status Ansible Galaxy

systemd-service - Ansible role

Register services to systemd.

Japanese ver http://qiita.com/tumf/items/9d5ac6853685ba53214d

Install

$ ansible-galaxy install tumf.systemd-service

Role Variables

name type default description
systemd_service_default_dir String "/etc/default" envs file path
systemd_service_systemd_dir String "/etc/systemd/system" systemd path
systemd_service_name * String service name
systemd_service_envs String,List,MapList [] envs (/etc/default/:name)

Note systemd_service_root_dir is obsolate.

[Unit]

name type default description
systemd_service_Unit_Description String [Unit]Description
systemd_service_Unit_Documentation String [Unit]Documentation
systemd_service_Unit_Requires String,List [Unit]Requires
systemd_service_Unit_Wants String,List [Unit]Wants
systemd_service_Unit_ConditionPathExists String [Unit]ConditionPathExists
systemd_service_Unit_After String,List [Unit]After
systemd_service_Unit_Before String,List [Unit]Before

[Service]

name type default description
systemd_service_Service_Type String "simple" [Service]Type
systemd_service_Service_ExecStartPre String,List [Service]ExecStartPre
systemd_service_Service_ExecStart * String [Service]ExecStart
systemd_service_Service_ExecStartPost String,List [Service]ExecStartPost
systemd_service_Service_Restart String "no" [Service]Restart "no" or "always" or "on-success" or "on-failure"
systemd_service_Service_RestartSec Integer [Service]RestartSec
systemd_service_Service_ExecReload String [Service]ExecReload
systemd_service_Service_ExecStop String [Service]ExecStop
systemd_service_Service_KillMode String [Service]KillMode
systemd_service_Service_ExecStopPost String,List [Service]ExecStopPost
systemd_service_Service_PIDFile String [Service]PIDFile
systemd_service_Service_BusName String [Service]BusName
systemd_service_Service_PrivateTmp String [Service]PrivateTmp
systemd_service_Service_LimitNOFILE String [Service]LimitNOFILE
systemd_service_Service_User String [Service]User
systemd_service_Service_Group String [Service]Group
systemd_service_Service_WorkingDirectory String [Service]WorkingDirectory

[Install]

name type default description
systemd_service_Install_WantedBy String [Install]WantedBy "multi-user.target" [Install]WantedBy
systemd_service_Install_RequiredBy String [Install]RequiredBy
systemd_service_Install_Also String [Install]Also
systemd_service_Install_Alias String [Install]Alias
  • Required

Example Playbook

- hosts: servers
  roles:
    - role: systemd-service
      systemd_service_name: "swarm-manager"
      systemd_service_envs:
          - "DOCKER_HOST=tcp://127.0.0.1:2375"
      systemd_service_Unit_Description: Docker Swarm Manager
      systemd_service_Unit_Requires: docker.service
      systemd_service_Unit_After: docker.service
      systemd_service_Service_ExecStartPre:
          - -/usr/bin/docker stop swarm-manager
          - -/usr/bin/docker rm swarm-manager
          - /usr/bin/docker pull swarm
      systemd_service_Service_ExecStart: /usr/bin/docker run -p 2377:2375 --name swarm-manager swarm manage

License

MIT

Author Information

@tumf

ansible-role-systemd-service's People

Contributors

ch-tactica avatar gaell avatar h3po avatar johngoldfinger avatar pfink avatar talset avatar tkhduracell avatar tumf avatar vkill 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ansible-role-systemd-service's Issues

Support for multiple services via list

Trying to utilize this role to support multiple systemd unit files is frustrating with ansible's current role implementation in playbooks. It would be great if this role could support piping in a list of dictionary values defining multiple roles.

I've tried to work around this limitation with include_role and the vars keyword and am hitting limitations in ansible.

systemd_service_name not defined

I don't believe this is an issue with this role, but I wanted to run this past you just in case you've seen it before or I'm doing something stupid.

I'm attempting to call this role from one of my own. They're being run by the Packer Ansible provisioner. It was working a couple of weeks ago. At the time, I had the following vars set in defaults/main.yml:

      systemd_service_name: 'ansible-bootstrap'
      systemd_service_Unit_Description: 'Run ansible-pull at boot to do post-launch configuration'
      systemd_service_Service_ExecStartPre: '-/usr/bin/ansible-galaxy install -f -r /opt/bootstrap/playbook/requirements.yml'
      systemd_service_Service_ExecStart: |
        /usr/bin/ansible-pull \
        -f -s 15 \
        -c local -i "localhost," \
        -e "@/opt/bootstrap/playbook_vars.yml" \
        -U {{ bootstrap_playbook_repo }} \
        -d /opt/bootstrap/playbook \
        --key-file="{{ bootstrap_playbook_keyfile | default('') }}"

When I tried rebuilding the image today, it started failing on the systemd_service handler with the following error:

amazon-ebs: fatal: [127.0.0.1]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'systemd_service_name' is undefined\n\nThe error appears to have been in '/tmp/packer-provisioner-ansible-local/59972dbd-d8b5-6a33-a238-a1e2082ec2cf/roles/tumf.systemd-service/handlers/main.yml': line 3, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# handlers file for roles/systemd/service\n- name: reload systemd\n  ^ here\n"}

I moved the vars into vars/main.yml but that resulted in the same error. I finally moved them into the include_role call's vars option as well and now Ansible fails a little earlier. Instead of failing on the handler, it fails on the template call:

    amazon-ebs: fatal: [127.0.0.1]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'systemd_service_name' is undefined\n\nThe error appears to have been in '/tmp/packer-provisioner-ansible-local/599730e4-50fc-d6d7-9c97-e1e8bb12fcce/roles/tumf.systemd-service/tasks/main.yml': line 8, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- template: src=\"default.j2\" dest=\"{{ ansible_unit_test_prefix_dir }}/{{ systemd_service_default_dir }}/{{ systemd_service_name }}\"\n  ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.  Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}

Again, I don't believe this is an issue with your role, but I'm not sure what the issue might be at this point. Any help you could provide would be appreciated. Thanks!

Add include_role example

I'm trying to use this from another role, but just get errors. A correct example in the readme would be helpful!

- name: setup nsd_exporter service
  include_role:
    name: tumf.systemd-service
  vars:
    systemd_service_name: "nsd_exporter"
    systemd_service_Service_ExecStart: "/opt/bin/nsd_exporter"

gives me this error:

ERROR! Invalid options for include_role: systemd_service_Service_ExecStart,systemd_service_name

I realize this isn't a problem with the role but really me not understanding the ansible documentation, but I thought still an example in the README here would be useful as I am guessing this might be a common use case. :-)

Print errors in case of reload failure

Sometimes we provide bad parameters and systemd reload will fail, with a generic message such as

"Failed to restart app-opstest.service: Unit app-opstest.service is not loaded properly: Invalid argument.\nSee system logs and 'systemctl status app-opstest.service' for details."

Would be nice if this was detected in the role and automatically have the errors displayed

systemd_service_Service_ExecReload is missing

I tried to configure reloading, but the documented var is incorrect.

The docs say systemd_service_Service_ExecReload, which is consistent with the rest

But the code says systemd_service_ExecReload

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.