使用 Ansible-Playbook 接受 Splunk 许可协议

Accepting Splunk license agreement using Ansible-Playbook

我是 Ansible-Playbooks 的新手,我正在 运行 解决接受 Splunk 许可协议的问题。

任何时候我有 shell 运行:

"/opt/splunkforwarder/bin/splunk start --accept-license --answer-yes"

我遇到持续的锁定,迫使我终止程序。

TASK [acceptlicense] ****************************************************************************************************************

^C

进入框并运行手动输入命令我被告知以下内容:

[root@##########-lab_env]# /opt/splunkforwarder/bin/splunk start --accept-license --answer-yes

This appears to be your first time running this version of Splunk.

Create credentials for the administrator account.
Characters do not appear on the screen when you type the password.
Password must contain at least:
   * 8 total printable ASCII character(s).
Please enter a new password:

我浏览了几个在线论坛,这些论坛在遇到此类特定提示时帮助回答该怎么做,但每当我进行调整时,我都会被告知以下内容:

ERROR! '_______' is not a valid attribute for a Task

此时我很困惑,不确定如何继续。

我的代码片段如下:

- hosts: "{{hostName}}"
  become: true
  become_user: root
  become_method: sudo

  tasks: 

    - name: copy_splunk
      shell: cp splunkforwarder-7.1.3-51d9cac7b837-linux-2.6-x86_64.rpm /opt/.; date; ls -l /opt
      args:
        chdir: /tmp
      register: run_ll

    - debug: var=run_ll.stdout_lines

    - name: install rpm package
      shell: rpm -ivh splunkforwarder-7.1.3-51d9cac7b837-linux-2.6-x86_64.rpm
      args:
        chdir: /tmp
      ignore_errors: True
      register: install_rpm

    - debug: var=install_rpm.stdout_lines

    - name: acceptlicense
      tags:
        - install
      shell: /opt/splunkforwarder/bin/splunk start --accept-license --answer-yes
      register: accept_l

    - debug: var=accept_l.stdout_lines

我过去只做过几本剧本,所以这个错误对我来说是新的。

有没有人有任何见解?

你应该看看expect module。它将允许您执行命令并响应它们各自的提示。

Splunk 对此没有很好的记录,但有两种方法可以做到这一点。

1) 在命令行中提供密码。 splunk start --accept-license --answer-yes --no-prompt --seed-passwd <passwd>.

2) 创建 $SPLUNK_HOME/etc/system/local/user-seed.conf 文件

[user_info]
USERNAME = admin
PASSWORD = <password>

然后启动 Splunk: splunk start --accept-license --answer-yes --no-prompt

基于 RichG 的回答,这里是我用来完成这项工作的 Ansible 任务。

- hosts: all
  tasks:
    - name: create a random password
      ansible.builtin.shell: date +%s | sha256sum | base64 | head -c 32 ; echo
      register: _splunk_password
      changed_when: false

    - name: hash the random password
      ansible.builtin.command:
        argv:
          - /opt/splunkforwarder/bin/splunk
          - "hash-passwd"
          - "{{ _splunk_password.stdout }}"
      register: _splunk_hashed_password
      changed_when: false

    - name: create the user-seed config file
      ansible.builtin.template:
        src: user-seed.conf.j2
        dest: /opt/splunkforwarder/etc/system/local/user-seed.conf
        owner: root
        group: root
        mode: 0640
      become: yes

    - name: accept the license
      ansible.builtin.shell:
        argv:
          - /opt/splunkforwarder/bin/splunk
          - start
          - "--accept-license"
          - "--answer-yes"
          - "--no-prompt"
      become: yes

而 user-seed.conf.j2 文件如下所示:

#
# {{ ansible_managed }}
#

[user_info]
USERNAME = admin
HASHED_PASSWORD = {{ _splunk_hashed_password.stdout }}