【问题标题】:ansible change to zimbra user and run zimbra servicesansible 更改 zimbra 用户并运行 zimbra 服务
【发布时间】:2021-09-13 05:25:38
【问题描述】:

我正在尝试运行执行 ansible 任务。 首先使用root登录服务器 将用户更改为 zimbra 用户 检查 zimbra 状态

当前配置

ansible.cfg

[defaults]
inventory=/home/admin/ansible/inventory
become= yes
become_method=su
remote_user=root
remote_tmp=/tmp/zimbraansible
allow_world_readable_tmpfiles=true

库存

[mail]
192.168.122.30
zimbra_playbook.yml 
- name: Restarting Zimbra Services
  hosts: mail 
  become: yes
  tasks:
    - name: Restart Zimbra service
      become: su
      become_user: zimbra
    - name: Display zimbra Status
      command: zmcontrol status

以下错误运行 -vvvv

完整的回溯是:

WARNING: The below traceback may *not* be related to the actual failure.
  File "/tmp/ansible_command_payload_Fl8ThR/ansible_command_payload.zip/ansible/module_utils/basic.py", line 2652, in run_command
    cmd = subprocess.Popen(args, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception

fatal: [192.168.122.30]: FAILED! => {
    "changed": false,
    "cmd": "zmcontrol status",
    "invocation": {
        "module_args": {
            "_raw_params": "zmcontrol status",
            "_uses_shell": false,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": true
        }
    },
    "msg": "[Errno 2] No such file or directory",
    "rc": 2
}

这在目标主机上不存在 “/tmp/ansible_command_payload_Fl8ThR/ansible_command_payload.zip/ansible/module_utils/basic.py”,第 2652 行,run_command 缺失

我能够在命令上运行,但不能在 zmcontrol 状态下运行 zimbra 命令。是不是说不能改成zimbra用户?

【问题讨论】:

  • 我想检查并重新启动 zimbra 服务。但是任何使用 zimbra 命令的命令都不起作用。 zmcontrol 状态/zmcontrol 重启。
  • 上面有很多问题,最重要的是您的示例剧本无效:第一个任务不包含任何操作并且运行它无法给出您显示的结果。接下来,become 任务关键字仅接受真值(是、否、真、假...)而不是字符串(您与 become_method 混淆了)。最后,除非在特定情况下并且您知道自己在做什么,否则您不想在ansible.cfg 中设置become = true,因为这会系统地将任何任务升级到root(默认become_user)。在命令行、播放或任务级别进行设置。

标签: ansible zimbra


【解决方案1】:
Updated config
[defaults]
inventory=/inventory
become=false
become_method=sudo
remote_user=admin
ask_pass=False
remote_tmp=/tmp/zimbraansible
allow_world_readable_tmpfiles=true

[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False
timeout=40
admin@ansible ansible]$ cat zimbra_plabyook.yml 
---
 - name: Restarting Zimbra Services
   hosts: mail 
   become: yes
   become_method: su
   become_user: zimbra
   tasks:
     - name: Restart Zimbra service
       command: zmcontrol restart
[admin@ansible ansible]$ cat inventory
[mail]
192.168.122.30

【讨论】:

  • 致命:[192.168.122.30]:失败! => { "msg": "Timeout (12s) waiting for privilege escalation prompt: " 执行剧本时出错。我的权限升级中缺少什么。已经尝试将权限提升设置为 true 和 false,但得到了同样的错误。
  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2017-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多