Ansible基础——ansible基础用法

ansible 基本用法



 - ping #ping服务器是否能通
   如:ansible all -m ping
   
 - command #在远程主机上执行命令,并将结果返回本主机,hosts为定义的主机清单中的用户组
   如:ansible -i hosts test -m command -a "chdir=/home/wps ls"
   
 - shell  #shell命令
   如:ansible -i hosts test -m shell -a "whoami"
   
 - copy #复制文件到远程机器
   如:ansible hosts -m copy -a "src=/home/ansible/test.txt dest=/home/"
   
 - fetch #拉取远程机器文件
   如:ansible 192.168.1.1 -m fetch  -a "src=/home/test.sh dest=/home flat=yes" #flat=yes 指定路径目录进行保存
   
 - file #创建、修改、删除文件
   如:ansible hosts -m file -a "path=/home/file_dir/test.txt state=touch mode=0755 owner=root group=root"
   
 -  user #管理用户账号
    如:ansible hosts -m user -a "name=keer uid=11111"
    
 - cron #定时任务
    如:ansible hosts -m cron -a "name='crontab test' minute=5 hour=1 job='echo test'"
    
 - script #将本机的脚本在被管理端的机器上运行
   如:ansible hosts -m script -a 'df.sh'        
   
 - replace #将被管理主机/etc/hosts文件匹配关键字进行替换
      如:ansible -i pod.cfg all -m replace -a 'path=/etc/hosts regexp="#10.207.95.11 mirrors.bclinux.org" replace="10.207.95.11 mirrors.bclinux.org"'

 - hosts中k8s[0]中第一个ip
   如: ansible -i hosts k8s[0] -m ping

 

posted on 2024-05-08 20:35  gkhost  阅读(4)  评论(0编辑  收藏  举报

导航