我有以下文件:roles / homepage / templates / vhost_443.conf.j2
< VirtualHost *:443> ServerName {{vhost_name}} {%if vhost_aliases定义为%} {%for vhost_alias in …
我最终选择的解决方案是添加标签 update_vhost 到我想要运行的特定任务 roles/homepage/tasks/main.yml 。所以在
update_vhost
roles/homepage/tasks/main.yml
... - name: create ssl vhost template: src: vhost_443.conf.j2 dest: "/etc/apache2/sites-available/{{ vhost_name }}_443.conf" notify: restart apache tags: ['vhostconfig', 'update_vhost'] ...
现在当我想运行我运行的特定任务时 ansible-playbook playbooks/webapps/homepage.yml --tags "update_vhost" 仅运行该任务。
ansible-playbook playbooks/webapps/homepage.yml --tags "update_vhost"
如果要将roles / homepage / tasks / main.yml保留为一个文件,则可能需要将逻辑分成块。创建一个变量 的 网页运行 强>
如果要运行整个角色,请设置homepage-run:full
如果要运行vhost更新,请设置homepage-run:vhost
- block: - name: Run homepage setup part 1 - task1 - task2 - task3 when: homepage-run == "full" - block: - name: Run vhost setup - name: create ssl vhost template: src: vhost_443.conf.j2 dest: "/etc/apache2/sites-available/{{ vhost_name }}_443.conf" notify: restart apache tags: - vhostconfig when: ( homepage-run == "full" ) or ( homepage-run == "vhost" ) - block: - name: Run homepage setup part 2 - task1 - task2 - task3 when: homepage-run == "full"