5.7. LWRPs
In the second example above, the :host attribute will be set to «github.com».
Also, on line 4, we are defining the kind_of validation parameter to tell
the resource which kind of data we should expect (in this case, a string),
whether this attribute is required (yes). Line 5 defines a :key attribute, which
is an optional string with no default. Line 6 defines a :port attribute, a Ruby
Fixnum (i.e. an integer) with a default of 22, which is the default when you
create a known host. Line 7 defines a :known_hosts_file attribute, a string with
a default of /etc/ssh/ssh_known_hosts, which is the default file with known hosts
for ssh client.
For example, the cron_d lightweight resource (found in the cron cookbook)
can be used to manage files located in /etc/cron.d:
Line 1 a c t i o n s : c r e a t e , : d e l e t e
- d e f a u l t _ a c t i o n : c r e a t e
-
- a t t r i b u t e : name , : kind_of => S tri n g , : name_attribute => tru e
5 a t t r i b u t e : cookbook , : kind_of => Stri ng , : d e f a u l t => " cron "
- a t t r i b u t e : minute , : kind_of => [ I n t e g e r , S t r i n g ] , : d e f a u l t => " * "
- a t t r i b u t e : hour , : kind_of => [ Integer , S t r i n g ] , : d e f a u l t => " * "
- a t t r i b u t e : day , : kind_of => [ I nteger , S t r i n g ] , : d e f a u l t => " * "
- a t t r i b u t e : month , : kind_of => [ I nteger , S t r i n g ] , : d e f a u l t => " * "
10 a t t r i b u t e : weekday , : kind_of => [ I nteger , S t r i n g ] , : d e f a u l t => " * "
- a t t r i b u t e : command , : kind_of => Stri ng , : r e q u i r e d => tru e
- a t t r i b u t e : user , : kind_of => S t rin g , : d e f a u l t => " r o o t "
- a t t r i b u t e : mailto , : kind_of => [ S t rin g , N i l C l a s s ]
- a t t r i b u t e : path , : kind_of => [ S trin g , N i l C l a s s ]
15 a t t r i b u t e : home , : kind_of => [ S t rin g , N i l C l a s s ]
- a t t r i b u t e : s h e l l , : kind_of => [ S trin g , N i l C l a s s ]
where
∙ the actions allow a recipe to manage entries in a crontab file (create entry,
delete entry)
∙ : create is the default action
∙ :minute, :hour, :day, :month, and :weekday are the collection of attributes
used to schedule a cron job, assigned a default value of «*»
∙ :command is the command that will be run (and also required)
∙ :user is the user by which the command is run
∙ :mailto, :path, :home, and : shell are optional environment variables that
do not have default value, which each being defined as an array that
supports the String and NilClass Ruby classes
Providers
Now we need to create file know_host.rb in «providers» directory:
Download my-server-cloud/site- . . .
Line 1 # Support whyrun
71