- Ansible Quick Start Guide
- Mohamed Alibi
- 136字
- 2021-07-23 16:37:49
The hostname module
This is another simple module that does the simple job of changing a hostname. To make this module more exciting, we will use some of the playbook features with it. This module takes one input, the new hostname, and changes the hostname of the remote host. We can use the playbook predefined variable, {{ inventory_hostname }}. This variable calls the hostname for the Ansible inventory and uses it with the playbook.
First, we need to change the inventory file to look as follows:
[servers]
server0 ansible_host=192.168.10.10
server1 ansible_host=192.168.10.11
server2 ansible_host=192.168.10.12
Then, we use the following playbook:
- name: change hostname
hostname:
name: "{{ inventory_hostname }}"
After executing the playbook, you can simply test it out using an ad hoc Ansible command:
ansible -m shell -a hostname servers
The result should look as follows:
推薦閱讀
- PowerShell 3.0 Advanced Administration Handbook
- Dreamweaver 8中文版商業案例精粹
- Hands-On Cloud Solutions with Azure
- ROS機器人編程與SLAM算法解析指南
- 自主研拋機器人技術
- 數據挖掘方法及天體光譜挖掘技術
- Spark大數據技術與應用
- 人工智能技術入門
- C++程序設計基礎(上)
- 電氣控制與PLC原理及應用(歐姆龍機型)
- HBase Essentials
- Serverless Design Patterns and Best Practices
- Practical AWS Networking
- 實戰Windows Azure
- Getting Started with Tableau 2019.2