Search code examples
ansibleiptablescentos7

unable to restart iptables from ansible ( Interactive authentication required)


How to restart iptables service from Ansible (in order to reload config file /etc/sysconfig/iptables)

I have handler restart iptables defined as

service: name=iptables enabled=yes state=restarted

But it produces following error message:

fatal: [xx.xx.xx.xx]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to stop iptables.service: Interactive authentication required.\n Failed to start iptables.service: Interactive authentication required.\n"}

I am working with CentOS Linux release 7.2.1511 (Core)


Solution

  • I was not running my handler command as root. If handler contains become: yes then handler works fine.

    - name: restart iptables
      become: yes
      service: name=iptables enabled=yes state=restarted
    

    Another way of refreshing iptables configuration, without restarting it is

    - name: reload iptables
      become: yes
      shell: iptables-restore <  /etc/sysconfig/iptables