如何让ansible对sendmailconfig要求的所有内容回答“是”

时间:2017-01-26 10:54:39

标签: linux bash ansible command-line-interface sendmail

我正在设置一个带有ansible的服务器,我想安装和配置sendmailconfig。要做到这一点,我首先使用apt安装它,然后我需要运行y AND asnwer sendmailconfig来解决它提出的所有问题。

最后一部分是我认为最难的部分。 -y没有XDocument original = .... using(var reader = original.CreateReader()) { var copy = XDocument.Load(reader, LoadOptions.SetLineInfo); } 标志对所有内容回答“是”,那么如何让Ansible简单地同意它所提出的所有问题呢?

2 个答案:

答案 0 :(得分:8)

只需使用yes shell实用程序

即可
yes 'y' | <command-name>
#    ^^The repeated string being 'yes' as the OP had asked.

man页面

NAME
       yes - output a string repeatedly until killed

SYNOPSIS
       yes [STRING]...
       yes OPTION

DESCRIPTION
       Repeatedly output a line with all specified STRING(s), or 'y'.

答案 1 :(得分:1)

基本上,您将需要执行两个任务:更新主机并运行sendmailconfig。 注意:如果您正在运行Ansible 2.5.0,则可能需要在远程主机上安装pexpect模块,因此请将此任务包括在任务文件中。例如:

- name: Update hosts
  lineinfile:
    path: /etc/hosts
    regexp: '^127\.0\.0\.1'
    line: '127.0.0.1 localhost   {{ ansible_host }}'
    owner: root
    group: root
    mode: 0644

- name: Install pexpect module
  raw: sudo apt-get -y install python-pexpect

- name: Configure sendmail
  expect:
    command: sendmailconfig
    responses:
      Question:
        - Configure sendmail with the existing /etc/mail/sendmail.conf? [Y]: y
        - Configure sendmail with the existing /etc/mail/sendmail.mc? [Y]: y
        - Reload the running sendmail now with the new configuration? [Y]: y
    timeout: 30