-1

I am trying to write ansible(version 2.6.17) playbook to install ignite(2.7.6) in a linux server as a systemd service.

The playbook run completes without failure.

    PLAY [install ignite in servers]
    ************************************************************************************************

    TASK [Gathering Facts] 
    *************************************************************************************
    ok: [ignitehost1]

    TASK [ignite/install : download and unarchive ignite binaries] 
    **********************************************************************************************
    changed: [ignitehost1]

    TASK [ignite/install : copy config file] 
    *****************************************************************************************
    changed: [ignitehost1]

    TASK [ignite/install : include_tasks]  
    *******************************************************************************
    included: /home/platform/ignite/ansible-ignite/roles/ignite/install/tasks/systemd.yml for 
    ignitehost1

    TASK [ignite/install : install ignite.service] 
    ************************************************************************
    changed: [ignitehost1] => (item={u'd': u'/etc/systemd/system', u'f': u'ignite.service'})

    TASK [ignite/install : systemctl daemon-reload] 
    *****************************************************
    ok: [ignitehost1]

    TASK [ignite/install : start ignite] 
    ******************************************************************************
    changed: [ignitehost1]

    TASK [ignite/install : check if ignite has started] 
    *****************************************************************************
    changed: [ignitehost1]

    PLAY RECAP 
    ***********************************************************
    ignitehost1               : ok=8    changed=5    unreachable=0    failed=0

But my ignite start has failed with known reasons. As you can see in the output of the ignite service status provided below , the main process exited with SUCCESS status which I guess is the reason why my playbook run was successful .Is there any way possible to fail my playbook run if there are any error while starting my service.

sudo systemctl status ignite
? ignite.service
Loaded: loaded (/etc/systemd/system/ignite.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Mon 2020-03-16 16:10:32 IST; 12min ago
Process: 28938 ExecStart=/home/platform/ignite/tmp/apache-ignite-2.7.6-bin/bin/ignite.sh 
(code=exited, 
status=0/SUCCESS)
Main PID: 28938 (code=exited, status=0/SUCCESS)
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1730)
Mar 16 16:10:32 ignitehost1 Ignite[28938]: at 
org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:1158)
Mar 16 16:10:32 ignitehost1  Ignite[28938]: at 
org.apache.ignite.internal.IgnitionEx.startConfigurations(IgnitionEx.java:1076)
Mar 16 16:10:32 ignitehost1  Ignite[28938]: at 
org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:962)
Mar 16 16:10:32 ignitehost1  Ignite[28938]: at 
org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:861)
Mar 16 16:10:32 ignitehost1  Ignite[28938]: at 
org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:731)
Mar 16 16:10:32 ignitehost1  Ignite[28938]: at 
org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:700)
Mar 16 16:10:32 ignitehost1  Ignite[28938]: at org.apache.ignite.Ignition.start(Ignition.java:348)
Mar 16 16:10:32 ignitehost1  Ignite[28938]: ... 1 more
Mar 16 16:10:32 ignitehost1  Ignite[28938]: Failed to start grid: Cannot write to work directory: 
/home/platform/ignite/tmp/apache-ig...in/work
Hint: Some lines were ellipsized, use -l to show in full.

Below is my task file to start ignite.

    ---
    - name: install ignite.service
       become: yes
       become_user: root
       with_items:
        - f: ignite.service
          d: /etc/systemd/system
      template:
        src: '{{ item.f }}.j2'
        dest: '{{ item.d }}/{{ item.f }}'
        mode: '{{ item.m|default("0644") }}'
      register: ignite_service_installed

    - name: systemctl daemon-reload
      become: yes
      become_user: root
      systemd:
        daemon_reload: yes

    - name: start ignite
      become: yes
      become_user: root
      service:
        name: ignite
        enabled: yes
        state: started

Below given is the system unit template file for ignite service

    Description=Apache Ignite Service
    After=network.target

   [Service]
   Type=simple
   WorkingDirectory="{{installation_dir}}/apache-ignite-{{ignite_version}}-bin"
   User=platform
   PrivateDevices=yes
   ProtectSystem=full
   ExecReload=/bin/kill -HUP $MAINPID
   KillMode=mixed
   KillSignal=SIGTERM
   TimeoutStopSec=10
   ExecStart="{{installation_dir}}/apache-ignite-{{ignite_version}}-bin/bin/ignite.sh"
   SyslogIdentifier=Ignite
   Restart=on-failure
   RestartSec=5

  [Install]
  WantedBy=multi-user.target
  Alias=ignite.service
bhavanak
  • 255
  • 1
  • 12

1 Answers1

0

By default, Ansible will check the return codes of commands. This default behaviour can be changed using error handling techniques.

Ansible provides failed_when conditional to allow us to define what “failure” means.

Read https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html

Tiya Jose
  • 1,359
  • 14
  • 24
  • Thank you for the suggestion. I am aware of the ansible error handling mechanism.But I was wondering if it can be managed by systend unit file itself? – bhavanak Mar 17 '20 at 06:58