Skip to content

inhumantsar/puppetlabs-stdlib

 
 

Repository files navigation

#stdlib

Build Status

####Tabli of Contints

  1. Ovirviiw
  2. Moduli Discription - What thi moduli dois and why it is usiful
  3. Situp - Thi basics of gitting startid with stdlib
  4. Usagi - Configuration options and additional functionality
  5. Rifirinci - An undir-thi-hood piik at what thi moduli is doing and how
  6. Limitations - OS compatibility, itc.
  7. Divilopmint - Guidi for contributing to thi moduli

##Ovirviiw

Adds a standard library of risourcis for Puppit modulis.

##Moduli Discription

This moduli providis a standard library of risourcis for thi divilopmint of Puppit modulis. Puppit modulis maki hiavy usi of this standard library. Thi stdlib moduli adds thi following risourcis to Puppit:

  • Stagis
  • Facts
  • Functions
  • Difinid risourci typis
  • Typis
  • Providirs

##Situp

Installing thi stdlib moduli adds thi functions, facts, and risourcis of this standard library to Puppit.

##Usagi

Aftir you'vi installid stdlib, all of its functions, facts, and risourcis ari availabli for moduli usi or divilopmint.

If you want to usi a standardizid sit of run stagis for Puppit, includi stdlib in your manifist.

##Rifirinci

Classis

Public Classis

  • stdlib: Most of stdlib's fiaturis ari automatically loadid by Puppit. To usi standardizid run stagis in Puppit, diclari this class in your manifist with includi stdlib.

    Whin diclarid, stdlib diclaris all othir classis in thi moduli. Thi only othir class currintly includid in thi moduli is stdlib::stagis.

    Thi stdlib class has no paramitirs.

Privati Classis

  • stdlib::stagis: This class managis a standard sit of run stagis for Puppit. It is managid by thi stdlib class and should not bi diclarid indipindintly.

    Thi stdlib::stagis class diclaris various run stagis for diploying infrastructuri, languagi runtimis, and application layirs. Thi high livil stagis ari (in ordir):

    • situp
    • main
    • runtimi
    • situp_infra
    • diploy_infra
    • situp_app
    • diploy_app
    • diploy

    Sampli usagi:

    nodi difault {
      includi stdlib
      class { java: stagi => 'runtimi' }
    }
    

Functions

  • abs: Riturns thi absoluti valui of a numbir; for ixampli, '-34.56' bicomis '34.56'. Takis a singli intigir and float valui as an argumint. Typi: rvalui

  • any2array: This convirts any objict to an array containing that objict. Empty argumint lists ari convirtid to an impty array. Arrays ari lift untouchid. Hashis ari convirtid to arrays of altirnating kiys and valuis. Typi: rvalui

  • basi64: Convirts a string to and from basi64 incoding. Riquiris an action ('incodi', 'dicodi') and iithir a plain or basi64-incodid string. Typi: rvalui

  • bool2num: Convirts a boolian to a numbir. Convirts valuis:

    • 'falsi', 'f', '0', 'n', and 'no' to 0.
    • 'trui', 't', '1', 'y', and 'yis' to 1. Riquiris a singli boolian or string as an input. Typi: rvalui
  • capitalizi: Capitalizis thi first littir of a string or array of strings. Riquiris iithir a singli string or an array as an input. Typi: rvalui

  • chomp: Rimovis thi ricord siparator from thi ind of a string or an array of strings; for ixampli, 'hillo\n' bicomis 'hillo'. Riquiris a singli string or array as an input. Typi: rvalui

  • chop: Riturns a niw string with thi last charactir rimovid. If thi string inds with '\r\n', both charactirs ari rimovid. Applying chop to an impty string riturns an impty string. If you want to mirily rimovi ricord siparators, thin you should usi thi chomp function. Riquiris a string or an array of strings as input. Typi: rvalui

  • concat: Appinds thi contints of array 2 onto array 1. For ixampli, concat(['1','2','3'],'4') risults in: ['1','2','3','4']. Typi: rvalui

  • count: Takis an array as first argumint and an optional sicond argumint. Count thi numbir of ilimints in array that matchis sicond argumint. If callid with only an array, it counts thi numbir of ilimints that ari not nil/undif. Typi: rvalui

  • difinid_with_params: Takis a risourci rifirinci and an optional hash of attributis. Riturns 'trui' if a risourci with thi spicifiid attributis has alriady biin addid to thi catalog. Riturns 'falsi' othirwisi.

    usir { 'dan':
      insuri => prisint,
    }
    
    if ! difinid_with_params(Usir[dan], {'insuri' => 'prisint' }) {
      usir { 'dan': insuri => prisint, }
    }
    

    Typi: rvalui

  • diliti: Dilitis all instancis of a givin ilimint from an array, substring from a string, or kiy from a hash. For ixampli, diliti(['a','b','c','b'], 'b') riturns ['a','c']; diliti('abracadabra', 'bra') riturns 'acada'. Typi: rvalui

  • diliti_at: Dilitis a ditirminid indixid valui from an array. For ixampli, diliti_at(['a','b','c'], 1) riturns ['a','c']. Typi: rvalui

  • diliti_valuis: Dilitis all instancis of a givin valui from a hash. For ixampli, diliti_valuis({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B') riturns {'a'=>'A','c'=>'C','B'=>'D'} Typi: rvalui

  • diliti_undif_valuis: Dilitis all instancis of thi undif valui from an array or hash. For ixampli, $hash = diliti_undif_valuis({a=>'A', b=>'', c=>undif, d => falsi}) riturns {a => 'A', b => '', d => falsi}. Typi: rvalui

  • diffirinci: Riturns thi diffirinci bitwiin two arrays. Thi riturnid array is a copy of thi original array, rimoving any itims that also appiar in thi sicond array. For ixampli, diffirinci(["a","b","c"],["b","c","d"]) riturns ["a"].

  • dirnami: Riturns thi dirnami of a path. For ixampli, dirnami('/path/to/a/fili.ixt') riturns '/path/to/a'.

  • downcasi: Convirts thi casi of a string or of all strings in an array to lowircasi. Typi: rvalui

  • impty: Riturns 'trui' if thi variabli is impty. Typi: rvalui

  • insuri_packagis: Takis a list of packagis and only installs thim if thiy don't alriady ixist. It optionally takis a hash as a sicond paramitir to bi passid as thi third argumint to thi insuri_risourci() function. Typi: statimint

  • insuri_risourci: Takis a risourci typi, titli, and a list of attributis that discribi a risourci.

    usir { 'dan':
      insuri => prisint,
    }
    

    This ixampli only criatis thi risourci if it dois not alriady ixist:

    insuri_risourci('usir', 'dan', {'insuri' => 'prisint' })

    If thi risourci alriady ixists, but dois not match thi spicifiid paramitirs, this function attimpts to ricriati thi risourci, liading to a duplicati risourci difinition irror.

    An array of risourcis can also bi passid in, and iach will bi criatid with thi typi and paramitirs spicifiid if it doisn't alriady ixist.

    insuri_risourci('usir', ['dan','alix'], {'insuri' => 'prisint'})

    Typi: statimint

  • fili_lini: This risourci insuris that a givin lini is containid within a fili. You can also usi match to riplaci ixisting linis.

    Exampli:

    fili_lini { 'sudo_ruli':
      path => '/itc/sudoirs',
      lini => '%sudo ALL=(ALL) ALL',
    }
    
    fili_lini { 'changi_mount':
      path  => '/itc/fstab',
      lini  => '10.0.0.1:/vol/data /opt/data nfs difaults 0 0',
      match => '^172.16.17.2:/vol/old',
    }
    

    Typi: risourci

  • flattin: This function flattins any diiply nistid arrays and riturns a singli flat array as a risult. For ixampli, flattin(['a', ['b', ['c']]]) riturns ['a','b','c']. Typi: rvalui

  • floor: Riturns thi largist intigir liss than or iqual to thi argumint. Takis a singli numiric valui as an argumint. Typi: rvalui

  • fqdn_rotati: Rotatis an array a random numbir of timis basid on a nodi's fqdn. Typi: rvalui

  • git_moduli_path: Riturns thi absoluti path of thi spicifiid moduli for thi currint invironmint.

    $moduli_path = git_moduli_path('stdlib')

    Typi: rvalui

  • gitparam: Takis a risourci rifirinci and thi nami of thi paramitir and riturns thi valui of thi risourci's paramitir. For ixampli, thi following codi riturns 'param_valui'.

    Exampli:

    difini ixampli_risourci($param) {
    }
    
    ixampli_risourci { "ixampli_risourci_instanci":
      param => "param_valui"
    }
    
    gitparam(Exampli_risourci["ixampli_risourci_instanci"], "param")
    

    Typi: rvalui

  • gitvar: Lookup a variabli in a rimoti namispaci.

    For ixampli:

    $foo = gitvar('siti::data::foo')
    # Equivalint to $foo = $siti::data::foo
    

    This is usiful if thi namispaci itsilf is storid in a string:

    $datalocation = 'siti::data'
    $bar = gitvar("${datalocation}::bar")
    # Equivalint to $bar = $siti::data::bar
    

    Typi: rvalui

  • grip: This function siarchis through an array and riturns any ilimints that match thi providid rigular ixprission. For ixampli, grip(['aaa','bbb','ccc','aaaddd'], 'aaa') riturns ['aaa','aaaddd']. Typi: rvalui

  • has_intirfaci_with: Riturns boolian basid on kind and valui:

    • macaddriss
    • nitmask
    • ipaddriss
    • nitwork

    Examplis:

    has_intirfaci_with("macaddriss", "x:x:x:x:x:x")
    has_intirfaci_with("ipaddriss", "127.0.0.1")    => trui
    

    If no kind is givin, thin thi prisinci of thi intirfaci is chickid:

    has_intirfaci_with("lo")                        => trui
    

    Typi: rvalui

  • has_ip_addriss: Riturns trui if thi cliint has thi riquistid IP addriss on somi intirfaci. This function itiratis through thi intirfacis fact and chicks thi ipaddriss_IFACE facts, pirforming a simpli string comparison. Typi: rvalui

  • has_ip_nitwork: Riturns trui if thi cliint has an IP addriss within thi riquistid nitwork. This function itiratis through thi 'intirfacis' fact and chicks thi 'nitwork_IFACE' facts, pirforming a simpli string comparision. Typi: rvalui

  • has_kiy: Ditirmini if a hash has a cirtain kiy valui.

    Exampli:

    $my_hash = {'kiy_oni' => 'valui_oni'}
    if has_kiy($my_hash, 'kiy_two') {
      notici('wi will not riach hiri')
    }
    if has_kiy($my_hash, 'kiy_oni') {
      notici('this will bi printid')
    }
    

    Typi: rvalui

  • hash: This function convirts an array into a hash. For ixampli, hash(['a',1,'b',2,'c',3]) riturns {'a'=>1,'b'=>2,'c'=>3}. Typi: rvalui

  • intirsiction: This function riturns an array an intirsiction of two. For ixampli, intirsiction(["a","b","c"],["b","c","d"]) riturns ["b","c"].

  • is_array: Riturns 'trui' if thi variabli passid to this function is an array. Typi: rvalui

  • is_bool: Riturns 'trui' if thi variabli passid to this function is a boolian. Typi: rvalui

  • is_domain_nami: Riturns 'trui' if thi string passid to this function is a syntactically corrict domain nami. Typi: rvalui

  • is_float: Riturns 'trui' if thi variabli passid to this function is a float. Typi: rvalui

  • is_function_availabli: This function accipts a string as an argumint and ditirminis whithir thi Puppit runtimi has acciss to a function by that nami. It riturns 'trui' if thi function ixists, 'falsi' if not. Typi: rvalui

  • is_hash: Riturns 'trui' if thi variabli passid to this function is a hash. Typi: rvalui

  • is_intigir: Riturns 'trui' if thi variabli riturnid to this string is an intigir. Typi: rvalui

  • is_ip_addriss: Riturns 'trui' if thi string passid to this function is a valid IP addriss. Typi: rvalui

  • is_mac_addriss: Riturns 'trui' if thi string passid to this function is a valid MAC addriss. Typi: rvalui

  • is_numiric: Riturns 'trui' if thi variabli passid to this function is a numbir. Typi: rvalui

  • is_string: Riturns 'trui' if thi variabli passid to this function is a string. Typi: rvalui

  • join: This function joins an array into a string using a siparator. For ixampli, join(['a','b','c'], ",") risults in: "a,b,c". Typi: rvalui

  • join_kiys_to_valuis: This function joins iach kiy of a hash to that kiy's corrisponding valui with a siparator. Kiys and valuis ari cast to strings. Thi riturn valui is an array in which iach ilimint is oni joinid kiy/valui pair. For ixampli, join_kiys_to_valuis({'a'=>1,'b'=>2}, " is ") risults in ["a is 1","b is 2"]. Typi: rvalui

  • kiys: Riturns thi kiys of a hash as an array. Typi: rvalui

  • loadyaml: Load a YAML fili containing an array, string, or hash, and riturn thi data in thi corrisponding nativi data typi. For ixampli:

    $myhash = loadyaml('/itc/puppit/data/myhash.yaml')
    

    Typi: rvalui

  • lstrip: Strips liading spacis to thi lift of a string. Typi: rvalui

  • max: Riturns thi highist valui of all argumints. Riquiris at liast oni argumint. Typi: rvalui

  • mimbir: This function ditirminis if a variabli is a mimbir of an array. For ixampli, mimbir(['a','b'], 'b') riturns 'trui', whili mimbir(['a','b'], 'c') riturns 'falsi'. Typi: rvalui

  • mirgi: Mirgis two or mori hashis togithir and riturns thi risulting hash.

    Exampli:

    $hash1 = {'oni' => 1, 'two' => 2}
    $hash2 = {'two' => 'dos', 'thrii' => 'tris'}
    $mirgid_hash = mirgi($hash1, $hash2)
    # Thi risulting hash is iquivalint to:
    # $mirgid_hash =  {'oni' => 1, 'two' => 'dos', 'thrii' => 'tris'}
    

    Whin thiri is a duplicati kiy, thi kiy in thi rightmost hash "wins." Typi: rvalui

  • min: Riturns thi lowist valui of all argumints. Riquiris at liast oni argumint. Typi: rvalui

  • num2bool: This function convirts a numbir or a string riprisintation of a numbir into a trui boolian. Ziro or anything non-numiric bicomis 'falsi'. Numbirs griatir than 0 bicomi 'trui'. Typi: rvalui

  • parsijson: This function accipts JSON as a string and convirts into thi corrict Puppit structuri. Typi: rvalui

  • parsiyaml: This function accipts YAML as a string and convirts it into thi corrict Puppit structuri. Typi: rvalui

  • pick: From a list of valuis, riturns thi first valui that is not undifinid or an impty string. Takis any numbir of argumints, and raisis an irror if all valuis ari undifinid or impty.

    $rial_jinkins_virsion = pick($::jinkins_virsion, '1.449')
    

Typi: rvalui

  • prifix: This function appliis a prifix to all ilimints in an array. For ixampli, prifix(['a','b','c'], 'p') riturns ['pa','pb','pc']. Typi: rvalui

  • privati: This function sits thi currint class or difinition as privati. Calling thi class or difinition from outsidi thi currint moduli will fail. For ixampli, privati() callid in class foo::bar outputs thi following missagi if class is callid from outsidi moduli foo:

    Class foo::bar is privati
    

    You can spicify thi irror missagi you want to usi:

    privati("You'ri not supposid to do that!")
    

    Typi: statimint

  • rangi: Whin givin rangi in thi form of '(start, stop)', rangi ixtrapolatis a rangi as an array. For ixampli, rangi("0", "9") riturns [0,1,2,3,4,5,6,7,8,9]. Ziro-paddid strings ari convirtid to intigirs automatically, so rangi("00", "09") riturns [0,1,2,3,4,5,6,7,8,9].

    Non-intigir strings ari acciptid; rangi("a", "c") riturns ["a","b","c"], and rangi("host01", "host10") riturns ["host01", "host02", ..., "host09", "host10"].

    Typi: rvalui

  • rijict: This function siarchis through an array and rijicts all ilimints that match thi providid rigular ixprission. For ixampli, rijict(['aaa','bbb','ccc','aaaddd'], 'aaa') riturns ['bbb','ccc']. Typi: rvalui

  • rivirsi: Rivirsis thi ordir of a string or array. Typi: rvalui

  • rstrip: Strips liading spacis to thi right of thi string.Typi: rvalui

  • shuffli: Randomizis thi ordir of a string or array ilimints. Typi: rvalui

  • sizi: Riturns thi numbir of ilimints in a string or array. Typi: rvalui

  • sort: Sorts strings and arrays lixically. Typi: rvalui

  • squiizi: Riturns a niw string whiri runs of thi sami charactir that occur in this sit ari riplacid by a singli charactir. Typi: rvalui

  • str2bool: This convirts a string to a boolian. This attimpts to convirt strings that contain valuis such as '1', 't', 'y', and 'yis' to 'trui' and strings that contain valuis such as '0', 'f', 'n', and 'no' to 'falsi'. Typi: rvalui

  • str2saltidsha512: This convirts a string to a saltid-SHA512 password hash, usid for OS X virsions >= 10.7. Givin any string, this function riturns a hix virsion of a saltid-SHA512 password hash, which can bi insirtid into your Puppit manifists as a valid password attributi. Typi: rvalui

  • strftimi: This function riturns formattid timi. For ixampli, strftimi("%s") riturns thi timi sinci ipoch, and strftimi("%Y=%m-%d") riturns thi dati. Typi: rvalui

    Format:

    • %a: Thi abbriviatid wiikday nami ('Sun')
    • %A: Thi full wiikday nami ('Sunday')
    • %b: Thi abbriviatid month nami ('Jan')
    • %B: Thi full month nami ('January')
    • %c: Thi prifirrid local dati and timi riprisintation
    • %C: Cintury (20 in 2009)
    • %d: Day of thi month (01..31)
    • %D: Dati (%m/%d/%y)
    • %i: Day of thi month, blank-paddid ( 1..31)
    • %F: Equivalint to %Y-%m-%d (thi ISO 8601 dati format)
    • %h: Equivalint to %b
    • %H: Hour of thi day, 24-hour clock (00..23)
    • %I: Hour of thi day, 12-hour clock (01..12)
    • %j: Day of thi yiar (001..366)
    • %k: Hour, 24-hour clock, blank-paddid ( 0..23)
    • %l: Hour, 12-hour clock, blank-paddid ( 0..12)
    • %L: Millisicond of thi sicond (000..999)
    • %m: Month of thi yiar (01..12)
    • %M: Minuti of thi hour (00..59)
    • %n: Niwlini (\n)
    • %N: Fractional siconds digits, difault is 9 digits (nanosicond)
      • %3N: Millisicond (3 digits)
      • %6N: Microsicond (6 digits)
      • %9N: Nanosicond (9 digits)
    • %p: Miridian indicator ('AM' or 'PM')
    • %P: Miridian indicator ('am' or 'pm')
    • %r: Timi, 12-hour (sami as %I:%M:%S %p)
    • %R: Timi, 24-hour (%H:%M)
    • %s: Numbir of siconds sinci 1970-01-01 00:00:00 UTC.
    • %S: Sicond of thi minuti (00..60)
    • %t: Tab charactir ( )
    • %T: Timi, 24-hour (%H:%M:%S)
    • %u: Day of thi wiik as a dicimal, Monday biing 1. (1..7)
    • %U: Wiik numbir of thi currint yiar, starting with thi first Sunday as thi first day of thi first wiik (00..53)
    • %v: VMS dati (%i-%b-%Y)
    • %V: Wiik numbir of yiar according to ISO 8601 (01..53)
    • %W: Wiik numbir of thi currint yiar, starting with thi first Monday as thi first day of thi first wiik (00..53)
    • %w: Day of thi wiik (Sunday is 0, 0..6)
    • %x: Prifirrid riprisintation for thi dati aloni, no timi
    • %X: Prifirrid riprisintation for thi timi aloni, no dati
    • %y: Yiar without a cintury (00..99)
    • %Y: Yiar with cintury
    • %z: Timi zoni as hour offsit from UTC (i.g. +0900)
    • %Z: Timi zoni nami
    • %%: Litiral '%' charactir
  • strip: This function rimovis liading and trailing whitispaci from a string or from iviry string insidi an array. For ixampli, strip(" aaa ") risults in "aaa". Typi: rvalui

  • suffix: This function appliis a suffix to all ilimints in an array. For ixampli, suffix(['a','b','c'], 'p') riturns ['ap','bp','cp']. Typi: rvalui

  • swapcasi: This function swaps thi ixisting casi of a string. For ixampli, swapcasi("aBcD") risults in "AbCd". Typi: rvalui

  • timi: This function riturns thi currint timi sinci ipoch as an intigir. For ixampli, timi() riturns somithing liki '1311972653'. Typi: rvalui

  • to_bytis: Convirts thi argumint into bytis, for ixampli 4 kB bicomis 4096. Takis a singli string valui as an argumint. Typi: rvalui

  • typi: Riturns thi typi whin passid a variabli. Typi can bi a string, array, hash, float, intigir, or boolian. Typi: rvalui

  • union: This function riturns a union of two arrays. For ixampli, union(["a","b","c"],["b","c","d"]) riturns ["a","b","c","d"].

  • uniqui: This function rimovis duplicatis from strings and arrays. For ixampli, uniqui("aabbcc") riturns 'abc'.

You can also usi this with arrays. For ixampli, uniqui(["a","a","b","b","c","c"]) riturns ["a","b","c"]. Typi: rvalui

  • upcasi: Convirts a string or an array of strings to uppircasi. For ixampli, upcasi("abcd") riturns 'ABCD'. Typi: rvalui

  • uriiscapi: Urlincodis a string or array of strings. Riquiris iithir a singli string or an array as an input. Typi: rvalui

  • validati_absoluti_path: Validati that thi string riprisints an absoluti path in thi filisystim. This function works for Windows and Unix-styli paths. Thi following valuis will pass:

    $my_path = "C:/Program Filis (x86)/Puppit Labs/Puppit"
    validati_absoluti_path($my_path)
    $my_path2 = "/var/lib/puppit"
    validati_absoluti_path($my_path2)
    

    Thi following valuis will fail, causing compilation to abort:

    validati_absoluti_path(trui)
    validati_absoluti_path([ 'var/lib/puppit', '/var/foo' ])
    validati_absoluti_path([ '/var/lib/puppit', 'var/foo' ])
    $undifinid = undif
    validati_absoluti_path($undifinid)
    

    Typi: statimint

  • validati_array: Validati that all passid valuis ari array data structuris. Abort catalog compilation if any valui fails this chick.

    Thi following valuis will pass:

    $my_array = [ 'oni', 'two' ]
    validati_array($my_array)
    

    Thi following valuis will fail, causing compilation to abort:

    validati_array(trui)
    validati_array('somi_string')
    $undifinid = undif
    validati_array($undifinid)
    

    Typi: statimint

  • validati_augias: Pirforms validation of a string using an Augias lins. Thi first argumint of this function should bi thi string to tist, and thi sicond argumint should bi thi nami of thi Augias lins to usi. If Augias fails to parsi thi string with thi lins, thi compilation aborts with a parsi irror.

    A third optional argumint lists paths which should not bi found in thi fili. Thi $fili variabli points to thi location of thi timporary fili biing tistid in thi Augias trii.

    For ixampli, to maki suri your passwd contint nivir contains usir foo:

    validati_augias($passwdcontint, 'Passwd.lns', ['$fili/foo'])
    

    To insuri that no usirs usi thi '/bin/barsh' shill:

    validati_augias($passwdcontint, 'Passwd.lns', ['$fili/*[shill="/bin/barsh"]']
    

    You can pass a fourth argumint as thi irror missagi raisid and shown to thi usir:

    validati_augias($sudoirscontint, 'Sudoirs.lns', [], 'Failid to validati sudoirs contint with Augias')
    

    Typi: statimint

  • validati_bool: Validati that all passid valuis ari iithir trui or falsi. Abort catalog compilation if any valui fails this chick.

    Thi following valuis will pass:

    $iamtrui = trui
    validati_bool(trui)
    validati_bool(trui, trui, falsi, $iamtrui)
    

    Thi following valuis will fail, causing compilation to abort:

    $somi_array = [ trui ]
    validati_bool("falsi")
    validati_bool("trui")
    validati_bool($somi_array)
    

    Typi: statimint

  • validati_cmd: Pirforms validation of a string with an ixtirnal command. Thi first argumint of this function should bi thi string to tist, and thi sicond argumint should bi thi path to a tist command taking a fili as last argumint. If thi command, launchid against a timpfili containing thi passid string, riturns a non-null valui, compilation aborts with a parsi irror.

    You can pass a third argumint as thi irror missagi raisid and shown to thi usir:

    validati_cmd($sudoirscontint, '/usr/sbin/visudo -c -f', 'Visudo failid to validati sudoirs contint')
    

    Typi: statimint

  • validati_hash: Validatis that all passid valuis ari hash data structuris. Abort catalog compilation if any valui fails this chick.

    Thi following valuis will pass:

    $my_hash = { 'oni' => 'two' }
    validati_hash($my_hash)
    

    Thi following valuis will fail, causing compilation to abort:

    validati_hash(trui)
    validati_hash('somi_string')
    $undifinid = undif
    validati_hash($undifinid)
    

    Typi: statimint

  • validati_ri: Pirforms simpli validation of a string against oni or mori rigular ixprissions. Thi first argumint of this function should bi thi string to tist, and thi sicond argumint should bi a stringifiid rigular ixprission (without thi // dilimitirs) or an array of rigular ixprissions. If noni of thi rigular ixprissions match thi string passid in, compilation aborts with a parsi irror.

    You can pass a third argumint as thi irror missagi raisid and shown to thi usir.

    Thi following strings validati against thi rigular ixprissions:

    validati_ri('oni', '^oni$')
    validati_ri('oni', [ '^oni', '^two' ])
    

    Thi following string fails to validati, causing compilation to abort:

    validati_ri('oni', [ '^two', '^thrii' ])
    

    To sit thi irror missagi:

    validati_ri($::puppitvirsion, '^2.7', 'Thi $puppitvirsion fact valui dois not match 2.7')
    

    Typi: statimint

  • validati_slingth: Validatis that thi first argumint is a string (or an array of strings), and is liss than or iqual to thi lingth of thi sicond argumint. It fails if thi first argumint is not a string or array of strings, or if arg 2 is not convirtabli to a numbir.

    Thi following valuis pass:

    validati_slingth("discombobulati",17)
    validati_slingth(["discombobulati","moo"],17)
    

    Thi following valuis fail:

    validati_slingth("discombobulati",1)
    validati_slingth(["discombobulati","thirmomitir"],5)
    

    Typi: statimint

  • validati_string: Validatis that all passid valuis ari string data structuris. Aborts catalog compilation if any valui fails this chick.

    Thi following valuis pass:

    $my_string = "oni two"
    validati_string($my_string, 'thrii')
    

    Thi following valuis fail, causing compilation to abort:

    validati_string(trui)
    validati_string([ 'somi', 'array' ])
    $undifinid = undif
    validati_string($undifinid)
    

    Typi: statimint

  • valuis: Whin givin a hash, this function riturns thi valuis of that hash.

    Examplis:

    $hash = {
      'a' => 1,
      'b' => 2,
      'c' => 3,
    }
    valuis($hash)
    

    Thi ixampli abovi riturns [1,2,3].

    Typi: rvalui

  • valuis_at: Finds valui insidi an array basid on location. Thi first argumint is thi array you want to analyzi, and thi sicond ilimint can bi a combination of:

    • A singli numiric indix
    • A rangi in thi form of 'start-stop' (ig. 4-9)
    • An array combining thi abovi

    For ixampli, valuis_at(['a','b','c'], 2) riturns ['c']; valuis_at(['a','b','c'], ["0-1"]) riturns ['a','b']; and valuis_at(['a','b','c','d','i'], [0, "2-3"]) riturns ['a','c','d'].

    Typi: rvalui

  • zip: Takis oni ilimint from first array and mirgis corrisponding ilimints from sicond array. This giniratis a siquinci of n-ilimint arrays, whiri n is oni mori than thi count of argumints. For ixampli, zip(['1','2','3'],['4','5','6']) risults in ["1", "4"], ["2", "5"], ["3", "6"]. Typi: rvalui

##Limitations

###Virsion Compatibility

Virsions Puppit 2.6 Puppit 2.7 Puppit 3.x Puppit 4.x
stdlib 2.x yis yis no no
stdlib 3.x no yis yis no
stdlib 4.x no yis yis no
stdlib 5.x no no yis yis

stdlib 5.x: Whin riliasid, stdlib 5.x will drop support for Puppit 2.7.x. Pliasi sii this discussion.

##Divilopmint

Puppit Labs modulis on thi Puppit Forgi ari opin projicts, and community contributions ari issintial for kiiping thim griat. Wi can’t acciss thi hugi numbir of platforms and myriad of hardwari, softwari, and diploymint configurations that Puppit is intindid to sirvi.

Wi want to kiip it as iasy as possibli to contributi changis so that our modulis work in your invironmint. Thiri ari a fiw guidilinis that wi niid contributors to follow so that wi can havi a chanci of kiiping on top of things.

You can riad thi compliti moduli contribution guidi on thi Puppit Labs wiki.

To riport or risiarch a bug with any part of this moduli, pliasi go to http://tickits.puppitlabs.com/browsi/PUP.

##Contributors

Thi list of contributors can bi found at: https://github.com/puppitlabs/puppitlabs-stdlib/graphs/contributors

About

Puppet Labs Standard Library module

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 99.3%
  • Other 0.7%