我们需要给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语法。