Using host resources
It's not always practical or convenient to use DNS to map your machine names to IP addresses, especially in cloud infrastructures, where those addresses may change all the time. However, if you use entries in the /etc/hosts
file instead, you then have the problem of how to distribute these entries to all machines and keep them up to date.
Here's a better way to do it; Puppet's host resource type controls a single /etc/hosts
entry, and you can use this to map a hostname to an IP address easily across your whole network. For example, if all your machines need to know the address of the main database server, you can manage it with a host
resource.
How to do it...
Follow these steps to create an example host
resource:
- Modify your
site.pp
file as follows:node 'cookbook' { host { 'packtpub.com': ensure => present, ip => '83.166.169.231', } }
- Run Puppet:
[root@cookbook ~]# puppet agent -t Info: Caching catalog for cookbook.example.com Info: Applying configuration version '1413781153' Notice: /Stage[main]/Main/Node[cookbook]/Host[packtpub.com]/ensure: created Info: Computing checksum on file /etc/hosts Notice: Finished catalog run in 0.12 seconds
How it works...
Puppet will check the target
file (usually /etc/hosts
) to see whether the host entry already exists, and if not, add it. If an entry for that hostname already exists with a different address, Puppet will change the address to match the manifest.
There's more...
Organizing your host resources into classes can be helpful. For example, you could put the host resources for all your DB servers into one class called admin::dbhosts
, which is included by all web servers.
Where machines may need to be defined in multiple classes (for example, a database server might also be a repository server), virtual resources can solve this problem. For example, you could define all your hosts as virtual in a single class:
class admin::allhosts { @host { 'db1.packtpub.com': tag => 'database' ... } }
You could then realize the hosts you need in the various classes:
class admin::dbhosts { Host <| tag=='database' |> } class admin::webhosts { Host <| tag=='web' |> }
- Hands-On Internet of Things with MQTT
- Getting Started with Oracle SOA B2B Integration:A Hands-On Tutorial
- Implementing Oracle API Platform Cloud Service
- 計算機網絡安全
- 數據庫系統原理及應用教程(第5版)
- JavaScript典型應用與最佳實踐
- 水下無線傳感器網絡的通信與決策技術
- Godot Engine Game Development Projects
- Salesforce Advanced Administrator Certification Guide
- ESP8266 Robotics Projects
- 一步步寫嵌入式操作系統
- 貫通開源Web圖形與報表技術全集
- 數據要素:全球經濟社會發展的新動力
- Web璀璨:Silverlight應用技術完全指南
- 自適應學習:人工智能時代的教育革命