【问题标题】:Start a DB service on a remote host在远程主机上启动数据库服务
【发布时间】:2020-07-06 17:39:30
【问题描述】:

在 Ansible playbook 中,我在运行启动服务模块时遇到错误,因为我想在远程主机上启动数据库。我是 Ansible 的新手。

我想出了这个:

- name: This starts the MySQL Database in the host
  hosts: dbserver
  connection: ssh
  become: yes
  become_method: sudo

  tasks:
  - name: Start the DB in host
    become: yes
    become_user: root
    service:
      name: mysql
      state: started

我收到此错误:

致命:[10.138.12.67]:失败! => {"changed": false, "msg": "找不到请求的服务mysql:host"}

【问题讨论】:

  • mysql 服务器的服务通常以 mysqld 的名称而闻名(对于 daemon)。还有一个简单的说明:如果become_* 选项已经在播放级别设置,则无需在任务级别设置它们。

标签: ansible


【解决方案1】:

@Zeitounator 是正确的,只需添加一个可以使用的正确剧本:

- name: This starts the MySQL Database in the host
  hosts: dbserver
  become: yes
  become_user: root

  tasks:
  - name: Start the DB in host
    service:
      name: mysqld
      state: started
      enable: yes

这里是您可以检查语法的链接:https://docs.ansible.com/ansible/latest/modules/service_module.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多