diff options
author | Daniel Wallace <danielwallace@gtmanfred.com> | 2017-12-04 16:49:15 -0700 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2018-02-23 10:26:42 -0500 |
commit | 65f0b263a1af170802215823d6e354f8bdfa5f39 (patch) | |
tree | 37ddb2b1528973f56b4c1bd52b73e8b0e7a15de1 | |
parent | 1e2c2f84cf68e19728f7bc51f0c9322c3e895019 (diff) | |
download | vyos-cloud-init-65f0b263a1af170802215823d6e354f8bdfa5f39.tar.gz vyos-cloud-init-65f0b263a1af170802215823d6e354f8bdfa5f39.zip |
salt: configure grains in grains file rather than in minion config.
While salt grains can be configured in the minion config file, it is
usually better to configure it in the /etc/salt/grains file.
This allows that to be done.
-rw-r--r-- | cloudinit/config/cc_salt_minion.py | 9 | ||||
-rw-r--r-- | tests/cloud_tests/testcases/modules/salt_minion.py | 5 | ||||
-rw-r--r-- | tests/cloud_tests/testcases/modules/salt_minion.yaml | 5 |
3 files changed, 19 insertions, 0 deletions
diff --git a/cloudinit/config/cc_salt_minion.py b/cloudinit/config/cc_salt_minion.py index 2b388372..5112a347 100644 --- a/cloudinit/config/cc_salt_minion.py +++ b/cloudinit/config/cc_salt_minion.py @@ -25,6 +25,9 @@ specified with ``public_key`` and ``private_key`` respectively. salt_minion: conf: master: salt.example.com + grains: + role: + - web public_key: | ------BEGIN PUBLIC KEY------- <key data> @@ -65,6 +68,12 @@ def handle(name, cfg, cloud, log, _args): minion_data = util.yaml_dumps(salt_cfg.get('conf')) util.write_file(minion_config, minion_data) + if 'grains' in salt_cfg: + # add grains to /etc/salt/grains + grains_config = os.path.join(config_dir, 'grains') + grains_data = util.yaml_dumps(salt_cfg.get('grains')) + util.write_file(grains_config, grains_data) + # ... copy the key pair if specified if 'public_key' in salt_cfg and 'private_key' in salt_cfg: if os.path.isdir("/etc/salt/pki/minion"): diff --git a/tests/cloud_tests/testcases/modules/salt_minion.py b/tests/cloud_tests/testcases/modules/salt_minion.py index c697db2d..f13b48a0 100644 --- a/tests/cloud_tests/testcases/modules/salt_minion.py +++ b/tests/cloud_tests/testcases/modules/salt_minion.py @@ -26,4 +26,9 @@ class Test(base.CloudTestCase): self.assertIn('<key data>', out) self.assertIn('------END PUBLIC KEY-------', out) + def test_grains(self): + """Test master value in config.""" + out = self.get_data_file('grains') + self.assertIn('role: web', out) + # vi: ts=4 expandtab diff --git a/tests/cloud_tests/testcases/modules/salt_minion.yaml b/tests/cloud_tests/testcases/modules/salt_minion.yaml index f20d24f0..ab0e05bb 100644 --- a/tests/cloud_tests/testcases/modules/salt_minion.yaml +++ b/tests/cloud_tests/testcases/modules/salt_minion.yaml @@ -17,6 +17,8 @@ cloud_config: | ------BEGIN PRIVATE KEY------ <key data> ------END PRIVATE KEY------- + grains: + role: web collect_scripts: minion: | #!/bin/bash @@ -30,5 +32,8 @@ collect_scripts: minion.pub: | #!/bin/bash cat /etc/salt/pki/minion/minion.pub + grains: | + #!/bin/bash + cat /etc/salt/grains # vi: ts=4 expandtab |