1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Ansible]Playbook中のタスク一覧を出力する

Last updated at Posted at 2016-11-16

--list-tasks オプションをつけてあげればよい

「初めてのAnsible」GitHubページよりサンプルを拝借

web-tls.yml
- 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 オプションに付けられたタスク名が出力されていることが分かる

name オプションを付けていなかった場合には、そのタスクのモジュール名(aptfile)が出力される

ansible-playbook --start-at-task="<task_name>" で任意のタスクからplaybookを実行できるし、nameは付けるようにしとこう

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?