I would like to use the metadata like policy_group from Automate in my Chef recipe. I have tried using Chef::Node and Chef::Config and both seem impossible.
Hello! You should be able to access this as the attribute node['policy_group'] from within a recipe -- is that what you're looking for there?
Hello Colin, thank you for replying. I ran these commands under Chef-client on the machine where I run the converges and I got nil return values.
chef (16.9.20)> Chef ::node[ ' policy_group ' ]
=> nil
chef (16.9.20)> node[ ' policy_group ' ]
=> nil
chef (16.9.20)> node
=> <Chef::Node:0xc30 @name="abc">
chef (16.9.20)> Chef ::node
=> <Chef::Node:0xc30 @name="abc">
Hello! If you load up chef-shell with the -z
flag that should get it running as the actual client, loading in the configuration, which should then show this data:
[root@localhost ~]# chef-shell -z
loading configuration: /etc/chef/client.rb
true
Session type: client
Loading.....Using policy 'chef-client' at revision '68b7e87a4afda1c82c6cbf587b654eb8788cabf3422af238cad2afb3ca9ad388'
resolving cookbooks for run list: ["chef-client::default@12.1.0 (f306f6c)"]
.Synchronizing Cookbooks:
- chef-client (12.1.0)
- cron (6.3.1)
- logrotate (2.2.3)
done.
Welcome to the chef-shell 16.9.32
For usage see https://docs.chef.io/chef_shell/
run `help' for help, `exit' or ^D to quit.
chef (16.9.32)> node['policy_group']
=> "prod"
chef (16.9.32)>