在使用vmware_vm_shell模块配置使用ansible的Linux虚拟机时成为su?

lvmkulzt  于 2023-03-07  发布在  Linux
关注(0)|答案(1)|浏览(128)

我有一个正在使用的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?

nzk0hqpo

nzk0hqpo1#

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

相关问题