V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
zunxiongchen
V2EX  ›  Linux

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

  •  
  •   zunxiongchen · Mar 26, 2021 · 2028 views
    This topic created in 1868 days ago, the information mentioned may be changed or developed.
    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 replies    2021-03-26 12:41:20 +08:00
    defunct9
        1
    defunct9  
       Mar 26, 2021
    直接用 test_user 执行不行么
    zunxiongchen
        2
    zunxiongchen  
    OP
       Mar 26, 2021
    @defunct9 感谢解答,也不是不可以,只是想区分下用户
    asilin
        3
    asilin  
       Mar 26, 2021   ❤️ 1
    生产环境一般都是为 ansible 专门创建一个只能密钥登陆、非交互式 SHELL 、具有完全 sudo 权限的用户
    defunct9
        4
    defunct9  
       Mar 26, 2021
    哦哦哦

    一、在 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  
       Mar 26, 2021 via Android
    namespace 走起?或者一步到位,docker 走起
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3768 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 04:50 · PVG 12:50 · LAX 21:50 · JFK 00:50
    ♥ Do have faith in what you're doing.