I copy-pasted this from the manual and it fails in my playbook (version 2.0.2):
- service: name=network state=restarted args=eth0
I am getting this error:
"msg": "Failed to stop eth0.service: Unit eth0.service not loaded.\nFailed to start eth0.service: Unit eth0.service failed to load: No such file or directory.\n"}
What is the correct syntax, please?
But if you change network configuration before restart, something like IP address, after restart ansible hangs because connection is lost (IP address changed). Won't work if system does not have the "network" service. That applies to recent Fedora and RHEL 8, in particular. There, you can do the equivalent of systemctl restart NetworkManager.
By default, any Ansible installation comes with the service module, and it is also part of the Ansible-base set of modules. Using the service module, we can manage and control the following service states: We can also configure the service to auto-start or be in a stop state when the server comes up using the enable key.
If you are a network engineer that has operational Ansible Playbooks that need to reboot devices or take them offline, this module will help you make more programmatic playbooks to handle disconnects. By leveraging wait_for_connection network automation playbooks can look and behave more like playbooks for Linux or Windows hosts.
Red Hat subscribers, select 2.9 in the version selection to the left for the most recent Red Hat release. This module is part of ansible-core and included in all Ansible installations.
Just do like this (@nasr already commented it):
- name: Restart network
service:
name: network
state: restarted
But if you change network configuration before restart, something like IP address, after restart ansible hangs because connection is lost (IP address changed).
- command: /etc/init.d/network restart
does work wonderfully but I feel that using command
kinda defeats the purpose of using ansible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With