Manage multiple server & client computers with SaltStack (finnish)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.1 KiB

  1. #!/bin/sh
  2. # Author: Pekka Helenius (~Fincer), 2018
  3. #
  4. # - This script creates two different text strings for two minions: minion_1 & minion_2
  5. # - This script is meant to be run on Salt master
  6. #
  7. # - This script creates the following files on master:
  8. # /srv/pillar/top.sls
  9. # /srv/pillar/minion-1.sls
  10. # /srv/pillar/minion-2.sls
  11. # /srv/salt/files/pillarfile
  12. # /srv/salt/myfirstpillar.sls
  13. if [ $(id -u) -eq 0 ]; then
  14. mkdir -p /srv/pillar
  15. tee /srv/pillar/top.sls <<PILLAR_TOP
  16. base:
  17. 'minion_1':
  18. - minion-1
  19. 'minion_2':
  20. - minion-2
  21. PILLAR_TOP
  22. tee /srv/pillar/minion-1.sls <<MINION_1_DATA
  23. test_variable: 'secret like coffee shop wants to say hello to the world'
  24. MINION_1_DATA
  25. tee /srv/pillar/minion-2.sls <<MINION_2_DATA
  26. test_variable: 'hidden miniart: superman vs. hulk figures'
  27. MINION_2_DATA
  28. mkdir -p /srv/salt/files
  29. tee /srv/salt/files/pillarfile << PILLARFILE_CONTENT
  30. This is my pillarfile which has the following content:
  31. {{ pillar['test_variable'] }}
  32. PILLARFILE_CONTENT
  33. tee /srv/salt/myfirstpillar.sls <<GENERIC_PILLAR
  34. pillar_file:
  35. file.managed:
  36. - user: 1000
  37. - group: 1000
  38. - name: /tmp/pillarfile_for_{{ grains['id'] }}
  39. - source: salt://files/pillarfile
  40. - makedirs: True
  41. - template: jinja
  42. GENERIC_PILLAR
  43. if [ ! -f /srv/salt/myfirstpillar.sls ] || \
  44. [ ! -f /srv/salt/files/pillarfile ] || \
  45. [ ! -f /srv/pillar/top.sls ]; then
  46. echo "Salt files missing. Aborting."
  47. exit 1
  48. else
  49. salt 'minion_*' test.ping
  50. if [ $? -eq 0 ]; then
  51. echo -e "\e[1m\n**Salt -- pillar.items output**\n\e[0m"
  52. salt 'minion_*' pillar.items
  53. echo -e "\e[1m\n**Salt -- saltutil.refresh_pillar output**\n\e[0m"
  54. salt 'minion_*' saltutil.refresh_pillar
  55. echo -e "\e[1m\n**Salt -- state.apply output**\n\e[0m"
  56. salt 'minion_*' state.apply myfirstpillar
  57. echo -e "\e[1m\n**Salt -- get file output with head command**\n\e[0m"
  58. salt 'minion_*' cmd.run 'head /tmp/pillarfile_for*'
  59. fi
  60. fi
  61. else
  62. echo "Run this script as root (or with sudo)"
  63. fi