Some code snippets I should remember for a while either for Python command line, or other CLI commands to use.
Last active
August 7, 2019 19:04
-
-
Save renoirb/6817704 to your computer and use it in GitHub Desktop.
Some Salt Stack Python tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
import keyword | |
array = """ | |
- ballmer | |
- torvalds | |
- gates | |
- timbl | |
""" | |
object = """ | |
ballmer: | |
first: Steve | |
last: Ballmer | |
type: Proprietarian | |
status: Retired | |
employer: !!null | |
torvalds: | |
first: Linus | |
last: Torvalds | |
type: Libertrarian | |
status: Active | |
employer: Google | |
gates: | |
first: Bill | |
last: Gates | |
type: Proprietarian | |
employer: Self employed | |
timbl: | |
first: Tim | |
last: Berners-lee | |
type: Libertrarian | |
status: Active | |
employer: W3C/MIT | |
""" | |
logstash = """ | |
logstash: | |
elasticsearch: | |
- memcache-test2 | |
brokers: | |
- app7 | |
shippers: | |
- app6 | |
confs: | |
- mysql_error | |
- mysql_slow | |
- nginx_default | |
- syslog | |
patterns: | |
- mysql_slow | |
""" | |
a = yaml.load(array) | |
o = yaml.load(object) | |
l = yaml.load(logstash) |
Salt and nova commands, booting typical VM
Boot new VM:
Some prebuilt images on OPS
nova boot --image 1236 --flavor 103 --key_name renoirb app6
nova boot --image 75845 --flavor 103 --key_name renoirb piwik-test
Configure new VM:
# Get public IP of new node
nova list
IPADDR='1.1.1.1'
ssh $IPADDR -l ubuntu
# In the new machine
wget -O - http://bootstrap.saltstack.org | sudo sh
sudo sh -c 'echo "10.5.240.3 deployment" >> /etc/hosts'
sudo sh -c 'echo "master: deployment" >> /etc/salt/minion'
sudo service salt-minion restart
Configure app* server:
salt 'app6*' state.highstate
salt 'app6*' state.sls code.node-app
salt 'app6*' state.sls code.node-bots
salt 'app6*' state.sls code.node-piwik
salt 'app6*' state.sls code.node-project
Salt; Getting state facts:
salt '*' grains.items
salt '*' pillar.items
salt 'app6*' grains.item id
Targeting either a node name, or using RegEx, or a Grain:
salt 'app*' state.highstate
salt 'db*' state.highstate
salt -E '(bots|code|storage|project|kuma).*' state.highstate
salt -G 'roles:app_server' state.highstate
Syncing pillars/grains or restarting a service:
salt '*test*' service.restart salt-minion
salt '*test*' saltutil.sync_all
Broadcast a message
NOTE: Not finished yet, needs to test more
from an other node than the main. Must have peer:
properly enabled.
salt-call 'publish.publish' 'role:logstash.elasticsearch' 'grains.item' 'id' 'grain'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Salt Stack console | |
""" | |
import salt | |
import salt.loader | |
import salt.config | |
client = salt.client.LocalClient() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment