ansible的简单使用练习
在上一次博客,我们成功的搭建了ansible的部署,现在基于上一次博客,做一些简单练习检验,搭建是否成功。
以all主机组为目标执行id命令
1、首先在master主机下,切换到class用户,并新建目录zuoye1。
2、在此目录下,新建ansible配置文件并编辑相应配置。
[class@master zuoye1]$ vim ansible.cfg
配置如下:
[defaults]
inventory = ./inventory
remote_user = student
ask_pass = False
[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False
3、再新建inventory文件,编辑受控节点有哪些。
[class@master zuoye1]$ vim inventory
配置内容如下:
[class@master zuoye1]$ cat inventory
node12
node13
4、测试:
[class@master zuoye1]$ ansible all -m command -a id
结果如下:
2、使用copy模块修改所有主机上的/etc/motd文件内容为welcome to ansible
命令:ansible all -m copy -a 'content="welcome to ansible" dest=/etc/motd'
3、使用command模块查看/etc/motd文件的内容
命令: ansible all -m command -a 'cat /etc/motd'
4、使用user模块创建用户xiaoming,uid为2000
命令:ansible all -m user -a 'name=xiaoming uid=2000 state=present'