Linux Ansible:即使在调试后显示已注册变量';内容 双寄存器变量
我有一个任务列表,在其中注册shell任务的输出。shell命令列出一个目录,然后通过管道将输出传输到grep。这个任务很有效,我得到了我想要的结果。playbook SVN源文件中的Eariler将被选中并发送到{{DestRemoteDir}}目录。所讨论的代码从命令的输出构建一个列表。我把这些清单放在剧本后面的其他各种事实上。[](我知道ansible的查找模块,但我发现“ls-1”更易于使用。) 剧本(任务/main.yml) 输出 调试 在“标准输出列”上方:[“IA-XD-U列表”和“标准输出列”:[“iaxd-U 1.2.7.6-15_all.deb”,…]已准备就绪 因此,从调试任务中,我看到变量存在并已定义(或者我认为是这样)。但是当我测试shell命令是否失败时 错误消息 状态清楚地表明Deb_列表未定义为什么? 我只是调试那个变量的thad值Linux Ansible:即使在调试后显示已注册变量';内容 双寄存器变量,linux,ansible,Linux,Ansible,我有一个任务列表,在其中注册shell任务的输出。shell命令列出一个目录,然后通过管道将输出传输到grep。这个任务很有效,我得到了我想要的结果。playbook SVN源文件中的Eariler将被选中并发送到{{DestRemoteDir}}目录。所讨论的代码从命令的输出构建一个列表。我把这些清单放在剧本后面的其他各种事实上。[](我知道ansible的查找模块,但我发现“ls-1”更易于使用。) 剧本(任务/main.yml) 输出 调试 在“标准输出列”上方:[“IA-XD-U列表”和
TASK [server_iaxd_install : Print if undefined Deb_list] *********************************************************************
task path: /home/ansible/ansible_server_working/roles/server_iaxd_install/tasks/main.yml:64
Tuesday 25 February 2020 11:50:12 +0100 (0:00:00.222) 0:00:07.890 ******
ok: [AnsibleTest2] => {
"msg": "Deb_List is not real"
}
Read vars_file '/home/ansible/.ssh/SudoPassKey'
尝试测试我想要的关键数据“Deb_list.stdout_line”,可能会出现错误,因为变量不存在
TASK [server_iaxd_install : Print if undefined Deb_list.stdout_lines] ********************************************************
task path: /home/ansible/ansible_server_working/roles/server_iaxd_install/tasks/main.yml:69
Tuesday 25 February 2020 11:50:12 +0100 (0:00:00.197) 0:00:08.087 ******
fatal: [AnsibleTest2]: FAILED! => {
"msg": "The conditional check 'Deb_list.stdout_lines is undefined' failed. The error was: error while evaluating conditional (Deb_list.stdout_lines is undefined): 'Deb_list' is undefined\n\nThe error appears to have been in '/home/ansible/ansible_server_working/roles/server_iaxd_install/tasks/main.yml': line 69, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Print if undefined Deb_list.stdout_lines\n ^ here\n"
}
这要么是一个“树之林”(我看不出明显的)错误,要么是一个我需要绕过去的恼人的Ansible怪癖。是的,这是一个“树之林”(我看不到明显的)错误。
查找错误后,我更改了代码
- name: Print if undefined Deb_List
debug:
msg: "Deb_List is not real"
when: Deb_List is undefined
- name: Print if undefined Deb_List.stdout_lines
debug:
msg: "Deb_List.stdout_lines is not real"
when: Deb_List.stdout_lines is undefined
而现在的输出要好得多:
TASK [server_iaxd_install : Print if undefined Deb_List] *********************************************************************
task path: /home/ansible/ansible_server_working/roles/server_iaxd_install/tasks/main.yml:77
Tuesday 25 February 2020 16:00:34 +0100 (0:00:00.242) 0:00:08.013 ******
skipping: [AnsibleTest2] => {}
Read vars_file '/home/ansible/.ssh/SudoPassKey'
TASK [server_iaxd_install : Print if undefined Deb_List.stdout_lines] ********************************************************
task path: /home/ansible/ansible_server_working/roles/server_iaxd_install/tasks/main.yml:82
Tuesday 25 February 2020 16:00:34 +0100 (0:00:00.065) 0:00:08.078 ******
skipping: [AnsibleTest2] => {}
大写:
当:Deb_列表未定义时
应该是当:Deb_列表未定义时
。是的,就是这样。
TASK [server_iaxd_install : Print if undefined Deb_list.stdout_lines] ********************************************************
task path: /home/ansible/ansible_server_working/roles/server_iaxd_install/tasks/main.yml:69
Tuesday 25 February 2020 11:50:12 +0100 (0:00:00.197) 0:00:08.087 ******
fatal: [AnsibleTest2]: FAILED! => {
"msg": "The conditional check 'Deb_list.stdout_lines is undefined' failed. The error was: error while evaluating conditional (Deb_list.stdout_lines is undefined): 'Deb_list' is undefined\n\nThe error appears to have been in '/home/ansible/ansible_server_working/roles/server_iaxd_install/tasks/main.yml': line 69, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Print if undefined Deb_list.stdout_lines\n ^ here\n"
}
- name: Print if undefined Deb_List
debug:
msg: "Deb_List is not real"
when: Deb_List is undefined
- name: Print if undefined Deb_List.stdout_lines
debug:
msg: "Deb_List.stdout_lines is not real"
when: Deb_List.stdout_lines is undefined
TASK [server_iaxd_install : Print if undefined Deb_List] *********************************************************************
task path: /home/ansible/ansible_server_working/roles/server_iaxd_install/tasks/main.yml:77
Tuesday 25 February 2020 16:00:34 +0100 (0:00:00.242) 0:00:08.013 ******
skipping: [AnsibleTest2] => {}
Read vars_file '/home/ansible/.ssh/SudoPassKey'
TASK [server_iaxd_install : Print if undefined Deb_List.stdout_lines] ********************************************************
task path: /home/ansible/ansible_server_working/roles/server_iaxd_install/tasks/main.yml:82
Tuesday 25 February 2020 16:00:34 +0100 (0:00:00.065) 0:00:08.078 ******
skipping: [AnsibleTest2] => {}