Ansible安装与配置

准备三台机器:
server.example.com
node1.example.com
node2.example.com
配置IP,主机名,/etc/hosts

主机server.example.com
[root@server ~]# hostnamectl set-hostname server.example.com
[root@server ~]# vim /etc/hosts
	添加:
        192.168.255.128 server.example.com
        192.168.255.129 node1.example.com
        192.168.255.130 node2.example.com

主机node1.example.com
[root@node1 ~]# hostnamectl set-hostname node1.example.com
[root@node1 ~]# vim /etc/hosts
	添加:
		192.168.255.129 node1.example.com
主机node2.example.com
[root@node2 ~]# hostnamectl set-hostname node2.example.com
[root@node2 ~]# vim /etc/hosts
	添加:
		192.168.255.130 node2.example.com

配置免密登录

[root@rhcsa ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:4L478U+nKiIdniujLwyZx/uwzc53BI/LfkmiS4P6ydU root@rhcsa
The key's randomart image is:
[root@rhcsa ~]# cd ~/.ssh/
[root@rhcsa .ssh]# ssh-copy-id root@node1.example.com

配置yum源使用Centos-stream.repo

将Centos-stream.repo文件上传到/etc/yum.repos.d/

安装ansible

yum install ansible -y

使用ansible --version去验证

[root@rhcsa yum.repos.d]# ansible --version

配置清单:/etc/ansible/hosts
[node]
node1.example.com
node2.example.com
使用ansible node -m ping去验证

[root@server .ssh]# ansible node1.example.com -m ping
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller 
starting with Ansible 2.12. Current version: 3.6.8 (default, Sep  9 2021, 07:49:02) 
[GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]. This feature will be removed from ansible-
core in version 2.12. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
/usr/local/lib/python3.6/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  from cryptography.exceptions import InvalidSignature
node1.example.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_59138290

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值