我們需要給docker傳人更多的參數,以便讓systemd在容器中運行:
doker run -it -m -v /sys/foup: /ys/fcgroup: o —v 'pd.'/
sible :/ansible<hash>
容器用systemd啟動,現在我們需要從一個不同的shell命令行連接運行著的容器
Docker exec -it <hash>bash
我的媽呀,為了讓容器運行得更加逼真我們也真是耗盡心力。不過換句話說,用虛擬
機的方式,如VirtualBox,在我看來更加麻煩。當然讀者也許不會這么覺得。現在,我們
可以在容器中運行一個更加復雜的Ansible playbook,如下所示:
- hosts : localhost
vars
http_port : 80
max clients : 200
remote user: root
tasks :
- name: ensure apache is at the latest version
yum: namehttpd state'-latest
- name: write the apache config file
template : src=/srv/httpd. j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running (and enable it at boot)
service : namehttpd state=started enabledyes
handlers :
- name: restart apache
service : namehttpd state=restarted
這個例子在前面的基礎上構建,并且告訴你如何
* 安裝包。
* 編寫一個模板文件。
* 處理一個服務的運行狀態。
%* 格式為非常簡單的YML語法。