google-cloud-platformansible

ubuntu 2404 image creation failure in creation using ansible


Getting error when creating the ubuntu 2404 image .

FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):
File "/tmp/ansible-tmp-1743068631.520732-94183-75803486625763/AnsiballZ_apt_repository.py", line 107, in
_ansiballz_main()
File "/tmp/ansible-tmp-1743068631.520732-94183-75803486625763/AnsiballZ_apt_repository.py", line 99, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/tmp/ansible-tmp-1743068631.520732-94183-75803486625763/AnsiballZ_apt_repository.py", line 47, in invoke_module
runpy.run_module(mod_name='ansible.modules.apt_repository', init_globals=dict(_module_fqn='ansible.modules.apt_repository', _modlib_path=modlib_path),
File "", line 226, in run_module
File "", line 98, in _run_module_code
File "", line 88, in _run_code
File "/tmp/ansible_apt_repository_payload_lau7f97l/ansible_apt_repository_payload.zip/ansible/modules/apt_repository.py", line 679, in
File "/tmp/ansible_apt_repository_payload_lau7f97l/ansible_apt_repository_payload.zip/ansible/modules/apt_repository.py", line 656, in main
File "/usr/lib/python3/dist-packages/apt/cache.py", line 157, in init
self.open(progress)
File "/usr/lib/python3/dist-packages/apt/cache.py", line 214, in open
self._cache = apt_pkg.Cache(progress)
^^^^^^^^^^^^^^^^^^^^^^^
apt_pkg.Error: E:Conflicting values set for option Signed-By regarding source https://packages.cloud.google.com/apt/ cloud-sdk: /usr/share/keyrings/google-cloud-archive-keyring.gpg != , E:The list of sources could not be read.
Shared connection to 127.0.0.1 closed.", "module_stdout": "", "msg": "MODULE FAILURE
See stdout/stderr for the exact error", "rc": 1}

Using the below ansible tasks

    - name: Download the new Google Cloud GPG key
  shell: |
    curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/google-cloud-archive-keyring.gpg
  args:
    creates: /usr/share/keyrings/google-cloud-archive-keyring.gpg

- name: Add Google Cloud repository to APT sources
  copy:
    dest: /etc/apt/sources.list.d/google-cloud.list
    content: |
      deb [signed-by=/usr/share/keyrings/google-cloud-archive-keyring.gpg] https://packages.cloud.google.com/apt cloud-sdk main
      
- name: add google sdk repository
  apt_repository:
    repo: "deb https://packages.cloud.google.com/apt cloud-sdk main"
    state: present

Solution

  • added

        - name: Update package list
          apt:
            update_cache: yes
    
    
        - name: install google sdk
          apt:
            name: "google-cloud-sdk"
            install_recommends: no
            state: present
          register: result
          until: result is not failed
          retries: 5
          delay: 5