2015-09-09 56 views
0

我正在爲任何Linux發行版上的Ansible.Galaxy編寫一本合適的劇本,其中包括install nginx。 但我覺得在包含Systemd的映像上使用Travis CI和Docker進行測試。因爲SystemD給出了一個錯誤:使用基於rpm的發行版測試劇本,systemd作爲Docker容器

Failed to get D-Bus connection: No connection to service manager.

正如你可以看到https://travis-ci.org/weldpua2008/ansible-nginx/jobs/78864352 時發生了錯誤。

所以我儘量表現吧:

~# git clone https://github.com/weldpua2008/ansible-nginx.git 
~# cd ansible-nginx 
~# docker run -ti --rm=true -v `pwd`:/ansible-nginx:rw centos:7 /bin/bash ^C 
~# cd ansible-nginx/ 
~/ansible-nginx# docker run -ti --rm=true -v `pwd`:/ansible-nginx:rw centos:7 /bin/bash 

[[email protected] /]# /ansible-nginx/tests/test-on-rpm.sh 
TASK: [ansible-nginx | create document root directory if needed] ************** 
ok: [localhost] 

TASK: [ansible-nginx | Starting nginx service] ******************************** 
failed: [localhost] => {"failed": true} 
msg: no service or tool found for: nginx 

FATAL: all hosts have already failed -- aborting 

PLAY RECAP ******************************************************************** 
      to retry, use: --limit @/root/test.retry 

localhost     : ok=5 changed=2 unreachable=0 failed=1 

也許沒有這個服務?

[[email protected] /]# systemctl enable nginx.service 
[[email protected] /]# systemctl -t service -a 
Failed to get D-Bus connection: No connection to service manager. 
[[email protected] /]# chkconfig --list 

Note: This output shows SysV services only and does not include native 
     systemd services. SysV configuration data might be overridden by native 
     systemd configuration. 

     If you want to list systemd services use 'systemctl list-unit-files'. 
     To see services enabled on particular target use 
     'systemctl list-dependencies [target]'. 

這就是我嘗試在ansible啓動服務:https://github.com/weldpua2008/ansible-nginx/blob/master/tasks/main-centos.yml#L24

- name: Starting nginx service 
    service: name=nginx state=started 
    tags: 
    - nginx 

我係有https://github.com/docker/docker/issues/7459

+0

在你的CentOS 6劇本,它看起來像nginx重啓失敗,因爲該端口已被使用(https://travis-ci.org/weldpua2008/ansible-nginx/jobs/78864352#L3972) - 也許nginx需要以不同的方式重新啓動,或者已經在運行? – ocean

回答

0

這是由以下事實造成的,解決的是多克(正常的「無特權」)的容器沒有權限運行systemd(因爲它要訪問/sys/fs/cgroup文件系統)。

但是,這實際上是因爲Docker容器更喜歡運行一個進程,您嘗試使用它的進程 - 將它們想象爲「一個支持實用程序的Unix進程」,而不是「小型虛擬機」。

你需要一個簡單的Dockerfile從CentOS的一個,它安裝nginx繼承,然後有一個最終CMD,就像這樣:

CMD /usr/sbin/nginx -g "daemon off;" 

提示說明,這裏的官方nginx Dockerfile https://github.com/nginxinc/docker-nginx/blob/7f3ef0927ec619d20181e677c97f991df0d7d446/Dockerfile

+1

我嘗試測試一下,ansible playbook會在裸機服務器或虛擬機內部安裝nginx。 –

+1

我可以看到這是您的回購的目的,編寫和測試一個Ansible腳本(這看起來都不錯:),但TravisCI在Docker容器中運行測試的事實意味着您只能使用它們。 – ocean

+0

我在不同的Ubuntu版本上測試Ansible,但是在CentOs 7上,它無法重新啓動服務:https://github.com/ansible/ansible-modules-core/issues/593#issuecomment-138809881 –

相關問題