← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~danielwallace/cloud-init:salt-grains into cloud-init:master

 

Daniel Wallace has proposed merging ~danielwallace/cloud-init:salt-grains into cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~danielwallace/cloud-init/+git/cloud-init/+merge/334718

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.
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~danielwallace/cloud-init:salt-grains into cloud-init:master.
diff --git a/cloudinit/config/cc_salt_minion.py b/cloudinit/config/cc_salt_minion.py
index 2b38837..c63f4ee 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('conf'))
+        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"):

Follow ups