Common ansible Commands
Use Ansible-doc-l to see how specific modules are used, here are examples of common ansible simple usage Execution system commands
[Root@ansible ~]# ansible pinpoint-m shell-a ' hostname '-o # Execute system command
192.168.0.102 | SUCCESS | rc=0 | (stdout) pinpoint-agent
192.168.0.101 | SUCCESS | rc=0 | (stdout) Apm-pinpoint
File copy
[Root@ansible ~]# echo "Itdevops is useful" > devops.txt [root@ansible ~]# ansible pinpoint-m copy-a ' Src=devops.txt Dest=/root/devops.txt owner=root group=root mode=644 backup=yes '-O 192.168.0.102 | SUCCESS = {"Changed": True, "checksum": "59e127fdd346abcd4a2e348e44691600018d95d5", "dest": "/root/devops.txt", " GID ": 0," group ":" Root "," md5sum ":" 9ada44440028d3aa4582f7d5cfcbfe99 "," mode ":" 0644 "," owner ":" Root "," size ": +," src " : "/root/.ansible/tmp/ansible-tmp-1489047961.58-135666976081973/source", "state": "File", "UID": 0} 192.168.0.101 | SUCCESS = {"Changed": True, "checksum": "59e127fdd346abcd4a2e348e44691600018d95d5", "dest": "/root/devops.txt", " GID ": 0," group ":" Root "," md5sum ":" 9ada44440028d3aa4582f7d5cfcbfe99 "," mode ":" 0644 "," owner ":" Root "," size ": +," src " : "/root/.ansible/tmp/ansible-tmp-1489047961.6-141588290458447/source", "state": "File", "UID": 0} [Root@ansible ~]# Ansible pinpoint-m shell-a ' cat/root/devops.txt '-O 192.168.0.102 | SUCCESS | Rc=0 | (stdout) Itdevops is useful 192.168.0.101 | SUCCESS | rc=0 | (stdout) Itdevops is useful
Package Management
[Root@ansible ~]# ansible pinpoint-m yum-a ' Name=lrzsz state=latest '-o # Install package
192.168.0.101 | SUCCESS = {"Changed": false, "MSG": "", "RC": 0, "Results": ["all packages providing Lrzsz is up to date", "" "]}
1 92.168.0.102 | SUCCESS = {"Changed": false, "MSG": "", "RC": 0, "Results": ["all packages providing Lrzsz is up to date", "" "}
[ Root@ansible ~]# ansible pinpoint-m yum-a "Name=lrzsz state=present" # yum install lrzsz-y
[root@ansible ~]# an Sible pinpoint-m yum-a "Name=lrzsz state=absent" # Yum Erase lrzsz-y
User Management
[Root@ansible ~]# echo ansible | OpenSSL passwd-1-stdin # using OpenSSL to generate home encrypted passwords
$1$7nqb45m/$QhN 9dim77y5a.cryrhp.g/
[root@ansible ~]# ansible Pinpoint-m user-a ' Name=shaon password= "$1$7nqb45m/$QhN 9dim77y5a.cryrhp.g/" '-O