我正在ansible中运行一本剧本,该剧本采用了shell模块输出的stdout_lines并给出了以下格式:
StackNames.stdout_lines:
- "["
- ' "SHSD-CZWV-ami-automation-WIN2012R2-NONPROD-ramirja-119",'
- ' "SHSD-CZWV-ami-automation-WIN2012R2-NONPROD-ramirja-118",'
- ' "SHSD-CZWV-ami-automation-WIN2012R2-NONPROD-ramirja-117"'
- "]"
我正在尝试获取可以在循环中使用的这些值的列表,以便可以删除堆栈,但是首先我需要除去所有引号,dbl引号和空格,以便为cloudformation ansible模块正确格式化接受stack_name参数值。
我尝试使用正确的格式设置新变量,例如:
- set_fact:
stack_list: "{{ StackNames.stdout_lines | replace('"','') |trim }}"
但到目前为止我还没有运气。
任何帮助是极大的赞赏
From your example, your shell command is returning a json parsable result. Simply parse the global output (
stdout
) inside a variable with thefrom_json
filter and you're done:使用这种模式
将选择这些行