How can I "sprinkle" my minions with custom grains when deploying salt-minion using Saltify (salt-cloud)?

485 Views Asked by At

I've gotten saltify to work on a fresh minion. I am able to specify a profile for the minion as well. However, I don't know how to assign custom grains to my minion during this process.

Here's my set up.

In /etc/salt/cloud.profiles.d/saltify.conf I have:

salt-this-webserver:
  ssh_host: 10.66.77.99
  ssh_username: opsuser
  password: **********
  provider: web-saltify-config

salt-this-fileserver:
  ssh_host: 10.66.77.99
  ssh_username: opsuser
  password: **********
  provider: file-saltify-config

In /etc/salt/cloud/cloud.providers I have:

web-saltify-config:
  minion:
    master: 10.66.77.44
  driver: saltify
  grains:
    layers:
      - infrastructure
    roles:
      - web-server

file-saltify-config:
  minion:
    master: 10.66.77.55
  driver: saltify
  grains:
    layers:
      - infrastructure
    roles:
      - file-server

When I run my command from my Salt master:

salt-cloud -p salt-this-fileserver slave-salttesting-01.eng.example.com

My /etc/salt/minion file on my minion looks like this:

grains:
  salt-cloud:
    driver: saltify
    profile: salt-this-fileserver
    provider: file-saltify-config:saltify
hash_type: sha256
id: slave-salttesting-01.eng.example.com
log_level: info
master: 10.66.77.99

I would really like it to also have:

grains:
  layers:
    - infrastructure
  roles:
    - file-server

I'd like for this to happen during the saltify stage rather than a subsequent step because it just fits really nicely into what I'm trying to accomplish at this step.

Is there a way to sprinkle some grains on my minion during "saltification"?

EDIT: The sync_after_install configuration parameter may have something to do with it but I'm not sure where to put my custom modules, grains, states, etc.

1

There are 1 best solutions below

0
On

I found the grains from my cloud.providers file in /etc/salt/grains This appears to just work if you build your cloud.providers file in a similar fashion to the way I built mine (above).

I enabled debugging (in /etc/salt/cloud) and in the debugging output on the screen I can see a snippet of code that suggests that at some point a file named "grains" in the conf directory in git root may also be transferred over:

# Copy the grains file if found
if [ -f "$_TEMP_CONFIG_DIR/grains" ]; then
  echodebug "Moving provided grains file from $_TEMP_CONFIG_DIR/grains to $_SALT_ETC_DIR/grains"

But, I am not sure because I didn't dig into it more since my grains are being sprinkled as I had hoped they would.