mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4
256 字
1 分钟
运行 Ansible 的前期准备
2026-04-07

运行ansible的前期准备#

安装三台虚拟机#

我们选择open euler

在VMware Workstation Pro 安装一台虚拟机

安装教程

第二台完整克隆

第三台链接克隆

配置固化三台虚拟机的网络#

发现固化网络时使用vim编辑固化失败推荐使用nmcli进行固化

使用nmcli命令进行固化网络

先规划三台虚拟机的IP地址

分别为

  1. 192.168.177.129
  2. 192.168.177.130
  3. 192.168.177.131

开始进行网络固化

#首先查看网卡名字
[example@example01 ansible]$ nmcli connection show
NAME UUID TYPE DEVICE
ens33 c73e89a6-5104-4b44-a476-63589c85c332 ethernet ens33
lo bd380bce-eade-45f0-badd-e49172d16314 loopback lo
#看到网卡名字为 ens33,分别更改ip,网关,dns,切换为静态IP
[example@example01 ansible]$ nmcli connection modify ens33 \
ipv4.addresses 192.168.177.129/24
nmcli connection modify ens33 \
ipv4.gateway 192.168.177.2
nmcli connection modify ens33 \
ipv4.dns 114.114.114.114
nmcli connection modify ens33 \
ipv4.method manual
#重启网卡
[example@example01 ansible]$ nmcli connection down ens33 && nmcli connection up ens33
#查看是否固化成功
[example@example01 ansible]$ nmcli connection show ens33 | grep ipv4.method
#成功
[root@example01 ansible]# nmcli connection show ens33 | grep ipv4.method
ipv4.method: manual
#查看详细配置
root@example01 ansible]# nmcli connection show ens33 | grep ipv4
ipv4.method: manual
ipv4.dns: 114.114.114.114
ipv4.dns-search: --
ipv4.dns-options: --
ipv4.dns-priority: 0
ipv4.addresses: 192.168.177.129/24
ipv4.gateway: 192.168.177.2
ipv4.routes: --
ipv4.route-metric: -1
ipv4.route-table: 0 (unspec)
ipv4.routing-rules: --
ipv4.replace-local-rule: -1(default)
ipv4.ignore-auto-routes:
ipv4.ignore-auto-dns:
ipv4.dhcp-client-id: --
ipv4.dhcp-iaid: --
ipv4.dhcp-timeout: 0 (default)
ipv4.dhcp-send-hostname:
ipv4.dhcp-hostname: --
ipv4.dhcp-fqdn: --
ipv4.dhcp-hostname-flags: 0x0(none)
ipv4.never-default:
ipv4.may-fail:
ipv4.required-timeout: -1 (default)
ipv4.dad-timeout: -1 (default)
ipv4.dhcp-vendor-class-identifier: --
ipv4.link-local: 0(default)
ipv4.dhcp-reject-servers: --
ipv4.auto-route-ext-gw: -1(default)

为三台虚拟机创建用户修改主机名#

修改主机名

#修改主机名为你的姓名简拼+01/02/03
[root@example01 /]# hostnamectl set-hostname example01

创建用户

#在三台虚拟机上创建三同名用户
[root@example01 /]# useradd example
[root@example01 /]# passwd example

为创建的用户提权#

在/etc/sudores 中使用vim提权

[root@example01 /]# visudo /etc/sudoers
Defaults secure_path = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
example ALL=(ALL) NOPASSWD: ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d

检验提权是否成功#

[example@example01 /]$ sudo cat /etc/shadow
root:$y$j9T$1urtbduE.3TtjoQ9tiKnSmTY$gv.ivHasgflb/6czuPgxHRC6nSZTtrFUXtO5BFm7tu2::0:99999:7:::
bin:*:20443:0:99999:7:::
daemon:*:20443:0:99999:7:::
adm:*:20443:0:99999:7:::
lp:*:20443:0:99999:7:::
sync:*:20443:0:99999:7:::
shutdown:*:20443:0:99999:7:::
halt:*:20443:0:99999:7:::
mail:*:20443:0:99999:7:::
operator:*:20443:0:99999:7:::
games:*:20443:0:99999:7:::
ftp:*:20443:0:99999:7:::
nobody:*:20443:0:99999:7:::
systemd-coredump:!:20526::::::
dbus:!:20526::::::
polkitd:!:20526::::::
saslauth:!:20526::::::
dhcpd:!:20526::::::
sshd:!:20526::::::
tss:!:20526::::::
unbound:!:20526::::::
chrony:!:20526::::::
example:$6$WkwUiZDosTU45NRX$MLpLOdKC.qC0lFAOS9aXIcdX3Te8.GQ/NTC7TtiRrOi0YPQjKvHn2hX.p2KZavbE5sVKBOePukiKvhiLLJkiq0:20532:0:99999:7:::
qq:!:20532:0:99999:7:::

提权成功example 用户可以不输入用户密码进行root操作

免密登录#

首先三台虚拟机在/etc/hosts 中修改目标IP的主机名做一个本地DNS

[root@example01 /]# vim /etc/hosts
# Loopback entries; do not change.
# For historical reasons, localhost precedes localhost.localdomain:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# See hosts(5) for proper format and other examples:
# 192.168.1.10 foo.example.org foo
# 192.168.1.13 bar.example.org bar
192.168.177.129 example01
192.168.177.130 example02
192.168.177.131 example03

开始生成SSH证书密钥

[root@example01 /]# ssh-keygen -t rsa
[root@example01 /]# ssh-copy-id example@example01
[root@example01 /]# ssh example@openeuler01

可以免密登录

检查网络仓库#

[root@example01 /]# dnf repolist all
repo id repo name status
EPOL EPOL enabled
OS OS enabled
debuginfo debuginfo enabled
everything everything enabled
source source enabled
update update enabled
update-source

前期准备完成,下一步安装ansible

分享

如果这篇文章对你有帮助,欢迎分享给更多人!

运行 Ansible 的前期准备
https://liangkazesblog.edgeone-pages.com/posts/anisble/0/0运行ansible的前期准备/
作者
liangkaze
发布于
2026-04-07
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

随机文章 随机推荐
暂无数据

目录