模块案例
ansible-doc -l | grep yum
ansible-doc yum =》查看具体模块手册,根据例子写任务
创建密钥:
ssh-keygen -t rsa -b 2048 -N ''
ssh-copy-id -i id_rsa.pub nodeX
给所有主机部署密钥
ansible all -m authorized_key -a "user=root exclusive=true manage_dir=true key='$(< /root/.ssh/id_rsa.pub)'" -k
验证是否成功
ansible all -m ping
查看除去注释和空行的内容
ansible es -m shell -a ' grep -Pv "^(#|$)" ' /etc/es/es.yml'
ansible es -m shell -a 'grep -Pnv "^\s*(#|$)" /etc/filebeat/filebeat.yml'
node.name: {{ansible_hostname}}
copy 模块打标签后,只执行标签模块
copy:
tags: confile
ansible-playbook xxx.yaml --list-tags #列出标签
ansible-playbook xxx.yml --tags=confile
网友评论