V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
zunxiongchen
V2EX  ›  Linux

Ansible playbook become 模块一定要配置 sudoers 为 ALL 吗?

  •  
  •   zunxiongchen · 2021-03-26 10:45:07 +08:00 · 1336 次点击
    这是一个创建于 1127 天前的主题,其中的信息可能已经有所发展或是发生改变。
    ansible playbook

    - hosts: backend_host
    remote_user: ansible_user
    gather_facts: no
    become: yes
    become_method: sudo
    become_user: test_user

    目前配置的 sudo nopasswd 是 all
    ansible_user ALL=(ALL) NOPASSWD:ALL

    感觉 ALL 给的权限太大,想要让 ansible 用户只能单单 sudo 到 test_user,像下边这样。不知道可否实现,有大佬懂吗?
    ansible_user ALL=(ALL) NOPASSWD:/bin/su - test_user
    5 条回复    2021-03-26 12:41:20 +08:00
    defunct9
        1
    defunct9  
       2021-03-26 10:49:08 +08:00
    直接用 test_user 执行不行么
    zunxiongchen
        2
    zunxiongchen  
    OP
       2021-03-26 11:01:01 +08:00
    @defunct9 感谢解答,也不是不可以,只是想区分下用户
    asilin
        3
    asilin  
       2021-03-26 11:08:55 +08:00   ❤️ 1
    生产环境一般都是为 ansible 专门创建一个只能密钥登陆、非交互式 SHELL 、具有完全 sudo 权限的用户
    defunct9
        4
    defunct9  
       2021-03-26 11:58:43 +08:00
    哦哦哦

    一、在 ansible 配置文件里,ansible.cfg 配
    [privilege_escalation]
    become_exe=’sudo su -‘

    或者干脆环境变量里指出 ANSIBLE_BECOME_EXE=’sudo su -‘

    二、再使用 become
    remote_user: remote-user
    become: yes
    become_user: informatica-user
    become_method: su
    lechain
        5
    lechain  
       2021-03-26 12:41:20 +08:00 via Android
    namespace 走起?或者一步到位,docker 走起
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   893 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 21:49 · PVG 05:49 · LAX 14:49 · JFK 17:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.