使用Ansible Playbook接受Splunk许可协议
我不熟悉使用Ansible Playbooks,在接受与Splunk的许可协议时遇到了问题 每当我运行shell时:使用Ansible Playbook接受Splunk许可协议,ansible,splunk,Ansible,Splunk,我不熟悉使用Ansible Playbooks,在接受与Splunk的许可协议时遇到了问题 每当我运行shell时: "/opt/splunkforwarder/bin/splunk start --accept-license --answer-yes" 我得到了一个持续的锁定,迫使我终止程序 TASK [acceptlicense] *******************************************************************************
"/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
#
# {{ ansible_managed }}
#
[user_info]
USERNAME = admin
HASHED_PASSWORD = {{ _splunk_hashed_password.stdout }}
过去我只写过几本剧本,所以这个错误对我来说是新的
有人有什么见解吗?你应该看看。它将允许您执行命令并响应相应的提示。Splunk没有很好地记录这一点,但有两种方法可以做到这一点 1) 在命令行中提供密码<代码>splunk start--接受许可证--回答是--否提示--种子密码 2) 创建一个$SPLUNK_HOME/etc/system/local/user-seed.conf文件
[user_info]
USERNAME = admin
PASSWORD = <password>
[用户信息]
用户名=管理员
密码=
然后开始Splunk:
splunk start--接受许可证--回答yes--no提示符
基于RichG的回答,下面是我用来实现这一点的一些任务
- 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文件如下所示:
- 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
#
# {{ ansible_managed }}
#
[user_info]
USERNAME = admin
HASHED_PASSWORD = {{ _splunk_hashed_password.stdout }}
成功!谢谢介绍如何使用expect模块。这种方法对我来说总是不合时宜,不起作用。