test
练习答案
练习: 在master上配置好所有的yum源,然后拷贝到group1的远程机器上(要求目录内的内容完全一致)
master# ansible group1 -m file -a "path=/etc/yum.repos.d/ state=absent"
master# ansible group1 -m copy -a "src=/etc/yum.repos.d dest=/etc/"
练习: 使用hostname模块修改过主机名后.在master上修改/etc/hosts文件,并拷贝到group1的远程机器上
修改/etc/hosts文件后,再执行下面这一句
master# ansible group1 -m copy -a 'src=/etc/hosts dest=/etc/hosts'
练习: 在group1的客户端的mariadb里创建一个abc库
远程操作mysql需要MySQL-python包的支持
master# ansible group1 -m yum -a "name=mariadb-server,MySQL-python state=present"
master# ansible group1 -m service -a "name=mariadb state=started enabled=yes"
master# ansible group1 -m mysql_db -a "login_port=3306 login_user=root name=abc state=present"
练习:
假设我主机清单里定义的group1里有多台机器,它们现在要做一个集群。此集群要求实现一个名为hadoop的普通用户之间的两两免密登录,如何实现(要求只在master上进行操作)?
[root@master ~]# ansible group1 -m user -a 'name=hadoop generate_ssh_key=yes'
[root@master ~]# ansible group1 -m fetch -a 'src=/home/hadoop/.ssh/id_rsa.pub dest=/tmp'
[root@master ~]# cat /tmp/10.1.1.12/home/hadoop/.ssh/id_rsa.pub /tmp/10.1.1.13/home/hadoop/.ssh/id_rsa.pub >> authorized_keys
[root@master ~]# ansible group1 -m copy -a "src=/tmp/authorized_keys dest=/home/hadoop/.ssh/"
[root@master ~]# useradd hadoop
[root@master ~]# su - hadoop
在master上把所有的group1组里的机器都ssh连接一遍,主要目的就是输入一次yes,把相应信息保存到/home/hadoop/.ssh/known_hosts里
[root@master ~]# su - hadoop
for i in {1..10}
do
ssh 10.1.1.$i -o StrictHostKeyChecking=no date &> /dev/null
done
[root@hadoop ~]# exit
[root@master ~]# ansible group1 -m copy -a "src=/home/hadoop/.ssh/known_hosts dest=/home/hadoop/.ssh/known_hosts"
new