#https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html
#shell 执行shell命令
ansible webservers -m shell -a "ls /tmp"
#sodo
#user用户登录之后 sodo root 提权
#注意配置user 具有sudo权限 vim /etc/sudoers
#user ALL=(ALL) ALL
ansible webservers -m shell -a "ls /tmp" -u user -k --become --become-user root -K
#copy 文件传输
src 本地路径 dest 目标主机路径
ansible webservers -m copy -a "src=/tmp/mysql-shell-8.0.18-linux-glibc2.12-x86-64bit.tar.gz dest=/tmp"
ansible webservers -m shell -a "ls /tmp"
#file
#state类型 file,directory,link,hard,touch,absent
#创建目录
ansible webservers -m file -a "dest=/tmp/abc mode=600 state=directory"
#创建文件
ansible webservers -m file -a "dest=/tmp/abc mode=600 state=touch"
#删除
ansible webservers -m file -a "dest=/tmp/abc mode=600 state=absent"
#yum 包管理
#absent,present,installed,removed,latest
ansible webservers -m yum -a "state=installed name=memcached"
#user 用户和组
ansible webservers -m user -a "name=foo password=123"
ansible webservers -m user -a "name=foo password=123 shell=/sbin/nologin"
ansible webservers -m user -a "name=foo state=absent"
#git 从源代码管理系统部署
ansible webservers -m git -a "repo=https://github.com/ansible/ansible.git dest=/tmp/ansible"
#service 服务管理
ansible webservers -m yum -a "state=installed name=memcached"
ansible webservers -m service -a "name=memcached state=started"
ansible webservers -m service -a "name=memcached state=restarted"
ansible webservers -m service -a "name=memcached state=stopped"
#开机启动
ansible webservers -m service -a "name=memcached enabled=true"
systemctl list-unit-files|grep enabled
#setup 手机目标主机信息
ansible webservers -m setup
ansible webservers -m setup -a "filter=ansible_nodename"
ansible webservers -m setup -a "filter=ansible_*_mb"
来源:CSDN
作者:取壳羊
链接:https://blog.csdn.net/java_w/article/details/103473618