puppet - Proper syntax for entry in Hiera yaml file -
the goal supply default value parameter being passed defined resource type. have supplied defaults class parameters using automatic defaulting procedure uses hiera, mechanism not work defined types.
here how call hiera in defined type:
define git_down( $local_repo_dir = undef, $remote_repo_url = undef, $version = undef, $shell = hiera("git_down::shell"), $path = hiera("git_down::path"), $date_format = hiera("git_down::date_format", '%y-%m-%d %h:%m:%s') ) { ... more puppet code type definition... }
my idea create classes have normal automatic defaults parameters keyed class name (hence done in class files, not shown), make other parameters same default users of type, regardless of class. above type permit updating git repo. needs type , not class, because need fetch files multiple git repositories, , classes singletons, while types may have multiple instances. every class declares "git_down" instance should expect find git executables (git_down::path , git_down::shell) in same place. different each class url of source repo, directory store local repo cloned or fetched into, , version tag checkout.
here hiera.yaml looks like:
--- :backends: - yaml :yaml: :datadir: c:/temp/usr :hierarchy: - "git_%{fqdn}" - "git_%{osfamily}" - git_common
(note: did not use ::fqdn , ::osfamily here because standalone hiera command line tool not recognize them. may add double colons when working.)
i not have machine specific yaml file (based on fqdn, fully-qualified-domain-name) should in osfamily specific file, git_windows.yaml:
--- # default class parameters when ::osfamily "windows" git_checkout::local_repo_dir: c:/usr/git_test_5 git_checkout::remote_repo_url: file:///c/usr/git_test git_checkout::version: v11.0.7.81 git_down::shell: 'c:/program files (x86)/git/bin/sh.exe' git_down::path: '/bin:/c/program files (x86)/git/bin' git_down::date_format: '%y-%m-%d %h:%m:%s'
i tested hiera way:
1) use command line facter create yaml fact file facts (as needed when running hiera):
facter -y > ..\facts.yaml
2) use command line hiera see if recognizes variables:
hiera -d -c ..\hiera.yaml -y ..\facts.yaml git_down::shell
hiera outputs following:
c:\usr\git_type\manifests>hiera.bat -d -c ..\hiera.yaml -y ..\facts.yaml git_down::shell debug: 2014-07-01 14:17:46 -0400: hiera yaml backend starting debug: 2014-07-01 14:17:46 -0400: looking git_down::shell in yaml backend debug: 2014-07-01 14:17:46 -0400: looking data source git_usb-pctbspaul.ef.com debug: 2014-07-01 14:17:46 -0400: cannot find datafile c:/usr/git_type/git_usb-pctbspaul.ef.com.yaml, skipping debug: 2014-07-01 14:17:46 -0400: looking data source git_windows debug: 2014-07-01 14:17:46 -0400: found git_down::shell in git_windows nil
instead of "nil", should see "c:/program files (x86)/git/bin/sh.exe". wrong?
while writing question, found answer.
in hiera.yaml, pointing wrong datadir!!!
i pointing older version of code, had of variables defined, other variables not defined.
my corrected hiera.yaml:
--- :backends: - yaml :yaml: :datadir: c:/usr/git_type :hierarchy: - "git_%{fqdn}" - "git_%{osfamily}" - git_common
Comments
Post a Comment