Ansible模块

主机清单

	**1.增加主机组** 
		vi /etc/ansible/hosts==>[webserver] host1 host2 host3.....
	**2.增加用户名 密码**
		vi /etc/ansible/hosts==>[webserver] host[1:n] ansible_ssh_user='账号' ansible_ssh_pass='密码'
	**3.增加端口**
		vi /etc/ansible/hosts==>[webserver] host1 ansible_ssh_port='端口号'
	
	
	**4 .组:变量**
		vi /etc/ansible/hosts==>[webserver] host[1:4] [webserver:vars]ansible_ssh_user='账号'
	ansible_ssh_pass='密码'
	**5.子分组**
	vi /etc/ansible/hosts==>	[apache]
				host[1:2]
				[nginx]
				host[3:4]
				[webserver:children]
				apache
				nginx
				[webserver:vars]
				ansible_ssh_user='root'
		ansible_ssh_pass='666666'
	**6.自定义主机列表**
		vim hostlist
		[dockers]
		host1
		host2
		[dockers:vars]
		ansible_ssh_user='账号'
		ansible_ssh_pass='密码'	
		ansible -i  hostlist dockers  -m ping  -o

Ad-Hoc-点对点模式

	**1.shell模块**
	     *帮助:ansible-doc shell*
		ansible webserver -m shell -a 'hostname' -o	获取主机名
		ansible webserver -m shell -a 'hostname' -o -f 2	-f 2指定线程数
		ansible host2 -m shell -a 'yum -y install httpd' -o	部署apache
		ansible host3 -m shell -a 'uptime' -o		查询系统负载
	**2.复制模块**
	     *帮助:ansible-doc copy*
		ansible webserver -m copy -a 'src=/etc/hosts dest=/tmp/2.txt owner=root group=bin mode=777'
	**3.用户模块**
	     *帮助:ansible-doc user*
		ansible webserver -m user -a 'name=qianfeng state=present'
	**4.软件包管理**
	     *帮助:ansible-doc yum*
		ansible host2 -m yum -a 'name="httpd" state=latest'
	**5.服务模块**
	     *帮助: ansible-doc service*
		ansible host2 -m service -a 'name=httpd state=started'
	**6.文件模块**
	     *帮助:ansible-doc file*
		ansible host1 -m file -a 'path=/tmp/88.txt mode=777 state=touch'
	**7.收集模块**
	     *帮助:ansible-doc setup*
		ansible host3 -m setup -a 'filter=ansible_all_ipv4_addresses'
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值