Ansible创建NIC绑定

时间:2016-03-30 20:17:05

标签: automation ansible ansible-playbook ansible-2.x

我必须使用Ansible进行NIC绑定。我机器上有4个NIC&试过这个戏,我从here

开始
---

#ansible-playbook -i hosts/groups.dat -l vertica07.abc.com vertica-network.yml -e '{ "bond1_ip" : "10.253.1.7" }' -u root -k

- hosts: vertica
  gather_facts: true
  sudo: yes

  vars:
    - bond1_ip: "{{ bond1_ip }}"
    - bond1_gw: "x.x.x.x"

    #bond vars
    - nmcli_bond:
         - {conn_name: 'bond0', ip4: "{{ ansible_default_ipv4.address }}", gw4: "{{ ansible_default_ipv4.gateway }}", mode: 'active-backup'}
         - {conn_name: 'bond1', ip4: "{{ bond1_ip }}", gw4: 'bond1_gw', mode: 'active-backup'}

    - nmcli_bond_slave:
         - {conn_name: 'p1p1', ifname: 'p1p1', master: 'bond0'}
         - {conn_name: 'p1p2', ifname: 'p1p2', master: 'bond0'}
         - {conn_name: 'p2p1', ifname: 'p2p1', master: 'bond1'}
         - {conn_name: 'p2p2', ifname: 'p2p2', master: 'bond1'}

    #ethernet vars
    - nmcli_ethernet:
         - {conn_name: 'p1p1', ifname: 'p1p1', ip4: "{{ ansible_default_ipv4.address }}", gw4: "{{ ansible_default_ipv4.gateway }}"}
         - {conn_name: 'p1p2', ifname: 'p1p2', ip4: "{{ ansible_default_ipv4.address }}", gw4: "{{ ansible_default_ipv4.gateway }}"}
         - {conn_name: 'p2p1', ifname: 'p2p1', ip4: "{{ bond1_ip }}", gw4: "{{ bond1_gw }}"}
         - {conn_name: 'p2p2', ifname: 'p2p2', ip4: "{{ bond1_ip }}", gw4: "{{ bond1_gw }}"}

  tasks:

  - name: install needed network manager libs
    yum: name={{ item }} state=installed
    with_items:
      - NetworkManager-glib
      - libnm-qt-devel.x86_64
      - nm-connection-editor.x86_64
      - libsemanage-python
      - policycoreutils-python


  - name: try nmcli add bond - conn_name only & ip4 gw4 mode
    nmcli: type=bond conn_name={{item.conn_name}} ip4={{item.ip4}} gw4={{item.gw4}} mode={{item.mode}} state=present
    with_items:
      - "{{nmcli_bond}}"


  - name: try nmcli add bond-slave
    nmcli: type=bond-slave conn_name={{item.conn_name}} ifname={{item.ifname}} master={{item.master}} state=present
    with_items:
      - "{{nmcli_bond_slave}}"

但它的失败

TASK [try nmcli add bond - conn_name only & ip4 gw4 mode] **********************
failed: [vertica07.abc.com] => (item={u'conn_name': u'bond0', u'mode': u'active-backup', u'ip4': u'10.100.1.7', u'gw4': u'bond0_gw'}) => {"failed": true, "item": {"conn_name": "bond0", "gw4": "bond0_gw", "ip4": "10.100.1.7", "mode": "active-backup"}, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1459368691.93-148688989216143/nmcli\", line 385, in <module>\r\n    from gi.repository import NetworkManager, NMClient\r\nImportError: No module named gi.repository\r\n", "msg": "MODULE FAILURE", "parsed": false}
failed: [vertica07.abc.com] => (item={u'conn_name': u'bond1', u'mode': u'active-backup', u'ip4': u'10.253.1.7', u'gw4': u'bond1_gw'}) => {"failed": true, "item": {"conn_name": "bond1", "gw4": "bond1_gw", "ip4": "10.253.1.7", "mode": "active-backup"}, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1459368692.4-174709839763552/nmcli\", line 385, in <module>\r\n    from gi.repository import NetworkManager, NMClient\r\nImportError: No module named gi.repository\r\n", "msg": "MODULE FAILURE", "parsed": false}

我在Ansible 2.0.1上并在Centos 6.3上进行网络绑定。目前我只在单个主机上运行它。

我在这里失踪了什么?

由于

3 个答案:

答案 0 :(得分:1)

尝试使用:

 - libnm-gtk-devel.x86_64

而不是:

 - libnm-qt-devel.x86_64

我目前在CentOS 7服务器中使用ansible 2.0.1。

答案 1 :(得分:0)

尝试在CentOs中安装Python-gobject尝试:

yum install NetworkManager-glib 

yum install pygobject2 

https://live.gnome.org/PyGObject

该模块需要pyhton依赖。

答案 2 :(得分:0)

在RHEL 7中出现类似的错误并通过安装PyGObject2修复了上面的Raul提及

[root @ node1~] #rpm -qa --last |头 pygobject2-2.28.6-11.el7.x86_64