4591566 发表于 2018-1-2 16:35:19

ansible playbook 示例

---  - hosts: '{{ hosts }}'
  gather_facts: no
  vars:
  host_links: |
  {% set l = [] %}
  {% for channel in channels|sort(case_sensitive=True, attribute='link') %}
  {%   set _ = l.append(links.ip+' '+channel.link) %}
  {% endfor %}
  {{ l | unique }}
  host_channels: |
  {% set c = [] %}
  {% for channel in channels|sort(case_sensitive=True, attribute='name') %}
  {%   set s = '#' if channel.status == 'disable' else '' %}
  {%   for type in channel.type|sort %}
  {%   set p = '|1' if channel.picture == type else '' %}
  {%   set _ = c.append(s+channel.link+':'+links.port|string()+'|wxcenter|'+channel.name+'|'+type+'|60'+p) %}
  {%   endfor %}
  {% endfor %}
  {{ c }}
  tasks:
  - name: update /etc/hosts
  template: src=hosts.j2 dest=/etc/hosts owner=root group=root mode=0644
  notify:
  - restart svscan
  - name: update /opt/script/channels.list
  template: src=channels.list.j2 dest=/opt/script/channels.list owner=root group=root mode=0644
  notify:
  - delete channel file
  - restart svscan
  handlers:
  - name: delete channel file
  shell: /bin/find /opt/online01/{m3u8,muxer} -name "{{ item.name }}"* | /usr/bin/xargs /bin/rm -rf
  when: item.status == 'disable'
  with_items: "{{ channels }}"
  - name: restart svscan
  command: /sbin/initctl restart svscan
页: [1]
查看完整版本: ansible playbook 示例