使用ansible

时间:2016-11-19 15:38:05

标签: python mysql ansible ansible-playbook

我可以使用ansible在我的应用服务器上安装几个python模块。但是,当我包含python-mysqldb模块时,它会抛出以下错误。

vagrant@control:~/ansible$ ansible-playbook playbooks/webserver.yml

PLAY [webserver] ***************************************************************

TASK [setup] *******************************************************************
ok: [app02]
ok: [app01]

TASK [install web components] **************************************************
failed: [app02] (item=[u'apache2', u'libapache2-mod-wsgi', u'python-pip', u'python-virtualenv', u'python-mysqldb']) => {"failed": true, "item": ["apache2", "libapache2-mod-wsgi", "python-pip", "python-virtualenv", "python-mysqldb"], "module_stderr": "Shared connection to app02 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_sYzNC_/ansible_module_apt.py\", line 909, in <module>\r\n    main()\r\n  File \"/tmp/ansible_sYzNC_/ansible_module_apt.py\", line 892, in main\r\n    if updated_cache and not retvals['changed']:\r\nKeyError: 'changed'\r\n", "msg": "MODULE FAILURE"}
failed: [app01] (item=[u'apache2', u'libapache2-mod-wsgi', u'python-pip', u'python-virtualenv', u'python-mysqldb']) => {"failed": true, "item": ["apache2", "libapache2-mod-wsgi", "python-pip", "python-virtualenv", "python-mysqldb"], "module_stderr": "Shared connection to app01 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_GKrHoN/ansible_module_apt.py\", line 909, in <module>\r\n    main()\r\n  File \"/tmp/ansible_GKrHoN/ansible_module_apt.py\", line 892, in main\r\n    if updated_cache and not retvals['changed']:\r\nKeyError: 'changed'\r\n", "msg": "MODULE FAILURE"}
    to retry, use: --limit @/home/vagrant/ansible/playbooks/webserver.retry

PLAY RECAP *********************************************************************
app01                      : ok=1    changed=0    unreachable=0    failed=1   
app02                      : ok=1    changed=0    unreachable=0    failed=1   

Ansible playbook:

---
- hosts: webserver
  become: true
  tasks:
    - name: install web components
      apt: name={{item}} state=present update_cache=yes
      with_items:
        - apache2
        - libapache2-mod-wsgi
        - python-pip
        - python-virtualenv
        - python-mysqldb

我正在尝试在apache app服务器上安装几个mysql模块,但是这个特殊模块阻止了我前进。我此刻毫无头绪。如果有人可以帮助我,那将是非常有帮助的。

非常感谢提前。

1 个答案:

答案 0 :(得分:1)

在进一步调试app服务器后,我开始了解根本原因。

应用服务器无法连接到远程存储库。我运行以下命令关闭防火墙,因为我正在使用流浪的ubuntu盒。

sudo ufw disable

它可能不是组织内ubuntu盒的可行选项,因为它们受防火墙策略的约束。