无法在csv中插入ansible寄存器输出

时间:2016-09-22 04:57:26

标签: ansible

这是我的代码:

- 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'

1 个答案:

答案 0 :(得分:1)

- name: insert data in csv
  shell: |
      echo "{{ name }}{{ last_usage.stdout | default('NULL') }} {{ last_modi.stdout | default('NULL') }}" >> /home/test/test.csv