######实验环境设置######
设置ansible主机网段为39网段ip为172.25.39.39(设置主机网桥时关闭虚拟机否则无法成功)
新建3台受控主机设置网络为39网段ip分别为172.25.39.10 ;20 ; 30
ansible主机建立用户devops
devops用户下cd ansible
ssh-keygen生成密钥
for i in 10 20 30
> do
> ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.25.39.$i
> done
openssl passwd -6 生成密钥
ansible all -m user -a 'name=devops state=present password=”密钥“' u root
for i in 10 20 30;do ssh-copy-id -i ~/.ssh/id_rsa.pub devops@172.25.39.$i; done
ansible all -m inventory -a ‘path=/etc/sudoers line="devops ALL=(ALL) NOPASSWD: ALL"’ -u root
ansible all -m ping 检测
##一.循环##
#循环迭代任务#
#1.简单循环#
loop: ##赋值列表
- value1
- value2
- ...
{ {item}} ##迭代变量名称
#实例#
---
- name: create file
hosts: all
tasks:
- name: file module
file:
name: /mnt/{
{item}}
state: touc
loop:
- westos_file1
- westos_file2
#2.循环散列或字典列表#
---
- name: create file
hosts: all
tasks:
- name: file module