Я пытаюсь предоставить через packer
и его ansible
инициатору пользовательский AMI, основанный на официальном Ubuntu 18.04
ami, предоставленном AWS.
Подготовка моего упаковщика, которая ищет соответствующую базуami выглядит следующим образом:
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "*{{user `ami-os`}}*",
"root-device-type": "ebs",
"architecture": "x86_64"
},
"owners": ["amazon"],
"most_recent": true
},
где я передаю на лету переменную:
-var "ami-os=ubuntu-bionic-18.04-amd64-server"
Так как у ami не установлено python2
, и я хочу подготовить, используя ansible
, Я должен выполнить через raw
:
- name: pre_tasks --> Install python2 for Ansible
raw: bash -c "test -e /usr/bin/python || (apt -qqy update && apt install -qqy python-minimal)"
become: yes
register: output
changed_when: output.stdout != ""
when: ansible_isbionic
Однако, в большинстве случаев вышеприведенное не удается с сообщением о том, что процесс apt
заблокирован:
amazon-ebs: fatal: [default]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 100, "stderr": "\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n\n\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n\nE: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)\nE: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?\nShared connection to 127.0.0.1 closed.\r\n", "stderr_lines": ["", "WARNING: apt does not have a stable CLI interface. Use with caution in scripts.", "", "", "WARNING: apt does not have a stable CLI interface. Use with caution in scripts.", "", "E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)", "E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?", "Shared connection to 127.0.0.1 closed."], "stdout": "190 packages can be upgraded. Run 'apt list --upgradable' to see them.\n", "stdout_lines": ["190 packages can be upgraded. Run 'apt list --upgradable' to see them."]}
Комучтобы преодолеть это, я явно выполняю:
- name: pre_tasks.yml --> Kill any apt commnds running
raw: bash -c "killall apt apt-get || echo 'no apt-related processes found'"
become: yes
when: ansible_isbionic
- name: pre_tasks.yml --> Remove apt lock files
raw: bash -c "rm -f /var/lib/apt/lists/lock"
become: yes
when: ansible_isbionic
- name: pre_tasks.yml --> Remove apt cache lock files
raw: bash -c "rm -f /var/cache/apt/archives/lock"
become: yes
when: ansible_isbionic
- name: pre_tasks.yml --> Remove apt cache lock files
raw: bash -c "rm -f /var/lib/dpkg/lock"
become: yes
when: ansible_isbionic
Есть идеи, почему процесс apt
блокируется?