在[Ansible]的Playbook中输出任务清单

只需要加上“–list-tasks”选项即可

从「初次使用Ansible」的GitHub页面借用样例。

- name : Configure webserver with nginx
  hosts: vagrant
  become: True
  vars:
    key_file: /etc/nginx/ssl/nginx.key
    cert_file: /etc/nginx/ssl/nginx.crt
    conf_file: /etc/nginx/sites-available/default
    server_name: localhost
  tasks:
    - name: install nginx
      apt: name=nginx update_cache=yes cache_valid_time=3600

    - name: create derectories for ssl certificates
      file: path=/etc/nginx/ssl state=directory

    - name: copy TLS key
      copy: src=files/nginx.key dest={{ key_file }} owner=root mode=0600
      notify: restart nginx

    - name: copy TLS certificate
      copy: src=files/nginx.crt dest={{ cert_file }}
      notify: restart nginx

    - name: copy nginx config file
      template: src=templates/nginx.conf.j2 dest={{ conf_file }}
      notify: restart nginx

    - name: enable configuration
      file: dest=/etc/nginx/sites-enabled/default src={{ conf_file }} state=link
      notify: restart nginx

    - name: copy index.html
      template: src=templates/index.html.j2 dest=/usr/shaore/nginx/html/index.html mode=0644

  handlers:
    - name: restart nginx
      service: name=nginx state=restarted

输出上述playbook的任务列表如下。

$ ansible-playbook web-tls.yml --list-tasks

  play #1 (vagrant): Configure webserver with nginx TAGS: []
    tasks:
      install nginx TAGS: []
      create derectories for ssl certificates   TAGS: []
      copy TLS key  TAGS: []
      copy TLS certificate  TAGS: []
      copy nginx config file    TAGS: []
      enable configuration  TAGS: []
      copy index.html   TAGS: []

可以明白输出了附加在名字选项上的任务名。

如果没有添加name选项,那么该任务的模块名称(apt或file)将被输出。

使用 `ansible-playbook –start-at-task=””` 命令可以从任意任务开始执行playbook,并确保给它一个名称。

广告
将在 10 秒后关闭
bannerAds