![如何修复我的 ansible playbook](https://linux22.com/image/1206300/%E5%A6%82%E4%BD%95%E4%BF%AE%E5%A4%8D%E6%88%91%E7%9A%84%20ansible%20playbook.png)
我在 GCP 上使用 Ubuntu 18,并尝试从主节点在我的工作节点上安装 Chromium 浏览器。我编写的剧本成功地在我的工作节点上安装了 Java 和 Git,但在尝试执行 Chrome 浏览器的安装时出现错误。这是剧本
---
- hosts: Hosts
become: yes
become_user: root
tasks:
- name: install git
package:
name: git
state: present
- name: install java
package:
name: openjdk-8-jdk
state: present
- name: copy chromedriver
copy:
src: /root
dest: /root
remote_src: yes
- name: install chromium browser
这是运行剧本的结果
root@mastervm-project:~# ansible-playbook project.yml
PLAY [Hosts] *******************************************************************
TASK [Gathering Facts] *********************************************************
ok: [10.128.0.11]
TASK [install git] *************************************************************
ok: [10.128.0.11]
TASK [install java] ************************************************************
ok: [10.128.0.11]
TASK [copy chromedriver] *******************************************************
changed: [10.128.0.11]
TASK [install chromium browser] ************************************************
fatal: [10.128.0.11]: FAILED! => {"cache_update_time": 1595897202, "cache_updated": false, "changed": false, "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\" install 'chromium-browser'' failed: E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. \n", "rc": 100, "stderr": "E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. \n", "stderr_lines": ["E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. "], "stdout": "", "stdout_lines": []}
PLAY RECAP *********************************************************************
10.128.0.11 : ok=4 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
我尝试sudo dpkg --configure -a
按照它所说的方式运行,然后再次运行剧本,但仍然出现同样的错误。
这是我按照 Brian 分享的链接中的格式编写的另一个剧本。这个剧本仅用于安装 Chromium。
---
- hosts: Hosts
tasks:
- name: install chromium
package:
name: chromium-browser
state: present
become: yes
become_user: root
它给了我类似的错误
root@mastervm-project:~# ansible-playbook project_chromium.yml
PLAY [Hosts] *******************************************************************
TASK [Gathering Facts] *********************************************************
ok: [10.128.0.11]
TASK [install chromium] ********************************************************
fatal: [10.128.0.11]: FAILED! => {"cache_update_time": 1595897202, "cache_updated": false, "changed": false, "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\" install 'chromium-browser'' failed: E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. \n", "rc": 100, "stderr": "E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. \n", "stderr_lines": ["E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. "], "stdout": "", "stdout_lines": []}
PLAY RECAP *********************************************************************
10.128.0.11 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
答案1
问:fatal: [10.128.0.11]: FAILED! => ... "rc": 100, "stderr": "E: dpkg 被中断,您必须手动运行‘sudo dpkg--configure-a’来纠正问题。
答:修复损坏的软件包。请参阅E:dpkg 被中断……运行“sudo dpkg --configure -a”. 任务将按预期进行
- name: install chromium
become: yes
become_user: root
package:
name: chromium-browser
state: present