我使用 Ansible 运行启动脚本,如下所示:
\n- name: Start service\n raw: "source ~/.profile; ~/start.sh"\nRun Code Online (Sandbox Code Playgroud)\n现在,我想继续检查上面启动的服务的 HTTP 状态,直到成功 \xe2\x80\x94 200。
下面是我如何检查 HTTP 状态200,但是,我不知道如何继续检查 2 分钟并报告 URL 是否仍然没有返回200。
- name: Detect if HTTp response is \'200\'\n uri:\n url: \'http://example.org/iportal/\'\n return_content: yes\n validate_certs: no\n status_code:\n - 200\n register: uri_output\nRun Code Online (Sandbox Code Playgroud)\n 我正在尝试创建一个 shell 脚本,通过检查显示 1/1 的 READY 标题来验证某些 Pod 是否已准备就绪。我尝试过两种方法。
1.
ready=$(oc get pods | awk '{print $2}' | tail -n +2) # prints 1/1 or 0/1 for each pod
until [[ ${ready} == "1/1" ]]
do
echo "Waiting for pods to be ready."
sleep 3
done
Run Code Online (Sandbox Code Playgroud)
即使 Pod 已准备好并在 READY 列中显示 1/1,上面的脚本仍会一直显示“等待 Pod 准备好”。
2.
while true ; do
for i in 1 2 3; do
ready=`oc get pods | awk '{print $2}' | tail -n +2 | head -n …Run Code Online (Sandbox Code Playgroud) 我有一个包含 Until 活动的 Azure 数据工厂 v2 管道。
\n\n直到里面是一个复制活动 - 如果失败,则会记录错误,与本文中完全相同,并且我希望循环继续。
\n\n\n\n尽管处理了内部复制活动\xe2\x80\x99s 错误,但直到活动被视为失败,因为内部活动已失败。
\n\n\n\n有没有办法配置直到活动在内部活动失败时继续?
\n我想知道如何循环多个任务直到满足条件。
#main.yml
- set_fact:
num: 1
req_num: 10
- name: Start to unregister entities
include_tasks: output.yml
loop: "{{ range(num, req_num + 1)|list }}"
Run Code Online (Sandbox Code Playgroud)
#输出.yml
- name: get status
raw: cat /tmp/output
register: rawoutput
- name: copy to localhost
copy:
content: "{{rawoutput.stdout}}"
dest: /tmp/output1
delegate_to: localhost
- name: reg output2
shell: awk something /tmp/output1 |awk '/something/,0' |head -n something |tail -n something > /tmp/output2 ; cat /tmp/output2
register: output2
delegate_to: localhost
- name: compare output2
debug:
msg: "{{item}}"
with_items: "{{ output2.stdout_lines …Run Code Online (Sandbox Code Playgroud) 作者注:此问题使用旧版本 Nushell 中过时的语法和语句。请参阅下面的答案以了解更新的语法。
Nushell 脚本中如何执行 while/until 循环?
由于 Nushell 有一个相当令人惊叹的表/JSON 解析系统,我一直在尝试通过它使用Stack Exchange API。
第一个挑战是循环访问 API 调用的多个可能的结果页面。我的(通常是程序性的,有时是面向对象的)背景让我在 Nushell 中找到了一个构造,例如:
let page = 1
let re = (http (echo "/2.3/questions?fromdate=1648771200&todate=1648944000&order=desc&sort=activity&site=askubuntu&page=" $page) | from json)
let questions = $re.items
while ($re.has_more) {
let page = page + 1
let re = (http (echo "/2.3/questions?fromdate=1648771200&todate=1648944000&order=desc&sort=activity&site=askubuntu&page=" $page) | from json)
let questions = $questions | append $re.items
}
Run Code Online (Sandbox Code Playgroud)
...或等效的until构造。
我如何在 Nushell 中实现这一点?
注意 -在上面的示例中使用httpiegzip ,因为它会自动处理Stack API 所需的压缩( …
为了检查内表的所有条目是否lt_itab满足条件 COND,我想使用 REDUCE 语句。一旦发生违反 COND 的行,循环当然需要终止。下面的第二个代码块似乎可以工作,但在我看来像是对迭代索引的轻微滥用。您是否知道 REDUCE 语法中有更好/更透明的解决方案?是否可以使用迭代变量的结构(整数、布尔值)?该INDEX INTO选项似乎不适用于 REDUCE。与内核版本 753(或更低版本)的兼容性会很好。
这是我的最小可重现示例(MRE),仅在lvr_flag_allowed = abap_false OR注释掉时才通过语法检查(即 -> "lvr_flag_allowed = abap_false OR):
DATA: lt_itab TYPE TABLE OF i,
rv_flag_allowed TYPE boole_d.
lt_itab = VALUE #( ( 2 ) ( 1 ) ( -1 ) ( 5 ) ).
IF lt_itab IS NOT INITIAL.
rv_flag_allowed = REDUCE #( INIT lvr_flag_allowed = abap_true
FOR lvf_idx = 1 UNTIL lvr_flag_allowed = abap_false OR
lvf_idx > lines( …Run Code Online (Sandbox Code Playgroud) until-loop ×6
ansible ×2
loops ×2
while-loop ×2
abap ×1
azure ×1
bash ×1
etl ×1
kubernetes ×1
nushell ×1
openshift ×1
url ×1
wait ×1