0
這裏是我的代碼:無法插入ansible寄存器輸出的CSV
- name: Check last usage history
shell: |
mysql -N --host={{ host }} \
--user={{ user }} \
--password={{ pass }} \
-D db \
-e "SELECT LEFT(CreationTime,LOCATE(' ',CreationTime) - 1) from table;"
register: last_usage
when: products != "1" and products != "2" and products != "3"
- name: Check last modified
shell: |
mysql -N --host={{ host }} \
--user={{ user }} \
--password={{ password }} \
-D db \
-e "SELECT LEFT(ModificationTime,LOCATE(' ',ModificationTime) - 1) FROM table2"
register: last_modi
when: products == "1 or products == "3" or products == "2"
- name: insert data in csv
shell: |
echo "{{ name }}{{ last_usage.stdout }} {{ last_modi.stdout }}" >> /home/test/test.csv
我想,如果任務被跳過打印在csv文件NULL輸出的變量。 現在,它顯示
One or more undefined variables: 'dict object' has no attribute 'stdout'
謝謝。我已經找到了相同的另一種解決方案來捕捉{last_usage.changed =真!| ternary('last_usage.stdout','NULL')} – kohi