将Git凭据传递给Ansible抛出错误

时间:2017-07-03 08:03:46

标签: ansible yaml ansible-2.x

我正在关注此页面Clone a private git repository with Ansible (using password prompt)以解决我的要求。在我的Playbook private static ISheet GetFileStream(string fullFilePath) { var fileExtension = Path.GetExtension(fullFilePath); string sheetName; ISheet sheet = null; switch (fileExtension) { case ".xlsx": using (var fs = new FileStream(fullFilePath, FileMode.Open, FileAccess.Read)) { var wb = new XSSFWorkbook(fs); sheetName = wb.GetSheetAt(0).SheetName; sheet = (XSSFSheet) wb.GetSheet(sheetName); } break; case ".xls": using (var fs = new FileStream(fullFilePath, FileMode.Open, FileAccess.Read)) { var wb = new HSSFWorkbook(fs); sheetName = wb.GetSheetAt(0).SheetName; sheet = (HSSFSheet) wb.GetSheet(sheetName); } break; } return sheet; } private static DataTable GetRequestsDataFromExcel(string fullFilePath) { try { var sh = GetFileStream(fullFilePath); var dtExcelTable = new DataTable(); dtExcelTable.Rows.Clear(); dtExcelTable.Columns.Clear(); var headerRow = sh.GetRow(0); int colCount = headerRow.LastCellNum; for (var c = 0; c < colCount; c++) dtExcelTable.Columns.Add(headerRow.GetCell(c).ToString()); var i = 1; var currentRow = sh.GetRow(i); while (currentRow != null) { var dr = dtExcelTable.NewRow(); for (var j = 0; j < currentRow.Cells.Count; j++) { var cell = currentRow.GetCell(j); if (cell != null) switch (cell.CellType) { case CellType.Numeric: dr[j] = DateUtil.IsCellDateFormatted(cell) ? cell.DateCellValue.ToString(CultureInfo.InvariantCulture) : cell.NumericCellValue.ToString(CultureInfo.InvariantCulture); break; case CellType.String: dr[j] = cell.StringCellValue; break; case CellType.Blank: dr[j] = string.Empty; break; } } dtExcelTable.Rows.Add(dr); i++; currentRow = sh.GetRow(i); } return dtExcelTable; } catch (Exception e) { throw; } } 中重复使用了相同的模板,其内容为

main.yml

以及其他一些内容。我正面临一个错误

---
- name: move CentOS repo definitions outside temp
  copy:
    src: "{{ item }}"
    dest: /etc/yum.repos.d/
    owner: "root"
    mode: 0600
  with_fileglob:
    - /etc/yum.repos.d/temp/*
  become: true

- name: passing git credentials for cloning the repos
  vars_prompt:
    - name: "githubuser"
      prompt: "Enter your github username"
      private: no
    - name: "githubpassword"
      prompt: "Enter your github password"
      private: yes

我使用可用的语法检查选项

验证了The error appears to have been in '/tmp/.../tasks/main.yml': line 12, column 3, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: - name: passing git credentials for cloning the repos ^ here The error appears to have been in '/tmp/.../tasks/main.yml': line 12, column 3, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: - name: passing git credentials for cloning the repos ^ here
yml

以及YAML lint,但似乎无法找到错误的原因。

1 个答案:

答案 0 :(得分:1)

您不能在任务级别使用vars_prompt,只能在剧本级别使用。{/ p>

如果您的main.yml是角色的一部分,则应将提示栏移至包含您角色的上级手册。