小编Sco*_*n21的帖子

使用 Ansible playbook 启用和禁用 root 登录

我是 Ansible 的新手,我正在尝试编写我的第一个 Ansible 剧本,以通过 ssh 两个远程 ubuntu 服务器启用 root 登录。

默认情况下,禁用以 root 身份 ssh 到两个远程 ubuntu 服务器的功能。为了通过 ssh 启用 root 登录,我通常这样做

#ssh to server01 as an admin user
ssh admin@server01

#set PermitRootLogin yes 
sudo vim /etc/ssh/sshd_config

# Restart the SSH server
service sshd restart
Run Code Online (Sandbox Code Playgroud)

现在我想通过 Ansible 剧本来做到这一点。

这是我的剧本

---
 - hosts: all
   gather_facts: no

   tasks:
   - name: Enable Root Login
     lineinfile:
           dest: /etc/ssh/sshd_config
           regexp: '^PermitRootLogin'
           line: "PermitRootLogin yes"
           state: present
           backup: yes
     notify:
       - restart ssh

   handlers:
   - name: …
Run Code Online (Sandbox Code Playgroud)

ansible ubuntu-18.04

8
推荐指数
1
解决办法
9513
查看次数

标签 统计

ansible ×1

ubuntu-18.04 ×1