先整理几张图
发展趋势
上图
阶段
devops运维开发
代码语言:yml复制
# vim hosts.j2
*
*
{% for host in groups['all'] %}
{{ hostvars[host]['ansible_facts']['default_ipv4']['address'] }} {{ hostvars[host]['ansible_facts']['fqdn'] }}
{{ hostvars[host]['ansible_facts']['hostname'] }}
{% endfor %}
# vim hosts.yml
---
- name: create myhosts
hosts: all
tasks:
- name: template a file /etc/myhosts
template:
src: /home/greg/ansible/hosts.j2
dest: /etc/myhosts
#when: '"dev" in group_names'
when: 'inventory_hostname in groups.dev'
# ansible-playbook hosts.yml