Git Cycle

  1. Create a git user and group.
  2. Generate a SSH public/private key pair for the git user and put the public key into the SaltStack pillar data for git_cycle.
  3. Copy the git_cycle.sh script into the git user’s home directory.
  4. Create an entry in the git user’s crontab to execute the git_cycle.sh script. Bonus points for redirecting the output to a log file.
  5. Create a folder to store the files from your hosts in. For me, I put those files in alongside the state files that will be using them. So, /srv/salt/hosts.
  6. For each Minion I want to retrieve files for, just create a sub directory.
/srv/salt/hosts/
└── Minion1
├── Minion2
  1. It creates a gituser and group.
  2. Adds a public key to the git user’s authorized_keys file.
  3. Adds specified users to the git group
  4. Copies a .gitconfig file to each user’s home directory.
  5. It creates a git repository in the root of the minion’s filesystem. Putting it there allows files from anywhere in the filesystem to be added.
  1. Execute the bash script git_cycle.sh. Accept when prompted about the remote hosts keys.
  2. You should now see the Minion files populating in the /srv/salt/hosts/ directory.
  3. Keep in mind that you have these files now when crafting your states. In the below example, salt first tries to use the host specific nrpe.cfg file that we git pull from the server. If there isn’t one, it will fall back to the default file which I keep stored with the state file.
# Drop in the nrpe.cfg file specific for this host. Or if its a new host, just use the default
{% set hostname = salt.grains.get('id') %}
nrpe_config_file:
file.managed:
- name: /etc/nagios/nrpe.cfg
- source:
- salt://hosts/{{ hostname }}/etc/nagios/nrpe.cfg
- salt://nrpe/nrpe.cfg
- makedirs: True
- user: root
- group: root
- mode: 644

--

--

Climber, surfer, yogi, dad who does some IT on the side to get by.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store