Ansible简单安装

系统centos7.3linux

ip地址192.168.1.10nginx

[安装ansible]centos

yum install epel-release -yssh

yum install ansible -yide


           [SSH部分]centos7


#配置ssh免密码登录,如果用普通用户请在普通用户下建立SSH密钥.且ssh统一使用一个帐号.日志

ssh-keygen -t rsa  默认下一步便可.ip

#复制密钥到须要ssh的机器.rem

ssh-copy-id -i #默认会把密钥放入对端机器的/root/.ssh/authorized_keysit

ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.1.11: 


             [Ansible配置部分]

1.[默认以下]

[root@centos7 ~] ll /etc/ansible

total 24

-rw-r--r--. 1 root root 18064 Jun 26 07:28 ansible.cfg  主配置文件

-rw-r--r--. 1 root root  1038 Jun 26 07:09 hosts        存放远程主机配置

drwxr-xr-x. 2 root root     6 Jun  2 05:49 roles        roles目录


2.[修改主配置文件]

[root@centos7 ~]# grep -v "#\|^$" /etc/ansible/ansible.cfg

[defaults]

inventory      = /etc/ansible/hosts  #主机文件

remote_tmp     = ~/.ansible/tmp

local_tmp      = ~/.ansible/tmp

ask_sudo_pass = True  #开启是否用sudo密码

ask_pass      = True  #开启这个每次操做须要ssh密码如果免密码则取消

remote_port    = 22

timeout = 10

log_path = /var/log/ansible.log  #存放日志文件


3.[添加客户端(节点)]----ip:192.168.1.11

[root@centos7 ~] grep "linux\|192.168.1.11" /etc/ansible/hosts 

      [linux]       组名

 192.168.1.11  组下节点IP


4.[Ansible简单操做]


#-----ansible linux -m yum -a 'name=nginx'

#-----linux也能够直接ip地址

-m 模块

-a 须要的指令

ansible-doc -l 列出全部的模块

相关文章
相关标签/搜索