linux - 使用vmware_vm_shell模块使用ansible配置Linux VM时变成su?

标签 linux ansible vmware

我有一个可用的 ansible 剧本,它使用 vmware_vm_shell module将网络配置命令推送到在 VMware 中运行的 Linux VM。仅当我使用 vm_username 作为'root'时,这才有效。我想使用“root”以外的其他用户并成为“su”来运行网络配置 cli 命令。请参阅下面的工作 ansible 剧本:

  - name: Edit Network Interfaces for VM
    vmware_vm_shell:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: "{{ vcenter_validate_certs }}"
        datacenter: "{{ vcenter_datacenter }}"
        folder: "{{ vcenter_destination_folder }}"
        vm_id: VM-Test
        vm_username: root
        vm_password: "{{ vm-password }}"
        vm_shell: "/bin/nmcli"
        vm_shell_args: "{{ item }}"
    with_items:
    - "con mod ens192 ipv4.address '{{ vmintip }}'"
    - "con mod ens192 ipv4.gateway '{{ intup }}'"
    - "con mod ens192 ipv4.dns '{{ dnsip }}'"
    - "con mod ens192 ipv4.method manual"
    - "con mod ens192 ipv6.method disabled"
    - "con up ens192"
    - "con mod 'Wired connection 1' ipv4.address '{{ vmmgip}}'"
    - "con mod 'Wired connection 1' ipv4.gateway '{{ mgup }}'"
    - "con mod 'Wired connection 1' ipv4.dns '{{ dnsip }}'"
    - "con mod 'Wired connection 1' ipv4.method manual"
    - "con mod 'Wired connection 1' ipv6.method disabled"
    - "con up 'Wired connection 1'"

当使用不同的用户名时,我失败了,它无法发出这些命令,因为我需要拥有root权限(我需要使用不同的用户名成为su)。当使用不同的用户和 vmware_vm_shell 模块时,有没有办法变成 su ?

最佳答案

将评论变成答案:

如果允许用户在没有额外密码的情况下执行这些 sudo 命令,您应该能够将 vm_shell: "/bin/nmcli" 替换为 vm_shell: "/path/to/sudo" (对我来说是/usr/bin/sudo 并将网络管理器添加到参数vm_shell_args: "/bin/nmcli {{ item }}"

关于linux - 使用vmware_vm_shell模块使用ansible配置Linux VM时变成su?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75595841/

相关文章:

python - scapy 的时间戳精度更高

http - 如何在 PowerShell 中向 VMware ESX Server 执行 HTTP PUT 上传?

django - 如何设置 uWSGI vassal 名称以获得更好的日志引用?

linux - X 窗口转发?

ansible - 使用 with_fileglob 循环

ansible - 我可以根据 ansible 详细级别将 ansible no_log 设置为默认值吗?

rest - VCenter:REST API:如何将 ova 上传到内容库

linux - 如何录制从扬声器发出的声音(而不是进入麦克风的声音)?

linux - 在 Linux 中模拟/模拟 iOS

Ansible 任务因 when 条件而失败