0

I am new to Chef and Ruby and I have been playing with recipes for just couple of days. Currently I am stuck with one problem which I think is simple but due to lack of proper knowledge I am not able to solve it.

I am going to creste chef recipy which will configure network interface on Linux VM.

My ifcfg-ethX template looks as follows:

ifcfg-ethX.erb

DEVICE=<% @int_name %>
HWADDR=<% @mac_address%>
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTBROTO=static
IPADDR=<% @ip_addr%>
NETMASK=<% @netmask %>

And most of the attributes will be retrieved from enviroment file. The structure of the file is:

default_attributes dev: {

#######################################################
#dev.bootstrap 
#######################################################
#default.dev.
    bootstrap:  {
################## nodes #######################
# nodes being managed this environment
        nodes:  [
            {
                fqdn: "Host01a",
                ip: "10.108.95.139",
                run_list: "role[roleA]",
                configs: [:FUNC01a],
            },
            {
                fqdn: "Host01b",
                ip: "10.108.95.140",
                run_list: "role[roleA]",
                configs: [:FUNC01b],
            },
############### End of bootstrap nodes  #################
#default.dev.bootstrap.nodes []
        ]
    },







    config: {   

######################    CONFIGS    ######################
#default.dev.config.
        FUNC01a: {
            ip: "10.0.0.1",
            fqdn: "Host01a",
            network: "255.25.255.0",
            int: "eth0",
            internal_ip: "10.1.0.1",
            internal_fqdn: "Host01aINT",
            internal_network: "255.25.255.0",
            internal_int" "eth1",
            traffic_ip: "10.2.0.1",
            traffic_fqdn: "Host01aPROD",
            traffic_network: "255.25.255.0",
            traffic_int" "eth2",
        },
        FUNC01b: {
            ip: "10.0.0.2",
            fqdn: "Host01b",
            network: "255.25.255.0",
            int: "eth0",
            internal_ip: "10.1.0.2",
            internal_fqdn: "Host01bINT",
            internal_network: "255.25.255.0",
            internal_int" "eth1",
            traffic_ip: "10.2.0.2",
            traffic_fqdn: "Host01bPROD",
            traffic_network: "255.25.255.0",
            traffic_int" "eth2",
        },

My problem is that I cannot retrieve the network parameters from that enviroment file dynamically. My current env flile defines only 2 hosts, but there will be dozens of them and probably new one will be constantly added, so I must have a recipe that copes with that. All solutions will be much appreciated.

1 Answers1

0

This isn't how you use Chef's environments feature. Node attributes are always per-node data, environment-level attrs would be for per-node data that is set for each environment, like during on longer log retention for production servers or different package versions in staging. For this case you would probably have to set those values in each node (as normal level attributes) because there is no role or environment grouping that applies to them, they are unique snowflake data.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Why would specific host attribute not be part of an environment? I am going to have couple of environment files (production, development, lab etc.) and each of them will contain different set of hostnames, interfaces and IP addresses... Are these not environment specific attributes? – Grzesiu Kropka PL Jan 28 '18 at 22:20
  • Because they are host-specific, not environment-specific. The fact that hosts are in environments doesn't change the baseline grouping. – coderanger Jan 29 '18 at 00:35
  • Could you give me an example then where these attributes can be stored and how to access them on each node injecting hostname in the path? – Grzesiu Kropka PL Jan 29 '18 at 07:57
  • Basically what I am looking for is how to access e.g. current ip addresses and interface names by injecting the hostname or "configs" name of the current VM in the path: e.g. node[:dev][:config][] [:internal_ip] how can I use that dynamically? – Grzesiu Kropka PL Jan 29 '18 at 10:52
  • I don't understand your question, sorry. – coderanger Jan 30 '18 at 02:01