我不明白或看到我做错了什么,但似乎我无法获得我的ansible playbook来在ubuntu服务器上启动rng-tools服务。
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
我的文件夹结构如下:
tasks/main.yml
tasks/packages.yml that is included from the main.yml file
handlers/main.yml
files/rng-tools
我正在使用我的playbook安装软件包rng-tools,并在执行后安装。
- name: install common packages
apt: name={{ item }} state=present
with_items:
- gnupg
- rng-tools
- reprepro
- dpkg-sig
- nginx
是的我正在安装多个包,但它们都已正确安装。
安装完成后,我使用以下方法复制/ etc / default / rng-tools文件:
- name: copy urandom default conf file
copy: src="rng-tools" dest="/etc/default/rng-tools"
notify: start rng-tools
您可以注意到我在那里写了notify: restart rng-tools
以启动服务。
我的handlers / main.yml文件如下:
---
# 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
正在运行的剧本的日志产生以下内容:
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
问题是该服务从未启动过,我用
进行检查sudo ps aux | grep rng
root 29392 0.0 0.0 11740 884 pts/1 S+ 22:45 0:00 grep rng
当我做sudo service rng-tools start
时,它开始加上我可以看到过程正常运行。
~: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
我尝试了很多东西,比如评论除了一个之外的所有处理程序。如果我在复制文件后输入命令类型并且命令启动服务运行服务,那么它似乎不是一个权限问题,但不知怎的,我无法弄明白。 另外使用handlers / main.yml在best practice guide中,所以我相信我做得对。
你知道为什么我不能开始使用剧本吗?
答案 0 :(得分:14)
changed:false
是解开这个谜团的关键:
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}
"通知:已启动"仅在文件复制发生时调用。