Is an elegant idempotent reload available?

We are currently studying Ansible to provide our servers. This is pretty default nginx, php-fpm and mysql setup. However, I am interested in installing these packages and how to make an idempotent playbook with running services.

For nginx, we have nginx.conf by default and some files in conf.d/ . For php, we have php.ini , a php-fpm.conf , a pool in pool.d/ and some ini files in conf.d/ . Is the idea to transfer all files to any available call for playback?

If all configurations are overwritten, is it normal to do service nginx reload and service php5-fpm reload , even if the server is under heavy load? For initial installation, a reload will not start the server, so I need to first check the status and based on this switch between start and reload ?

If I am looking for players with nginx installation, they often use handlers that restart nginx. However, this is not elegant, so I don't really like this approach:

 service: name=nginx state=restarted 

In general , what is the general pattern for using servers and provisioning servers with services such as nginx, php-fpm and mysql without forcing a restart ?

+6
source share
2 answers

The service module can reload with state=reloaded .

The configuration file will not be loaded if the same version is already on the server. Thus, a reboot will not be a trigger if you use service: name=nginx state=restarted in the handler ( http://www.ansibleworks.com/docs/playbooks.html#handlers-running-operations-on-change ).

You can also use service: name=nginx enable=yes so that the service starts at boot (and therefore there is no need to explicitly start nginx, only reload if necessary).

+5
source

On the #ansible IRC channel, I already have an answer that works. Typically, the template for apt systems is that the service starts after installation. Thus, you can omit start completely and only reload in cases when configurations change.

Then the installation would be (e.g. Nginx)

  • Install nginx
  • Overwrite all configuration files
  • If something has changed in # 2, start a reboot

That should be enough; when Nginx is not installed, steps 1,2 and 3 are performed. When Nginx is installed and the configs are in order, a reboot does not occur. If we update the configuration, step # 2 will lead to a change, so a reboot will occur.

This should be enough to cover all cases.

+4
source

Source: https://habr.com/ru/post/959036/


All Articles