Saltstack in-depth-management Python-pip
Operating content: First, the basic Environment 1, using Tvm-saltmaster operation 2, Network: eth0:host-only (for virtual intranet, manually fixed IP, so from the host can directly connect to this VM) Eth1:nat (for Sisu network, dynamic IP) [email protected] ~]# cd /etc/sysconfig/network-scripts/[[email protected] network-scripts]# cat ifcfg-eth0device=eth0type=ethernetonboot=yesnm_controlled=yesbootproto= noneipaddr=192.168.56.253prefix=24gateway=192.168.56.1dns1=192.168.56.254[[email protected] network-scripts]# cat ifcfg-eth1device=eth1type=ethernetonboot=yesnm_controlled=yesbootproto= dhcpdns1=192.168.56.254 ii. configuration 1, file structure [[Email protected] base]# tree ops/ops/└── bin.sls0 directories, 1 file[[email protected] base]# tree conf.d/ops/conf.d/ops/ └── bin ├── pw ├── randchars.py └── sendemail1 directory, 3 files2, SLS configuration [[Email protected] base]# cat ops/bin.sls ## the required packages are listed here #python-pip: pkg.installed: - name: python-pip - require_in: -file: pip-pkgspip-pkgs: pip.installed: - names: - virtualenvwrapper - pwgen/usr/bin/sendEmail: file.managed: -&NBSP;SOURCE:&NBSP;SALT://CONF.D/OPS/BIN/SENDEMAIL&NBSP;&NBSP;&NBSP;&NBSP;-&NBSP;MODE:&NBSP;755/USR/BIN/PW: file.managed: - source: salt://conf.d/ops/bin/pw - mode: 755/usr/bin/randchars: file.managed: - source: salt://conf.d/ops/bin/randchars.py - mode: 755 implementation of [[email protected] base]# salt ' tvm-* ' state.sls ops.bin test=true[[email protected] base]# salt ' tvm-* ' state.sls ops.bin added to Top.sls [email protected] base]# cat top.sls base: ' Tvm-yum ': - dnsmasq - crontab - web ' Tvm-zabbix ': - mysql.server - zabbix.server - zabbix.web ' * ': - abc - monit - postfix - salt.minion - ssh - vim - zabbix.agent - ops.bin four, summed up here used to: pip.installed use, you need to ensure that the installation of PYTHON-PIP this package, otherwise it will prompt the exception. and PIP installation package, the corresponding host can be connected to the external network, if there is no network, the following error:---------- id: pip-pkgs function: pip.installed name: virtualenvwrapper Result: False Comment: Failed to install packages: virtualenvwrapper. error: collecting virtualenvwrapper Retrying (Retry (total=4, connect=none, read=none, redirect=none)) after connection broken by ' ProtocolError (' connection aborted. ', error (101, ' Network is unreachable ')) ': /simple/virtualenvwrapper/ Retrying (Retry (total=3, connect=none, read= None, redirect=none)) after connection broken by ' ProtocolError (' connection aborted. ', error (101, ' network is unreachable ') ': /simple/virtualenvwrapper/ retrying (Retry (total=2, connect= None, read=none, redirect=none)) after connection broken by ' ProtocolError ( ' Connection aborted ', error (101, ' network is unreachable ') ': /simple/ virtualenvwrapper/ Retrying (Retry (total=1, connect=none, read=none, redirect=none)) after connection broken by ' ProtocolError (' connection aborted. ', error (101, ' Network is unreachable ')) ': /simple/virtualenvwrapper/ Retrying (Retry (total=0, connect=none, read= None, redirect=none)) after connection broken by ' ProtocolError (' connection aborted. ', error (101,&NBSP; ' Network is unreachable ')) ': /simple/virtualenvwrapper/ Retrying (Retry (Total=4, connect=none, read=none, redirect=none)) after connection broken by ' ProtocolError (' connection aborted. ', error (101, ' network is unreachable ') ': /simple/ virtualenvwrapper/ Retrying (Retry (total=3, connect=none, read=none, redirect=none)) after connection broken by ' ProtocolError (' connection aborted. ', error (101, ' Network is unreachable ')) ': /simple/virtualenvwrapper/ Retrying (Retry (total=2, connect=none, read= None, redirect=none)) after connection broken by ' ProtocolError (' connection aborted. ', error (101, ') Network is unreachable ')) ': /simple/virtualenvwrapper/ Retrying (Retry (Total=1, connect=none, read=none, redirect=none)) after connection broken by ' ProtocolError (' connection aborted. ', error (101, ' network is unreachable ') ': /simple/ virtualenvwrapper/ Retrying (Retry (total=0, connect=none, read=none, redirect=none)) after connection broken by ' ProtocolError (' connection aborted. ', error (101, ' Network is unreachable ')) ': /simple/virtualenvwrapper/ could not find a version that satisfies the requirement virtualenvwrapper (from versions: ) No matching distribution found for virtualenvwrapper started: 16:30:04.360978 duration: 15536.139 ms Changes: ----------Five, attach a few gadgets to the usage 1, disorderly output character pw a small script written by someone else, This tool is called PIP-installed Pwgen [[email protected] ~]# cat /usr/bin/pw#!/usr/bin/python## 2015/8/ 14IMPORT&NBSP;OSIMPORT&NBSP;SYSDEF&NBSP;GEN_PW (): # yum -y install python-pip# pip install pwgen p = os.popen ('/usr/bin/pwgen -1 -b -n 10 ') p = p.read (). strip (' \ n ') p = p[:5 ].upper () + p[5:].lower () return pdef print_msg (): p1 = GEN_PW () &NBSP;&NBSP;&NBSP;&NBSP;P2&NBSP;=&NBSP;GEN_PW () #msg = ' root:{0} root1:{1} '. Format (P1,P2) msg = ' {0} {1} '. Format (P1,P2) print msgif __name__ == ' __main__ ': print_msg () 2, Out-of-sequence output character randchar writes a small script of its own, generating some simple characters [[email protected] ~]# cat /usr/bin/randchars #!/bin/env python# # 2015/08/10import randomclass randchars (object): " randchars" Generate () " # char pools pools = ' 23456789 ' pools += ' abcdefghijkmnpqrstuvwxyz ' pools += ' abcdefghijkmnpqrstuvwxyz ' pools += ' [email protected]#$%^&* () _+ ' # pool size pool_size = len (pools) def __ Init__ (self, length=12): self.length = length # get a char from pool def fetch_ One (self): rnd_index = random.randint (0, SELF.POOL_SIZE-1) return self.pools[rnd_index] # map the password by index def generate (self ): rnd_chars = ' i = 0 while i < Self.length: &nBsp; rnd_chars += self.fetch_one () i += 1 return rnd_charsif __name__ == ' __main__ ': try: while True: print (' [-] [press ' CTRL + C ' to cancel], default=24: ') length = raw_input (' Length to generate: ') # python3 #length = input (' length: ') if not length : length = ' if length.isdigit (): print (' \n\n{0}\n\n '. Format (RandChars (int ( Length)). Generate ())) else: print (' \n[WARNING] hi , length is digit.\n ') except KeyboardInterrupt: print (' \n\n[notice] you cancelled the operation.\n ') except exception as err: print (' \n[error]: {0}\n '. Format (ERR)) 3, SendEmail scripts written by others [[email protected]&nbSp;~]# sendemail -s smtp.company.com -xu [email protected] -xp mail_ password -f [email protected] -t [email protected] -u ' Msg title ' -m ' Msg body ' -a /tmp/attachment.txt aug 14 17:00:10 tvm-test sendemail[6319]: email was sent successfully! Zyxw, reference 1, official website Dochttp://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.pip.html#module-salt.modules.pip
Saltstack in-depth-management Python-pip