如何在 shell 模块中传递多个可执行文件?
How to pass multiple executable in ansible within a shell module?
我试图在ansible执行命令时传递一个提示符y。
当我在服务器上手动执行时,它会要求提示。
问题是命令 运行 我需要传递可执行文件 /bin/bash
命令:source /etc/profile.d/tableau_server.sh && tsm pending-changes apply
期望命令 运行 我需要传递 /usr/bin/expect 。
我的问题是,我如何在 ansible 中传递 2 个可执行文件,以便对于命令它使用 /bin/bash 而对于期望提示它应该使用 /usr/bin/expect 并且错误是因为我正在使用源代码,什么我可以使用替代方案吗?
更新:我不知道为什么,但我无法通过 --ignore-prompt ,它给出了一个错误
ubuntu@ip-xx-xxx-xx-xx:~$ tsm pending-changes apply --ignore-prompt
Unrecognized option: --ignore-prompt
请帮我解决!
ubuntu@ip-xx-xxx-xx-xx:~$ tsm pending-changes apply
This operation will perform a server restart. Are you sure you wish to continue?
(y/n):
我的 ansible 脚本:
shell: |
source /etc/profile.d/tableau_server.sh && tsm pending-changes apply
expect "This operation will perform a server restart. Are you sure you wish to continue?\n(y/n):"
send "y\n"
exit 0
args:
executable: /usr/bin/expect
args:
executable: /bin/bash/expect
when: inventory_hostname == "xx.xxx.xx.xx"
错误:
changed: [xx.xxx.xxx.xx] => {
"changed": true,
"cmd": "source /etc/profile.d/tableau_server.sh && tsm pending-changes apply\n expect \"This operation will perform a server restart. Are you sure you wish to continue?\n(y/n):\"\n send \"y\n\"\n exit 0",
"delta": "0:00:00.034824",
"end": "2018-08-20 17:29:41.457700",
"invocation": {
"module_args": {
"_raw_params": "source /etc/profile.d/tableau_server.sh && tsm pending-changes apply\n expect \"This operation will perform a server restart. Are you sure you wish to continue?\n(y/n):\"\n send \"y\n\"\n exit 0",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": "/usr/bin/expect",
"removes": null,
"stdin": null,
"warn": true
}
},
"rc": 0,
"start": "2018-08-20 17:29:41.422876",
"stderr": "wrong # args: should be \"source ?-encoding name? fileName\"\n while executing\n\"source /etc/profile.d/tableau_server.sh && tsm pending-changes apply\"",
"stderr_lines": [
"wrong # args: should be \"source ?-encoding name? fileName\"",
" while executing",
"\"source /etc/profile.d/tableau_server.sh && tsm pending-changes apply\""
],
"stdout": "",
"stdout_lines": []
我会说你用 bash 命令和命令内部的 '&&' 做的太多了,none 这感觉是幂等的。
我可以建议回到绘图板吗?我建议使用 'creates' 参数创建命令,以便它可以判断是否需要 运行。
https://docs.ansible.com/ansible/2.6/modules/command_module.html
或者事先检查,然后查看命令是否需要 运行ning 使用寄存器。
在您的问题实例中:
tsm pending-changes apply
应该支持https://onlinehelp.tableau.com/current/server-linux/en-us/cli_pending-changes.htm
tsm pending-changes apply --ignore-prompt
然后不会提示是,也不需要 expect 模块。
我通过传递 -r 选项解决了我的问题。
- name: Initialize and Start Tableau Server
shell: source /etc/profile.d/tableau_server.sh && tsm pending-changes apply -r -u ubuntu -p '{{ tableau_server_admin_password }}'
args:
executable: /bin/bash
when: inventory_hostname == "xx.xxx.xx.xx"
我试图在ansible执行命令时传递一个提示符y。 当我在服务器上手动执行时,它会要求提示。
问题是命令 运行 我需要传递可执行文件 /bin/bash
命令:source /etc/profile.d/tableau_server.sh && tsm pending-changes apply
期望命令 运行 我需要传递 /usr/bin/expect 。
我的问题是,我如何在 ansible 中传递 2 个可执行文件,以便对于命令它使用 /bin/bash 而对于期望提示它应该使用 /usr/bin/expect 并且错误是因为我正在使用源代码,什么我可以使用替代方案吗?
更新:我不知道为什么,但我无法通过 --ignore-prompt ,它给出了一个错误
ubuntu@ip-xx-xxx-xx-xx:~$ tsm pending-changes apply --ignore-prompt
Unrecognized option: --ignore-prompt
请帮我解决!
ubuntu@ip-xx-xxx-xx-xx:~$ tsm pending-changes apply
This operation will perform a server restart. Are you sure you wish to continue?
(y/n):
我的 ansible 脚本:
shell: |
source /etc/profile.d/tableau_server.sh && tsm pending-changes apply
expect "This operation will perform a server restart. Are you sure you wish to continue?\n(y/n):"
send "y\n"
exit 0
args:
executable: /usr/bin/expect
args:
executable: /bin/bash/expect
when: inventory_hostname == "xx.xxx.xx.xx"
错误:
changed: [xx.xxx.xxx.xx] => {
"changed": true,
"cmd": "source /etc/profile.d/tableau_server.sh && tsm pending-changes apply\n expect \"This operation will perform a server restart. Are you sure you wish to continue?\n(y/n):\"\n send \"y\n\"\n exit 0",
"delta": "0:00:00.034824",
"end": "2018-08-20 17:29:41.457700",
"invocation": {
"module_args": {
"_raw_params": "source /etc/profile.d/tableau_server.sh && tsm pending-changes apply\n expect \"This operation will perform a server restart. Are you sure you wish to continue?\n(y/n):\"\n send \"y\n\"\n exit 0",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": "/usr/bin/expect",
"removes": null,
"stdin": null,
"warn": true
}
},
"rc": 0,
"start": "2018-08-20 17:29:41.422876",
"stderr": "wrong # args: should be \"source ?-encoding name? fileName\"\n while executing\n\"source /etc/profile.d/tableau_server.sh && tsm pending-changes apply\"",
"stderr_lines": [
"wrong # args: should be \"source ?-encoding name? fileName\"",
" while executing",
"\"source /etc/profile.d/tableau_server.sh && tsm pending-changes apply\""
],
"stdout": "",
"stdout_lines": []
我会说你用 bash 命令和命令内部的 '&&' 做的太多了,none 这感觉是幂等的。
我可以建议回到绘图板吗?我建议使用 'creates' 参数创建命令,以便它可以判断是否需要 运行。
https://docs.ansible.com/ansible/2.6/modules/command_module.html
或者事先检查,然后查看命令是否需要 运行ning 使用寄存器。
在您的问题实例中:
tsm pending-changes apply
应该支持https://onlinehelp.tableau.com/current/server-linux/en-us/cli_pending-changes.htm
tsm pending-changes apply --ignore-prompt
然后不会提示是,也不需要 expect 模块。
我通过传递 -r 选项解决了我的问题。
- name: Initialize and Start Tableau Server
shell: source /etc/profile.d/tableau_server.sh && tsm pending-changes apply -r -u ubuntu -p '{{ tableau_server_admin_password }}'
args:
executable: /bin/bash
when: inventory_hostname == "xx.xxx.xx.xx"