Chan
Chan

Reputation: 11

Translating Puppet to Ansible

This is the puppet code managing a service:

class fred::service {

service { 'bob':
        enable => true,
        ensure => 'running',
        require => Package['bob-5.4']
    }
}

My translation in Ansible role

---
- name: check bob
    service:
    name: bob
    enabled: true
    state: running
    package:
    name: bob-5.4
    state: present

My question is:

  1. Is the translation correct?
  2. I am told package comes before service?
  3. Do I require package:

Upvotes: 1

Views: 188

Answers (1)

rpm192
rpm192

Reputation: 2454

The order is incorrect. You should first attempt to install the package. It will automatically skip this (resulting in ok) if the package is already present.

When checking if the service is running, state: running is not valid in Ansible, it should be state: started.

- name: Install package
  apt:
    name: bob-5.4
    state: present

- name: Check if service is running
  service:
    name: bob
    state: started
    enabled: yes

Depending on what you install the package with, this may require a little modification (package or yum instead of apt for example).

Upvotes: 2

Related Questions