Write more chaotic, the context is not good understanding, only for their own retention use.
A Python-paramiko
Python.. /ssh.py hosts_vertical_new cmd root
Python.. /sftp.py-p hosts_vertical_new Root/root/python/audit/audit.rules/etc/audit/audit.rules
Python.. /sftp.py-p hosts_vertical_new root/root/python/audit/auditd.conf/etc/audit/auditd.conf
Python.. /sftp.py-p hosts_vertical_new root/root/python/audit/audit.tar/opt/
Python.. /ssh.py hosts_vertical_new Cmd_tarx_bash Root
Python.. /sftp.py-g hosts_vertical_new Root/opt/audit/audit-check.log./result/
[Email protected] sudo]# python/root/python/ssh.py hosts.hiv01 cmd_hive Root
Password:
Scchdphiv02101
SCCHDPHIV02101
[Email protected] sudo]# python/root/python/ssh.py hosts_hive cmd_chpasswdomm Root
Password:
scchdphiv02124
Changing password for user oMM.
Passwd:all authentication tokens updated successfully.
Adjusting aging data for user oMM.
Passwd:success
Two ansible
Yum Install Ansible
[[Email Protected]:/root/python] #ansible all-i host_stormtag--list-hosts from text Host_stromtag list machine information
[[Email Protected]:/root/python] #ansible all-i host_stormtag-m shell-a "hostname"-k-u adminzhy--default is root user
[[Email Protected]:/root/python] #ansible all-i host_stormtag-m command-a "WhoAmI"-k-u adminzhy--default is root user
Ansible hadoopservers-m shell-a ' touch a '-k-u adminzhy-k-S #使用adminzhy执行sudo touch a file a,hadoopservers is/etc/ansibl A server group in the E/hosts
Ansible all-i host_stormtag-m command-a "WhoAmI"-k-u Adminzhy #host_stormtag is a standalone host file that is not in/etc/ansible/hosts
Ansible all-i host_tagsvr-m shell-a "df-h"-k-u adminzhy-k-S #host_stormtag is a standalone host file that is not in/etc/ansible/hosts
1.vim/etc/ansible/ansible.cfg
2. Host group definition
Vim/etc/ansible/hosts
[Storm_cluster]
10.223.55.100
10.223.55.101
3 Copying files to a remote machine
Backup: Before overwriting, the source file is backed up, and the backup file contains the time information. There are two options: Yes|no
Content: Used instead of "src", you can set the value of the specified file directly
Dest: Required option. The absolute path of the remote host to which the source file is to be copied, and if the source file is a directory, the path must also be a directory
Directory_mode: Recursively set permissions for the directory, default to system default permissions
Force: If the target host contains the file, but the content is different, if set to Yes, the override is enforced, and if no, the file is copied only if the target location for the destination host does not exist. The default is Yes
Others: All the options in the file module can be used here
SRC: A local file that is copied to the remote host, either an absolute path or a relative path. If the path is a directory, it will be replicated recursively. In this case, if the path ends with "/", only the contents of the directory are copied, and if "/" is not used to end, the entire content, including the directory, is copied, similar to rsync.
Example
# # Copy the local file "/etc/ansible/ansible.cfg" to the remote server
# ansible storm_cluster-m copy-a "src=/etc/ansible/ansible.cfg dest=/tmp/ansible.cfg owner=root group=root mode=0644"
4 Remote Execute shell script
# ansible storm_cluster-m shell-a "/tmp/rocketzhang_test.sh"
Building trust:
Ansible all-m copy-a "Src=/root/.ssh/id_rsa.pub dest=/root"-K
Ansible all-m shell-a "cat/root/id_rsa.pub >>/root/.ssh/authorized_keys"
Ansible all-m shell-a "Rm-f/root/id_rsa.pub"
Istory |grep-a 3-b 3 ansible
The application of Python in automated operations