码迷,mamicode.com
首页 > 其他好文 > 详细

Ansible 安装和配置

时间:2017-08-08 12:35:54      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:ansible

We start with installing Ansible using root.


step 1 - run "yum install ansible" to install it on one machine with CenOS 7;

step 2 - configuring ansible hosts

Open the file /etc/ansible/hosts, in this file, add:

[servers]
host1 ansible_ssh_host=user_name@server_ip
host2 ansible_ssh_host=user_name@server_ip

We test ansible to connect to host1 and host2 using command:

ansible -m ping all

However, it failed and presented the error:

host1 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n",
    "unreachable": true
}

We addressed this problem by generating private and public keys on this server, and copying the public key to the server that ansible attempted to connect.

On local computer, generate a SSH key pair by the following command:

ssh-keygen

The key pair will be created within ~/.ssh directory.

The password can be neglected.

To copy the public key to the server, typing 

ssh-copy-id username@remote_host

To test the ssh connection, run

ssh username@remote_host

After SSH key authentication is established, we come back to ansible and run

ansible -m ping all

Now we can see that

host1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

Reference

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-centos-7


本文出自 “胡一刀” 博客,谢绝转载!

Ansible 安装和配置

标签:ansible

原文地址:http://11190017.blog.51cto.com/11180017/1954330

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!