ansible에서 copy를 활용하면 jinja2가 적용될 것이라는 기대감이 있다. 파일 확장자명인 j2를 추가해도 동작이 되지 않는다. 자세한 레퍼런스는 아래 정보를 확인한다.
http://docs.ansible.com/template_module.html
즉 아래와 같은 copy task를 활용하면 index.php.j2에서 사용하는 vars(예, {{ ansible_hostname }}, {{ansible_default_ipv4.address }} ) 들을 사용할 수 없다.
- name: Hello World PHP script
copy: src=index.php.j2 dest=/var/www/index.php mode=0664
따라서 아래와 같이 고쳐야 한다.
- name: Hello World PHP script
template: src=index.php.j2 dest=/var/www/index.php mode=0664
참고로, ansible에서 자동으로 생성되는 변수들을 보려면 아래 명령어를 사용한다.
$ ansible -m setup hostname
만약 host inventory file을 따로 사용하면 아래와 같이 사용한다.
$ ansible -m setup -i hosts 127.0.0.1
127.0.0.1 | success >> {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"10.0.3.1",
"172.17.42.1",
"10.0.2.15"
],
"ansible_all_ipv6_addresses": [
"fe80::c4c3:d3ff:fedd:7b42",
"fe80::8855:d1ff:fedb:831e",
"fe80::a00:27ff:fe88:ca6"
],
"ansible_architecture": "x86_64",
"ansible_bios_date": "12/01/2006",
"ansible_bios_version": "VirtualBox",
"ansible_cmdline": {
"BOOT_IMAGE": "/vmlinuz-3.8.0-44-generic",
"quiet": true,
"ro": true,
"root": "/dev/mapper/precise64-root"
},
"ansible_date_time": {
"date": "2014-09-10",
"day": "10",
"epoch": "1410337463",
"hour": "08",
"iso8601": "2014-09-10T08:24:23Z",
"iso8601_micro": "2014-09-10T08:24:23.937363Z",
"minute": "24",
"month": "09",
"second": "23",
"time": "08:24:23",
"tz": "UTC",
"tz_offset": "+0000",
"weekday": "Wednesday",
"year": "2014"
},
"ansible_default_ipv4": {
"address": "10.0.2.15",
"alias": "eth0",
"gateway": "10.0.2.2",
"interface": "eth0",
"macaddress": "08:00:27:88:0c:a6",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "10.0.2.0",
"type": "ether"
},
"ansible_default_ipv6": {},
"ansible_devices": {
"sda": {
"holders": [],
"host": "SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev 02)",
"model": "VBOX HARDDISK",
"partitions": {
"sda1": {
"sectors": "497664",
"sectorsize": 512,
"size": "243.00 MB",
"start": "2048"
},
"sda2": {
"sectors": "2",
"sectorsize": 512,
"size": "1.00 KB",
"start": "501758"
},
"sda5": {
"sectors": "167268352",
"sectorsize": 512,
"size": "79.76 GB",
"start": "501760"
}
},
"removable": "0",
"rotational": "1",
"scheduler_mode": "deadline",
"sectors": "167772160",
"sectorsize": "512",
"size": "80.00 GB",
"support_discard": "0",
"vendor": "ATA"
},
"sr0": {
"holders": [],
"host": "IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)",
"model": "CD-ROM",
"partitions": {},
"removable": "1",
"rotational": "1",
"scheduler_mode": "deadline",
"sectors": "2097151",
"sectorsize": "512",
"size": "1024.00 MB",
"support_discard": "0",
"vendor": "VBOX"
},
"sr1": {
"holders": [],
"host": "IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)",
"model": "CD-ROM",
"partitions": {},
"removable": "1",
"rotational": "1",
"scheduler_mode": "deadline",
"sectors": "2097151",
"sectorsize": "512",
"size": "1024.00 MB",
"support_discard": "0",
"vendor": "VBOX"
}
},
"ansible_distribution": "Ubuntu",
"ansible_distribution_major_version": "12",
"ansible_distribution_release": "precise",
"ansible_distribution_version": "12.04",
"ansible_docker0": {
"active": true,
"device": "docker0",
"id": "8000.000000000000",
"interfaces": [],
"ipv4": {
"address": "172.17.42.1",
"netmask": "255.255.0.0",
"network": "172.17.0.0"
},
"ipv6": [
{
"address": "fe80::8855:d1ff:fedb:831e",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "8a:55:d1:db:83:1e",
"mtu": 1500,
"promisc": false,
"stp": false,
"type": "bridge"
},
"ansible_domain": "",
"ansible_env": {
"HOME": "/home/vagrant",
"LANG": "en_US.UTF-8",
"LC_ALL": "en_US",
"LC_CTYPE": "en_US.UTF-8",
"LOGNAME": "vagrant",
"MAIL": "/var/mail/vagrant",
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games",
"PWD": "/home/vagrant",
"SHELL": "/bin/bash",
"SHLVL": "1",
"SSH_CLIENT": "10.0.2.2 55976 22",
"SSH_CONNECTION": "10.0.2.2 55976 10.0.2.15 22",
"SSH_TTY": "/dev/pts/1",
"TERM": "xterm-color",
"USER": "vagrant",
"_": "/bin/sh"
},
"ansible_eth0": {
"active": true,
"device": "eth0",
"ipv4": {
"address": "10.0.2.15",
"netmask": "255.255.255.0",
"network": "10.0.2.0"
},
"ipv6": [
{
"address": "fe80::a00:27ff:fe88:ca6",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "08:00:27:88:0c:a6",
"module": "e1000",
"mtu": 1500,
"promisc": false,
"type": "ether"
},
"ansible_form_factor": "Other",
"ansible_fqdn": "precise64",
"ansible_hostname": "precise64",
"ansible_interfaces": [
"lo",
"lxcbr0",
"docker0",
"eth0"
],
"ansible_kernel": "3.8.0-44-generic",
"ansible_lo": {
"active": true,
"device": "lo",
"ipv4": {
"address": "127.0.0.1",
"netmask": "255.0.0.0",
"network": "127.0.0.0"
},
"ipv6": [
{
"address": "::1",
"prefix": "128",
"scope": "host"
}
],
"mtu": 65536,
"promisc": false,
"type": "loopback"
},
"ansible_lsb": {
"codename": "precise",
"description": "Ubuntu 12.04 LTS",
"id": "Ubuntu",
"major_release": "12",
"release": "12.04"
},
"ansible_lxcbr0": {
"active": true,
"device": "lxcbr0",
"id": "8000.000000000000",
"interfaces": [],
"ipv4": {
"address": "10.0.3.1",
"netmask": "255.255.255.0",
"network": "10.0.3.0"
},
"ipv6": [
{
"address": "fe80::c4c3:d3ff:fedd:7b42",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "c6:c3:d3:dd:7b:42",
"mtu": 1500,
"promisc": false,
"stp": false,
"type": "bridge"
},
"ansible_machine": "x86_64",
"ansible_memfree_mb": 74,
"ansible_memtotal_mb": 364,
"ansible_mounts": [
{
"device": "/dev/mapper/precise64-root",
"fstype": "ext4",
"mount": "/",
"options": "rw,errors=remount-ro",
"size_available": 76284248064,
"size_total": 83366748160
},
{
"device": "/dev/sda1",
"fstype": "ext2",
"mount": "/boot",
"options": "rw",
"size_available": 173715456,
"size_total": 238787584
}
],
"ansible_nodename": "precise64",
"ansible_os_family": "Debian",
"ansible_pkg_mgr": "apt",
"ansible_processor": [
"Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz",
"Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz"
],
"ansible_processor_cores": 2,
"ansible_processor_count": 1,
"ansible_processor_threads_per_core": 1,
"ansible_processor_vcpus": 2,
"ansible_product_name": "VirtualBox",
"ansible_product_serial": "NA",
"ansible_product_uuid": "NA",
"ansible_product_version": "1.2",
"ansible_python_version": "2.7.3",
"ansible_selinux": false,
"ansible_ssh_host_key_dsa_public": "AAAAB3NzaC1kc3MAAACBAJwR6q4VerUDe7bLXRL6ZPTXj5FY66he+WWlRSoQppwDLqrTG73Pa9qUHMDFb1LXN1qgg0p0lyfqvm8ZeN+98rbT0JW6+Wqa7v0K+N82xf87fVkJcXAuU/A8OGR9eVMZmWsIOpabZexd5CHYgLO3k4YpPSdxc6S4zJcOGwXVnmGHAAAAFQDHjsPg0rmkbquTJRdlEZBVJe9+3QAAAIBjYIAiGvKhmJfzDjVfzlxRD1ET7ZhSoMDxU0KadwXQP1uBdlYVEteJQpUTEsA+7kFH7xhtZ/zbK2afEFHriAphTJmz8GqkIR5CJXh3dZspdk2MHCgxkXl5G/iVPLR9UShN+nsAVxfm0gffCqbqZu3Ridt3JwTXQbiDfXO/a6T/eQAAAIEAlsW/i/dUuFbRVO2zaAKwL/CFWT19Al7+njszC5FCJ2deggmF/NIKJUbJwkRZkwL4PY1HYj2xqn7ImhPSyvdCd+IFdw73Pndnjv0luDc8i/a4JUEfna4rzXt1Y5c24J1pEoKA05VicyCBD2z6TodRJEVEFSsa1s8s2p9x6LxwsDw=",
"ansible_ssh_host_key_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFxsiWE3WImfJcjiWS5asOVoMsn+0gFLU5AgPNs2ATokB7kw00IsB0YGrqClwYNauRRddkYMsi0icJSR60mYNSo=",
"ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDZt46W9slSN3Y6D2f931rijUPCEewhQWmBfGhybuF4qLftfJMuyFcREZkG6UretVI8ZnQn/OMDgbf2DYMzKsRLnz7W5cGy1Mt1pWoG0iCgi2xHzLqOqPYo4mP9/hdZT6pANXapETT55yx8sHAYLAa9NK5Dtyv+QNQ2dUUb1wUTCqgYffLVDgoHvNNDwCwB6biJf6uopqfg2KXvAzcqSa6oaRChJOXjFlM08HebMwkMSzrOXjWbXhFsONy5JuDf3WztCtLMsFrVRHTdDwTh7uL2UQ8Qcky+kP6Wd7G8NlW5RxubYIFpAM0u2SsQIjYOxz+eOfQ8GE3WjvaIBqX05gat",
"ansible_swapfree_mb": 767,
"ansible_swaptotal_mb": 767,
"ansible_system": "Linux",
"ansible_system_vendor": "innotek GmbH",
"ansible_user_id": "vagrant",
"ansible_userspace_architecture": "x86_64",
"ansible_userspace_bits": "64",
"ansible_virtualization_role": "guest",
"ansible_virtualization_type": "virtualbox",
"module_setup": true
},
"changed": false
}
'Ansible-Puppet-Chef' 카테고리의 다른 글
기존의 bash script와 ansible의 차이 (0) | 2014.09.30 |
---|---|
ansible conference 자료 (0) | 2014.09.29 |
[ansible] command 명령 내리기 (0) | 2014.09.10 |
[vagrant] vagrant provision 관련 명령어 찾기 (0) | 2014.07.25 |
[ansible] 멱등성(idempotent) 용어 이해하기 (0) | 2014.07.24 |