1、playbook的执行文件为YAML语言编写,所以文件名为xxx.yml。YAML语法可以参考https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html#id1 2、下面以安装httpd软件来作讲解 示例playbook: [root@localhost test]# cat httpd.yml --- #文件起始行,也可以省略。但是不建议省略 - hosts: docke...
创建成功,node2上查看 9.yml文件部署haproxy [ansible@node1 ~]$ cat hosts #主机的分组 [balance] node1 [test] node2 [prod] node3 web=http [webserver:children] test prod [webserver:vars] http_port=80 [ansible@node1 ~]$ vim haproxy.cfg.j2 #用魔术变量编辑配置文件 frontend main *:80 ...
1、创建文件实例 1)编辑配置文件 [root@master ~]# cd /etc/ansible/ [root@master ansible]# vim test.yml //固定后缀为yml,一定要注意空格 --- - hosts: testhost user: root tasks: - name: playbook_test shell: touch /tmp/playbook.txt 注意: hosts参数指定了对哪些主机进行参作; user参数指定了...
Templates 允许你使用 Jinja2 模板引擎生成配置文件。 • 示例: - name: Configure Nginx template: src: templates/nginx.conf.j2 dest:/etc/nginx/nginx.conf 模板文件 (templates/nginx.conf.j2): worker_processes{{ ansible_processor_vcpus }};...
1.通过Inventory文件定义主机及主机组变量 当机器数量不多的时候,Ansible操控机器的时候会去Inventory里面获取主机信息, 此时我们就可以将变量传过去,默认Inventory配置文件为/etc/ansible/hosts. playbook文件:variable.yaml --- -hosts: all gather_facts: False ...
vars参数指定了变量,这里指字一个user变量,其值为test ,需要注意的是,变量值一定要用引号引住; user提定了调用user模块,name是user模块里的一个参数,而增加的用户名字调用了上面user变量的值。 (2)执行配置文件 代码语言:javascript 复制 [root@tiejiangSRC1 ansible]# ansible-playbook create_user.ymlPLAY[crea...
在需要被监控的任务(tasks)中定义一个notify,只有当这个任务被执行时,才会触发notify对应的handlers去执行相应操作。例如配置文件被修改后,有可能需要重启程序,此时我们可以配置一个handlers,类似触发器。注意:handlers下的name名称必须要和它对应的notify名称相同!否则不会执行!!
file: # 使用的模块 path: /etc/abc # 模块的动作 state: directory owner: www group: www# 例2:安装部署nginxvim nginx.yaml - hosts: web_grouptasks:- name: 安装nginx yum: name=nginx state=present- name: 复制nginx配置文件 copy: src=/root/ansible/wordpress/nginx.con...
需求又来了, 要修改主机的 httpd 端口为 8080 思路:ansible 主机需要有一份 修改好端口的配置文件,将配置文件推送到被管理主机,然后重启服务。 修改如下: - hosts: test_hosts remote_user: root vars: - package: httpd - service: httpd tasks: - name: install {{ package }} yum: name={{ package ...
下面是一个简单的playbook配置文件 hosts:操作主机,或者主机分组 romote_user:ssh用户名 tasks:在当前主机下执行的任务列表 yum/template/yum/service:ansible模块 -hosts:webserversremote_user:roottasks:-name:ensure apache is at the latest versionyum:name:httpdstate:latest-name:write the apache config filete...