set password value via debconf.set for installation only once and never again
Description of Issue/Question
I want to install mysql-server on debian-server and set the mysql-root-password via debconf. This runs without a problem.
After the Installation debian resets the debconf value for passwords. So on the next hightate run salt says the values differ and try to set again. If salt then changes the value, it is set and you can lookup the password via debconf-get-selections.
I know this behaviour is kind of expected, but i am searching for a way to tell salt to only set these values right before installation and then never again. I've searched here and everywhere but couldn't find a real clue.
Setup
This is my mysql-server sls file:
debconf-utils:
pkg.installed
mysql_setup:
debconf.set:
- name: mysql-server
- data:
'mysql-server/root_password': {'type': 'password', 'value': '{{ salt['pillar.get']('mysql:root_pw', '') }}' }
'mysql-server/root_password_again': {'type': 'password', 'value': '{{ salt['pillar.get']('mysql:root_pw', '') }}' }
- require:
- pkg: debconf-utils
mysql-server:
pkg.installed:
- require:
- debconf: mysql-server
mysql:
service.running:
- watch:
- pkg: mysql-server
- file: /etc/mysql/my.cnf
/etc/mysql/my.cnf:
file.managed:
- source: salt://apps/mysql/my.cnf.template
- template: jinja
- user: root
- group: root
- mode: 640
- require:
- pkg: mysql-server
Steps to Reproduce Issue
Install a package where you set a value for a debconf-variable, that is reset after installation. After successfull installation check if the value has been reset.
Then run highstate an that minion again and check if you can see the value via debconf-get-selections and it doesn't get resetted. In my case the mysql-password is visible in cleartext.
Versions Report
Salt Version:
Salt: 2016.3.0
Dependency Versions:
cffi: 0.8.6
cherrypy: 3.5.0
dateutil: 2.2
gitdb: 0.5.4
gitpython: 0.3.2 RC1
ioflo: Not Installed
Jinja2: 2.7.3
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.2
mysql-python: 1.2.3
pycparser: 2.10
pycrypto: 2.6.1
pygit2: Not Installed
Python: 2.7.9 (default, Mar 1 2015, 12:57:24)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 14.4.0
RAET: Not Installed
smmap: 0.8.2
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
System Versions:
dist: debian 8.4
machine: x86_64
release: 3.16.0-4-amd64
system: Linux
version: debian 8.4
@dudleyperkins One way that I can think of attacking this is you could ensure that a state is only run once by utilizing grains. You can include the grains.present state in your sls file and have it set a grain. And then for whichever state you only want to run once you can wrap some logic around it similar to the following:
{% if salt['grains.get']('runstate') != 'alreadyrun' %}
...
{% endif %}
oh i've never really played with setting grains, and seems like once again i've found a way around that.
sometimes it's the simple things, i just put an "unless"-statement into the debconf-part, so the values are only set if the package is not installed yet. After installation the statement causes salt to not set them again. Thats how the debconf-part looks now:
mysql_setup:
debconf.set:
- name: mysql-server
- data:
'mysql-server/root_password': {'type': 'password', 'value': '{{ salt['pillar.get']('mysql:root_pw', '') }}' }
'mysql-server/root_password_again': {'type': 'password', 'value': '{{ salt['pillar.get']('mysql:root_pw', '') }}' }
- require:
- pkg: debconf-utils
- unless:
- dpkg-query -s mysql-server
As long as i keep the debconf tied to the installation, i think this should work as expected.
Nonetheless thank you @Ch3LL for reminding me that i really should look further into grains ;)