# Provide debconf variable from data bag? (Newbie)

**URL:** <https://discourse.chef.io/t/provide-debconf-variable-from-data-bag-newbie/7730>\
**Category:** Chef Infra (archive)\
**Created:** [February 3, 2016, 3:20pm UTC](https://discourse.chef.io/t/provide-debconf-variable-from-data-bag-newbie/7730 "2016-02-03T15:20:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nogginboink](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/nogginboink/32/1274_2.png) [@nogginboink](https://discourse.chef.io/u/nogginboink)\
**Post date:** [February 3, 2016, 3:20pm UTC](https://discourse.chef.io/t/provide-debconf-variable-from-data-bag-newbie/7730/1 "2016-02-03T15:20:29Z")

</div>

I’m just starting to learn my way around chef by designing recipes and cookbooks to install a distributed application.

One of the first things I need to do is install mariadb on one of my servers. Because many recipes will need the database root password, I’ve put the root password in a data bag. (I think that’s an appropriate choice, no?)

To install the database server, a recipe will have a section similar to:

```
package 'database-server' do
   package_name 'mariadb-server'
   action [:install]
end

```

My question: how can I take the root password out of the databag and supply it to dpkg so that the database server installation succeeds and the root password is the one I gave?

The debconf variable names needed (from `debconf-get-selections`) are, I believe, `mysql-server/root_password` and `mysql-server/root_password_again`.

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [February 3, 2016, 7:35pm UTC](https://discourse.chef.io/t/provide-debconf-variable-from-data-bag-newbie/7730/2 "2016-02-03T19:35:53Z")

</div>

Basically you just need to create a debian pressed file and run `debconf-set-selections FILE_PATH`. Be sure to set the `DEBIAN_FRONTEND` env var to “noninteractive” so it doesn’t pop up a modal dialog. You could do that manually with a template file and execute resource, which might be the easiest way.

Chef also has built-in support for this in the package resource, but it can be a bit tricky to use. if you want to use it, create a template for the response file, then set the `response_file` property on the resource. Standard naming convention is `$package_name.seed.erb`. You set the variables to pass in with the `response_file_variables` property (it’s a Hash, like you would give to a normal template resource). Then the package resource should automatically find the template and evaluate it and run `debconf-set-selections` for you when installing.

Either way, you’ll probably want to run in debug mode while you’re getting this all working, using hard coded values at first to make your task simpler, then change the code to pull the values from a data bag which should be pretty straightforward once the other stuff works.

---

<div class="post-metadata">

**Author:** ![nogginboink](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/nogginboink/32/1274_2.png) [@nogginboink](https://discourse.chef.io/u/nogginboink)\
**Post date:** [February 3, 2016, 8:52pm UTC](https://discourse.chef.io/t/provide-debconf-variable-from-data-bag-newbie/7730/3 "2016-02-03T20:52:17Z")

</div>

Thanks for the input, but I’m afraid I’m still having difficulties. It appears that running debconf-set-selections in my recipe isn’t doing anything. I have:

```
bash 'set_apt_noninteractive' do
  command 'export DEBIAN_FRONTEND="noninteractive"'
end

cookbook_file 'mariadb_preseed_answers' do
  source 'mariadb-preseed'
  mode '777'
  path '/home/mariadb_preseed.txt'
end

bash 'load_mariadb_preseed' do
  command "debconf-set-selections /home/mariadb_preseed.txt"
end

bash 'list_debconf_variables' do
  command "debconf-get-selections > /home/debconfselections.txt"
end

```

I’m finding that, though the client reports that everything runs without error, the debconf settings aren’t getting set, and `/home/debconfselections.txt` isn’t getting created. However, `/home/mariadb_preseed.txt` is getting copied over, and if I run `debconf-set-selections /home/mariadb_preseed.txt` at the command line, the settings take effect.

I’m afraid I’m new enough to Chef that I don’t know how to troubleshoot this from here. If I do install mariadb-server from within the recipe, it doesn’t use the password specified in the preseed file. If I install mariadb-server from the command line after running `debconf-set-selections`, the DB server installs with the password I specified in the file.

It seems as if the shell command `debconf-set-selections` isn’t doing anything when run by the Chef client, but I suspect the true explanation is a bit more involved than that.

Any further trouleshooting suggestions from the community would be appreciated.

---

<div class="post-metadata">

**Author:** ![nogginboink](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/nogginboink/32/1274_2.png) [@nogginboink](https://discourse.chef.io/u/nogginboink)\
**Post date:** [February 3, 2016, 9:55pm UTC](https://discourse.chef.io/t/provide-debconf-variable-from-data-bag-newbie/7730/4 "2016-02-03T21:55:54Z")

</div>

I found that changing my `bash` block to an `execute` block to run debconf-set-selections did the trick.

If anyone can give me the quick version of why one works and the other doesn’t, I’d appreciate the enlightenment.

Thanks, everyone!

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [February 3, 2016, 11:21pm UTC](https://discourse.chef.io/t/provide-debconf-variable-from-data-bag-newbie/7730/5 "2016-02-03T23:21:11Z")

</div>

> [@nogginboink](#):
>
> ```auto
> bash 'set_apt_noninteractive' do
> command 'export DEBIAN_FRONTEND="noninteractive"'
> end
> 
> ```

Just wanted to point out that code like that won't do anything for you. What it does is it starts a bash process, which then sets an environment variable for itself, and then exits. This won't have any effect on any subsequent bash resources you run. You instead want to use the `env` parameter for execute/bash/other script resources, which will set the environment for the process when chef launches it.
