0
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 1 year has passed since last update.

Ansible playbookで日付を扱う

Posted at

ansible-playbookで日付毎に新しいファイルパスを作成する場合はansible_date_time.dateを利用します。
但し、ansible_date_timeを利用する場合はgather_factをtrueにします。ただ日付を使うためにgather_factをtrueにするよりもgather_subsetを利用して日付だけを取得するようにします。

例:

- name: gather date and time only
  setup:
    gather_subset:
      - "date_time"
  when: ansible_date_time is not defined

- name: save result to local directory
  copy:
    content: "{{ result.stdout[1] | replace('show ip interface brief', '') | replace('\\n', '\n') }}"
    dest: "/home/ozawa/outputs/show_ip_interface_brief/{{ ansible_date_time.date }}/{{ inventory_hostname }}.txt"

以上

0
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
0
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?