一、ansible优化
vim /etc/ansible/ansible.cfg host_key_checking = False #不进行验证 log_path = /var/log/ansible.log #打开日志
基于ssh
vim /etc/ssh/sshd_config UseDNS no #重启sshd # systemctl restart sshd
二、常用模块
1、coyp 模块
ansible date -m copy -a 'src=/etc/selinux/config dest=/etc/selinux/confi
2、fetch模块 从客户端取文件
ansible date -m fetch -a "src=/var/log/cron dest=/data/"
3、shell模块(执行命令、或者执行远程脚本)、也这样代替file模块
ansible date -m shell -a 'cat /etc/selinux/config'
4、script模块(远程不需要有脚本,控制端有可以)
ansible date -m script -a "/root/scripts/test.sh" [root@linux-node1 scripts]# cat /root/scripts/test.sh #!/bin/bash hostname
三、角色下载
官网地址: https://galaxy.ansible.com/
下载角色(下载下来直接拷贝一份,自己使用也可以) ansible-galaxy install geerlingguy.nginx - downloading role 'nginx', owned by geerlingguy - downloading role from https://github.com/geerlingguy/ansible-role-nginx/archive/2.7.0.tar.gz - extracting geerlingguy.nginx to /root/.ansible/roles/geerlingguy.nginx - geerlingguy.nginx (2.7.0) was installed successfully #查看有那些角色 [root@linux-node1 roles]# ansible-galaxy list # /root/.ansible/roles - geerlingguy.nginx, 2.7.0 # /usr/share/ansible/roles # /etc/ansible/roles #删除(或者直接删除目录) [root@linux-node1 roles]# ansible-galaxy remove geerlingguy.nginx/ - successfully removed geerlingguy.nginx/