inventory 清單
[webservers]
servera
serverb
[datebase]
serverc
serverd
[prod:children]
webservers
datebase
ansable.cfg 設
#默認值
[defaults]
#inventory 存放位置
inventory = /home/student/web/inventory
#是否詢問sudo_pass=否
ask_sudo_pass = false
#詢問pass=否
ask_pass = false
#遠端使用者
remote_user= devops
#特權獲得
[privilege_escalation]
#become是的
become=True
#become的方法是sudo
become_method=sudo
#become的使用是root
become_user=root
#become是否詢問密碼否
become_ask_pass=False
[student@workstation web]$ ansible prod --list-hosts
hosts (4):
servera
serverb
serverc
serverd
#測試設定檔是否正確
[student@workstation web]$ ansible --version
ansible [core 2.13.5]
config file = /home/student/web/ansible.cfg
configured module search path = ['/home/student/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /home/student/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.13 (main, Jun 24 2022, 15:32:51) [GCC 8.5.0 20210514 (Red Hat 8.5.0-13)]
jinja version = 3.1.2
libyaml = True
[student@workstation web]$
ansible prod –list-hosts