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

时间:2019-05-29 20:06:44

标签: ansible splunk

我不熟悉Ansible-Playbook,并且在接受与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:

我已经浏览了多个在线论坛,当遇到诸如此类的特定提示时,它们会帮助回答该怎么办,但是无论何时我进行调整,都会被告知以下内容:

  

错误! “ _______”不是“任务”的有效属性

在这一点上,我很困,不确定如何继续。

我的代码段如下:

- 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

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

有人有什么见识吗?

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

基于 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 }}
相关问题