# chef\_env getting set incorrectly in node attr data

**URL:** <https://discourse.chef.io/t/chef-env-getting-set-incorrectly-in-node-attr-data/2397>\
**Category:** Chef Infra (archive)\
**Created:** [January 26, 2012, 11:51pm UTC](https://discourse.chef.io/t/chef-env-getting-set-incorrectly-in-node-attr-data/2397 "2012-01-26T23:51:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kallen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallen/32/1049_2.png) [@Kallen](https://discourse.chef.io/u/Kallen)\
**Post date:** [January 26, 2012, 11:51pm UTC](https://discourse.chef.io/t/chef-env-getting-set-incorrectly-in-node-attr-data/2397/1 "2012-01-26T23:51:29Z")

</div>

hi. i’m trying to figure out how the chef\_environment is being set  
incorrectly on some of my nodes, and could use advice on how to rummage  
around to find the culprit.

one of my recipes relies on grabbing something from a data bag depending  
on which chef\_environment is set. i’m currently seeing a “dev” item  
being grabbed on a host which should be “prod”.

as background, the way i bootstrap chef onto my systems, hence establishing  
at the very start which chef\_env it is, is by doing:

# tail -1 /etc/chef/client.rb

environment “prod”

# chef-client -j /etc/chef/first-boot.json -l debug -L /var/log/chef/client.log

# knife environment show dev | grep ^name

name: dev

# knife environment show prod | grep ^name

name: prod

(in case you want to see fuller output of the above, it’s at the end.)

in viewing this node’s attr data, i can see there are 2 places where  
chef\_environment is set. the correct and desired env is “prod”, which  
appears at the end of the node attr data below. the incorrect env is  
"dev", which appears as a “normal” attr at the top of the below output.

one thing i tried was to use “knife node edit”. i’m not certain of what  
the -E arg is supposed to do…

# knife node edit -E prod [admin1.prod.spergatronic.com](http://admin1.prod.spergatronic.com)

the node attr json appeared in $EDITOR, i corrected the chef\_env value  
under the “normal” attrs. i ran chef-client again on this client, and  
then the normal attrs again showed the wrong chef\_env - “dev”.

fwiw, in the client debug output, i do see the likes of  
[Thu, 26 Jan 2012 23:45:31 +0000] DEBUG: Sending HTTP Request via GET to [chef.dev.spergatronic.com:443/environments/prod](http://chef.dev.spergatronic.com:443/environments/prod)

any halps? many thanks,  
kallen

chef server: ubuntu 11.04, 0.10.8-1  
chef client: centos 5.7, 0.10.4-1

the following output was created by

# knife node show [admin1.prod.spergatronic.com](http://admin1.prod.spergatronic.com) -l -Fj

for brevity, i’m snipped out a lot, but left in the relevant bits.

{  
“normal”: {  
“mail\_type”: “master”,  
“chef\_environment”: “dev”,  
“tags”: [

```
],
"aws": {
  "aws_x509_cert_path": "/etc/ec2/certs/servercert.pem",
  "aws_x509_key_path": "/etc/ec2/certs/privatekey.pem"
},

```

},  
“name”: “[admin1.prod.spergatronic.com](http://admin1.prod.spergatronic.com)”,  
“override”: {  
“chef\_client”: {  
“server\_url”: “[https://chef.dev.spergatronic.com](https://chef.dev.spergatronic.com)”,  
“init\_style”: “init”,  
“validation\_client\_name”: “chef-validator”,  
“runstyle”: “cron”  
},  
“postfix”: {  
“smtp\_sasl\_auth\_enable”: “yes”,  
“mail\_type”: “master”,  
“mail\_relay\_networks”: “10.0.0.0/8, 127.0.0.0/8, 172.22.22.0/24”  
}  
},  
“default”: {  
“aws\_x509\_cert\_path”: “/etc/ec2/certs/servercert.pem”,  
},  
“firewall”: {  
“rules”: [

```
  ],
  "securitylevel": ""
},
"chef_server_url": "https://chef.dev.spergatronic.com",
"aws_x509_key_path": "/etc/aws/certs/privatekey.pem",
"yum": {
  "exclude": {
  },
  "installonlypkgs": {
  },
  "ius_release": "1.0-8",
  "epel_release": "5-4"
},
"aws": {
  "right_aws_version": "2.1.0"
},
"s3cmd": {
  "users": [
    "root"
  ]
},
"resolver": {
  "domain": [
    "prod.spergatronic.com"
  ],
  "nameservers": [
    "10.251.x.x",
    "10.64.x.x",
    "10.252.x.x",
    "10.245.x.x"
  ],
  "search": [
    "prod.spergatronic.com"
  ]
},
"chef_client": {
  "conf_dir": "/etc/chef",
  "cache_path": "/var/cache/chef",
  "backup_path": "/var/lib/chef",
  "init_style": "init",
  "ohai_plugin_disable": true,
  "validation_client_name": "chef-validator",
  "run_path": "/var/run/chef",
  "bin": "/usr/bin/chef-client",
  "splay": "20",
  "interval": "1800",
  "croninterval": "0 */4 * * *",
  "log_dir": "/var/log/chef"
},
"postfix": {
  "myorigin": "$myhostname",
  "myhostname": "admin1.prod.spergatronic.com",
  "relayhost": "[outbound.mailhop.org]",
  "smtp_fallback_relay": "[smtp.gmail.com]:587",
  "smtp_use_tls": "yes",
}

```

},  
“automatic”: {  
“dmi”: {  
“dmidecode\_version”: “2.11”  
},  
“keys”: {  
“ssh”: {  
“host\_dsa\_public”: “AAAABsnip”,  
“host\_rsa\_public”: “AAAABsnip”,  
}  
},  
“kernel”: {  
snip  
},  
“machine”: “i686”,  
“name”: “Linux”,  
“os”: “GNU/Linux”,  
“version”: “#1 SMP Fri Feb 15 12:39:36 EST 2008”,  
“release”: “2.6.21.7-2.fc8xen”  
},  
“platform\_version”: “5.7”,  
“fqdn”: “[admin1.prod.spergatronic.com](http://admin1.prod.spergatronic.com)”,  
“command”: {  
“ps”: “ps -ef”  
},  
“ipaddress”: “10.215.x.x”,  
“domain”: “[prod.spergatronic.com](http://prod.spergatronic.com)”,  
“os”: “linux”,  
“lsb”: {  
},  
“virtualization”: {  
“role”: “guest”,  
“system”: “xen”  
},  
“current\_user”: “root”,  
“ohai\_time”: 1327618833.9791,  
“chef\_packages”: {  
“ohai”: {  
“ohai\_root”: “/usr/lib/ruby/gems/1.8/gems/ohai-0.6.4/lib/ohai”,  
“version”: “0.6.4”  
},  
“chef”: {  
“version”: “0.10.4”,  
“chef\_root”: “/usr/lib/ruby/gems/1.8/gems/chef-0.10.4/lib”  
}  
},  
“recipes”: [  
“chef-client::delete\_validation”,  
“chef-client::config”,  
“chef-client”,  
“aws”,  
“toolbin”,  
“s3cmd”,  
“users::ops”,  
“yum”,  
“bind9::nameserver”,  
“syslog-ng::17syslog-ng”,  
“postfix”,  
“postfix::sasl\_auth”  
],  
“os\_version”: “2.6.21.7-2.fc8xen”,  
“languages”: {  
“python”: {  
“version”: “2.4.3”,  
“builddate”: “Sep 21 2011, 20:06:00”  
},  
“perl”: {  
“version”: “5.8.8”,  
“archname”: “i386-linux-thread-multi”  
},  
“ruby”: {  
“target\_os”: “linux”,  
“bin\_dir”: “/usr/bin”,  
“host\_vendor”: “redhat”,  
“target\_vendor”: “redhat”,  
“target\_cpu”: “i386”,  
“ruby\_bin”: “/usr/bin/ruby”,  
“version”: “1.8.7”,  
“host\_os”: “linux-gnu”,  
“target”: “i386-redhat-linux-gnu”,  
“release\_date”: “2011-06-30”,  
“host\_cpu”: “i686”,  
“host”: “i686-redhat-linux-gnu”,  
“gems\_dir”: “/usr/lib/ruby/gems/1.8”,  
“platform”: “i386-linux”  
}  
},  
“uptime”: “49 days 03 hours 03 minutes 44 seconds”,  
“hostname”: “admin1”,  
“roles”: [  
“admin-server”,  
“syslog-ng-server”,  
“postfix-server”,  
“dns-client”,  
“chef-client”,  
“vpn-server”,  
“dns-server”,  
“base”  
],  
“ec2”: {  
“placement\_availability\_zone”: “us-east-1a”,  
},  
“platform”: “centos”,  
},  
“chef\_environment”: “prod”,  
“run\_list”: [  
“role[base]”,  
“role[dns-server]”,  
“role[dns-client]”,  
“role[syslog-ng-server]”,  
“role[postfix-server]”,  
“role[admin-server]”  
]  
}

[chef-repo]$ knife environment show dev  
chef\_type: environment  
cookbook\_versions:  
default\_attributes:  
resolver:  
domain: [dev.spergatronic.com](http://dev.spergatronic.com)  
nameservers:  
10.69.xx.xx  
10.66.89.xx  
10.xx.55.xx  
10.xx.65.xx  
search: [dev.spergatronic.com](http://dev.spergatronic.com)  
description: Development environment (dev)  
json\_class: Chef::Environment  
name: dev  
override\_attributes:

[chef-repo]$ knife environment show prod  
chef\_type: environment  
cookbook\_versions:  
default\_attributes:  
resolver:  
domain: [prod.spergatronic.com](http://prod.spergatronic.com)  
nameservers:  
10.251.xx.0  
10.64.xx.51  
10.252.xx.163  
10.245.xx.162  
search: [prod.spergatronic.com](http://prod.spergatronic.com)  
description: Production environment (prod)  
json\_class: Chef::Environment  
name: prod  
override\_attributes:

---

<div class="post-metadata">

**Author:** ![Kallen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallen/32/1049_2.png) [@Kallen](https://discourse.chef.io/u/Kallen)\
**Post date:** [January 27, 2012, 12:19am UTC](https://discourse.chef.io/t/chef-env-getting-set-incorrectly-in-node-attr-data/2397/2 "2012-01-27T00:19:48Z")

</div>

On Thu, 26 Jan 2012, [kallen@groknaut.net](mailto:kallen@groknaut.net) wrote:

> hi. i'm trying to figure out how the chef\_environment is being set  
> incorrectly on some of my nodes, and could use advice on how to rummage  
> around to find the culprit.

found it! i was mistakenly using an assignment operator rather than a  
check value operator.

wrong:  
if node[:chef\_environment] = /dev/  
aws\_creds = Chef::EncryptedDataBagItem.load("hush","bag-dev")

right:  
if node[:chef\_environment] == /dev/

just enough ruby to be dangerous! thanks for playing :\>

kallen
