首页 > 其他 > 详细

Ansible 安装和配置

时间:2017-08-08 12:14:24      阅读:416      评论:0      收藏:0      [点我收藏+]

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 安装和配置

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!