---
- name: Install and configure NetworkManager
  hosts: oo_all_hosts
  become: yes
  tasks:
  - name: install NetworkManager
    package:
      name: 'NetworkManager'
      state: present
    register: result
    until: result is succeeded

  - name: configure NetworkManager
    lineinfile:
      dest: "/etc/sysconfig/network-scripts/ifcfg-{{ ansible_default_ipv4['interface'] }}"
      regexp: '^{{ item }}='
      line: '{{ item }}=yes'
      state: present
      create: yes
    with_items:
    - 'USE_PEERDNS'
    - 'NM_CONTROLLED'

  - name: enable and start NetworkManager
    service:
      name: 'NetworkManager'
      state: started
      enabled: yes
