# Question:  Network restart stuff

**URL:** <https://forum.ansible.com/t/question-network-restart-stuff/26561>\
**Category:** Ansible Project\
**Created:** [January 24, 2018, 11:31pm UTC](https://forum.ansible.com/t/question-network-restart-stuff/26561 "2018-01-24T23:31:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [January 24, 2018, 11:31pm UTC](https://forum.ansible.com/t/question-network-restart-stuff/26561/1 "2018-01-24T23:31:04Z")

</div>

I know that ssh is smart enough to stay connected (or reconnect), but I am wondering if there is a general rule of thumb to keep in mind when restarting network services via ansible? ie. I am disabling NetworkManager on all systems, enabling the network, and then restarting the network. Any gotchas or anything else to be aware of?

`

# tasks file for disable\_NetworkManager

- name: Check if NetworkManager is installed  
shell: “rpm -qa | grep -i NetworkManager”  
changed\_when: false  
no\_log: true  
register: nm\_installed  
ignore\_errors: true

- name: Gather list of ifcfg-\* files  
shell: ls “{{ net\_path }}” | grep ^ifcfg- | grep 0$ | grep -ve ifcfg-lo -e @ # @ excludes ansible backup files  
register: ifcfg\_list  
changed\_when: false

- name: Disable NetworkManager control from ifcfg-\* files  
lineinfile:  
path: “{{ net\_path }}{{ item }}”  
regexp: “^NM\_CONTROLLED.\*”  
line: ‘NM\_CONTROLLED=no’  
state: present  
with\_items: “{{ ifcfg\_list.stdout\_lines }}”

- fail:  
msg: “NetworkManager is not installed on {{ ansible\_hostname }}. Nothing left to do. Stopping here to prevent network restart.”  
when: nm\_installed.rc != 0

- name: Uninstall NetworkManager  
yum:  
name: “{{ item }}”  
state: absent  
with\_items: “{{ nm\_installed.stdout\_lines }}”  
when: nm\_installed.rc == 0  
notify: Restart Networking

- name: Disable NetworkManager and Enable networking services  
service:  
name: “{{item.name}}”  
enabled: “{{item.enabled}}”  
state: “{{item.state}}”  
changed\_when: false  
with\_items:

- {name: “NetworkManager”, enabled: “no”, state: “stopped”}

- {name: “network”, enabled: “yes”, state: “started”}  
ignore\_errors: true  
notify: Restart Networking

`
