从Ansible中的stdout中删除空值

时间:2019-07-15 12:59:17

标签: null ansible

有人可以让我知道如何从stdout_lines中删除空值。
输出

"stdout_lines": [
        "D:\\Program Files\\Apache Softwarecoder.exe",
        "D:\\Program Files\\Apache Software\\cat8.5.exe"

    ]

预期产量

path: "{{test.stdout_lines | rejectattr('') }}"
path: "{{test.stdout_lines | reject('')|list }}"
path: "{{test.stdout_lines | rejectattr('')|list }}"

我尝试如下

"path": "<generator object _select_or_reject at 0x7fb349f45cd0>"

但是出现以下错误或输出没有变化:

public class Worktime
{

    @SerializedName("ISSUEKEY")
    private String projectKey;
    @SerializedName("STARTDATE")
    private String from;
    @SerializedName("ENDDATE")
    private String to;
    @SerializedName("BOOKINGTEXT")
    private String bookingtext;

    public Worktime(String from, String to, String projectKey) {
        this.from = from;
        this.to = to;
        this.projectKey = projectKey;
    }

    public String getFrom() {
        return from;
    }

    public String getFromAsDate() {
       try {
        return new SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.GERMANY).parse(from);
       } catch (Exception e) {

        }
        return null;
    }

    public void setFrom(Date from) {
        this.from = from;
    }

    public String getTo() {
        return to;
    }

    public String getToAsDate() {
       try {
        return new SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.GERMANY).parse(to);
       } catch (Exception e) {

        }
        return null;
    }

    public void setTo(String to) {
        this.to = to;
    }

    public String getProjectKey() {
        return projectKey;
    }

    public void setProjectKey(String projectKey) {
        this.projectKey = projectKey;
    }

    public String getBookingtext() {
        return bookingtext;
    }

    public void setBookingtext(String bookingtext) {
        this.bookingtext = bookingtext;
    }

    @Override
    public String toString() {
        return "Worktime{" +
                "from=" + from +
                ", to=" + to +
                ", projectKey='" + projectKey + '\'' +
                ", bookingtext='" + bookingtext + '\'' +
                '}';
    }

    public String toRequest()
    {
        SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.GERMANY);
        Date dStart = from;
        Date dEnd = to;
        dEnd.setHours(15);
        return String.format("{" +
                        "\"ISSUEKEY\":\"%s\"," +
                        "\"STARTDATE\":\"%s\"," +
                        "\"ENDDATE\":\"%s\"," +
                "\"BOOKINGTEXT\":\"%s\"" +
                               "}", projectKey, df.format(dStart), df.format(dEnd), bookingtext);
    }
}

1 个答案:

答案 0 :(得分:0)

拒绝执行工作

path: "{{ stdout_lines|reject('match', '^$')|list }}"

以及select

path: "{{ stdout_lines|select('match', '.+')|list }}"