I don't understand or see what I am doing wrong but it seems like I can't get my ansible playbook to start rng-tools service on an ubuntu server.
environment:
remote server (configured): Ubuntu 14.04.1 LTS
server with playbook: Debian GNU/Linux 7.6 (wheezy)
> apt-cache policy ansible
ansible:
Installed: 1.7-0.git201406241728~unstable
Candidate: 1.7-0.git201406241728~unstable
Version table:
*** 1.7-0.git201406241728~unstable 0
100 /var/lib/dpkg/status
My folder structure is like the following:
tasks/main.yml
tasks/packages.yml that is included from the main.yml file
handlers/main.yml
files/rng-tools
I am installing the package rng-tools using my playbook and it is installed after the execution.
- name: install common packages
apt: name={{ item }} state=present
with_items:
- gnupg
- rng-tools
- reprepro
- dpkg-sig
- nginx
Yes I am installing multiples packages but they are all installed correctly.
Once it is installed I copy the /etc/default/rng-tools file over using:
- name: copy urandom default conf file
copy: src="rng-tools" dest="/etc/default/rng-tools"
notify: start rng-tools
You can notice that I wrote the notify: restart rng-tools
there to get the service started.
My handlers/main.yml file looks like:
---
# Handler for rng-tools
- name: start rng-tools
service: name=rng-tools state=started
- name: restart rng-tools
service: name=rng-tools state=restarted
- name: stop rng-tools
service: name=rng-tools state=stopped
- name: reload rng-tools
service: name=rng-tools state=reloaded
The log of the running playbook produces the following:
TASK: [debian-repository | install common packages] ***************************
ok: [debian.home.dr] => (item=gnupg,rng-tools,reprepro,dpkg-sig,nginx) => {"changed": false, "item": "gnupg,rng-tools,reprepro,dpkg-sig,nginx"}
TASK: [debian-repository | copy urandom default conf file] ********************
ok: [debian.home.dr] => {"changed": false, "dest": "/etc/default/rng-tools", "gid": 0, "group": "root", "md5sum": "45ed1b1ee174494442296fdd262f3b09", "mode": "0644", "owner": "root", "path": "/etc/default/rng-tools", "size": 815, "state": "file", "uid": 0}
PLAY RECAP ********************************************************************
debian.home.dr : ok=12 changed=2 unreachable=0 failed=0
The problem is that the service is never started and I check this with
sudo ps aux | grep rng
root 29392 0.0 0.0 11740 884 pts/1 S+ 22:45 0:00 grep rng
While when I do sudo service rng-tools start
it starts plus I can see the process runing fine.
~:sudo service rng-tools start
Starting Hardware RNG entropy gatherer daemon: rngd.
~:sudo ps aux | grep rng
root 29431 0.0 0.0 8964 336 ? Ss 22:47 0:00 /usr/sbin/rngd -r /dev/urandom
root 29433 0.0 0.0 11740 880 pts/1 S+ 22:47 0:00 grep rng
I tried many thing like commenting all the handlers except one. If I put a command type after the file is copied over and that the command starts the service the service runs, so it doesn't seems to be a permission issue, but somehow I can't figure it out. Plus using the handlers/main.yml is in the best practice guide so I believed I am doing it right.
Do you have any idea why I can't get it started using the playbook?
Notifying handlers In the above example the handlers are executed on task change in the following order: Restart memcached , Restart apache . Handlers are executed in the order they are defined in the handlers section, not in the order listed in the notify statement.
In a nutshell, handlers are special tasks that only get executed when triggered via the notify directive. Handlers are executed at the end of the play, once all tasks are finished. In Ansible, handlers are typically used to start, reload, restart, and stop services.
In Ansible, a handler refers to a particular task that executes when triggered by the notify module. Handlers perform an action defined in the task when a change occurs in the remote host.
changed:false
is the key to unrolling that mystery:
TASK: [debian-repository | copy urandom default conf file] ********************
ok: [debian.home.dr] => {"changed": false, "dest": "/etc/default/rng-tools", "gid": 0, "group": "root", "md5sum": "45ed1b1ee174494442296fdd262f3b09", "mode": "0644", "owner": "root", "path": "/etc/default/rng-tools", "size": 815, "state": "file", "uid": 0}
The "notify: started" is only invoked if the file copy occurs.
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