0

Google gn的主页指定二进制下载链接https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest。我尝试使用 Ansibleunarchive下载、解压和安装这个 zip 存档:

- name: Unpack gn Ninja meta-build for Android and ChromeOS into /usr/bin/
  become: yes
  unarchive:
    src:  https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest
    remote_src: yes
    exclude: .cipdpkg
    dest: /usr/bin
    mode: 0755

Ansible 似乎检测到这是一个 zip 存档,但给出了错误:

An exception occurred during task execution. To see the full traceback, use -vvv.
The error was: ValueError: time data '19800000.000000' does not match format '%Y%m%d.%H%M%S'
fatal: [127.0.0.1]: FAILED! => changed=false
  module_stderr: |-
    Traceback (most recent call last):
      File "/home/johnm/.ansible/tmp/ansible-tmp-1579394036.8322327-49836510689463/AnsiballZ_unarchive.py", line 102, in <module>
        _ansiballz_main()
      File "/home/johnm/.ansible/tmp/ansible-tmp-1579394036.8322327-49836510689463/AnsiballZ_unarchive.py", line 94, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/home/johnm/.ansible/tmp/ansible-tmp-1579394036.8322327-49836510689463/AnsiballZ_unarchive.py", line 40, in invoke_module
        runpy.run_module(mod_name='ansible.modules.files.unarchive', init_globals=None, run_name='__main__', alter_sys=True)
      File "/usr/lib/python3.6/runpy.py", line 205, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
        mod_name, mod_spec, pkg_name, script_name)
      File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_unarchive_payload_3ij5ij4p/ansible_unarchive_payload.zip/ansible/modules/files/unarchive.py", line 913, in <module>
      File "/tmp/ansible_unarchive_payload_3ij5ij4p/ansible_unarchive_payload.zip/ansible/modules/files/unarchive.py", line 871, in main
      File "/tmp/ansible_unarchive_payload_3ij5ij4p/ansible_unarchive_payload.zip/ansible/modules/files/unarchive.py", line 478, in is_unarchived
      File "/usr/lib/python3.6/_strptime.py", line 559, in _strptime_time
        tt = _strptime(data_string, format)[0]
      File "/usr/lib/python3.6/_strptime.py", line 362, in _strptime
        (data_string, format))
    ValueError: time data '19800000.000000' does not match format '%Y%m%d.%H%M%S'
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

使用 Python 2.7 也同样失败。

如何下载和安装此 zip 存档?

4

1 回答 1

0

zip 存档中文件的时间确实是19800000.000000,这表明这是 zip 存档的问题:

$ wget https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest
$ zipinfo -s -T latest
Archive:  latest
Zip file size: 887558 bytes, number of entries: 2
-r-x------  2.0 unx  2101112 bl defN 19800000.000000 gn
-r--------  2.0 unx      141 bl defN 19800000.000000 .cipdpkg/manifest.json
2 files, 2101253 bytes uncompressed, 887304 bytes compressed:  57.8%

虽然 Ansibleunarchive无法提取存档,但unzipshell 命令可以。所以首先使用下载存档get_url,然后使用提取它unzip

- name: Create a temporary download directory
  tempfile:
    state: directory
  register: tempdir

- name: Download gn
  become: yes
  get_url:
    url:  https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest
    dest: "{{ tempdir.path }}/gn-linux-amd64.zip"

- name: Extract gn
  become: yes
  command:
    cmd: /usr/bin/unzip -o "{{ tempdir.path }}/gn-linux-amd64.zip" gn -d /usr/bin
    warn: false    # Suppress suggestion to use unarchive

- name: Make gn executable
  become: yes
  file:
    path: /usr/bin/gn
    mode: 0755

这有效,但文件gn仍然有一个不太可能的时间戳:

$ ls -l /usr/bin/gn
-rwxr-xr-x 1 root root 2101112 Dec 31  1979 /usr/bin/gn

向 Yuji Konishi 致敬,他在Ansible 问题 35686 中正确指出问题出在 zip 存档中。

于 2020-01-19T01:26:31.267 回答