Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppet: relationship between resources on different nodes

I know that we can specify relationship between resources, which determines the deployment order. But is it possible to create relationship between resources on different nodes in Puppet?

For example, I have apache web server in node A and mysql server in node B. I want to start mysql first before starting apache web server. How could I express this in Puppet language?


I have tried the following codes:

node ‘host1’ {
  @@service { ‘mysql’:
    ensure => running,
    tag => ‘host1-mysql’,
  }
}
node ‘host2’ {
  service { ‘apache2’:
    ensure => running,
  }
  Service<<| tag == ‘host1-mysql’ |>> -> Service[‘apache2’]
}

But it didn't work - produced a compile error. Any other solution?

like image 811
Herry Avatar asked Dec 02 '13 09:12

Herry


People also ask

How are resources represented in the Puppet infrastructure?

Every resource is associated with a resource type , which determines the kind of configuration it manages. Puppet has built-in resource types such as file , service , and package . See the resource type reference for a complete list and information about the built-in resource types.

What are the resources and its types in Puppet?

The resource type defines the kind of configuration it manages. This section provides information about the resource types that are built into Puppet. This page provides a reference guide for the core Puppet types: package , file , service , notify , exec , cron , user , and group .

Which of the following defines the node function in Puppet?

A node definition, also known as a node statement, is a block of Puppet code that is included only in matching nodes' catalogs. This allows you to assign specific configurations to specific nodes. Put node definitions in the main manifest, which can be a single site. pp file, or a directory containing many files.

What is the default order in which Puppet resources are applied?

By default, Puppet applies unrelated resources in the order in which they're written in the manifest.


1 Answers

In a distributed "puppet" setup, the apply order isn't guaranteed.

Puppet don't do orchestration across multiple nodes. At best, your changes will get applied multiple times on the machines and finally will converge to the desired state.

Dependencies only work in a same node. You can actually get values of resources exported by others nodes (for eg to configure the firewall of your db to allow the web server to do sql) Or cheat with hiera to know who have the "db" and "app" roles.

For orchestration see tools like mcollective, capistrano, ansible,...

like image 92
mestachs Avatar answered Oct 18 '22 01:10

mestachs