簡體   English   中英

如何在Amazon Linux EC2中安裝Ansible?

[英]How to install Ansible in Amazon Linux EC2?

我選擇以下Amazon Linux:Amazon Linux AMI 2017.09.1(HVM),SSD卷類型-ami-1a033c7a。 我使用以下命令安裝了Ansible:

sudo pip install ansible, 

它顯示安裝完成。當我運行ansible --version時,它顯示:

ansible 2.4.1.0
  config file = None
  configured module search path = [u'/home/ec2-    
user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-
packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Nov  2 2017, 19:20:38) [GCC 4.8.5     
20150623 (Red Hat 4.8.5-11)]

為什么config file = None 它不應該顯示/etc/ansible/ansible.cfg嗎? 我看不到/etc/ansible/hosts ,甚至看不到文件夾/etc/ansible 我是否安裝正確,文件夾/etc/ansible哪里?

為什么config file = None

因為在運行ansible --version未找到配置文件。

它不應該顯示/etc/ansible/ansible.cfg嗎?

否。它應該顯示實際使用的ansible.cfg

根據文檔,Ansible嘗試在以下位置找到配置文件:

  • ANSIBLE_CONFIG (環境變量)
  • ansible.cfg (在當前目錄中)
  • .ansible.cfg (在主目錄中)
  • /etc/ansible/ansible.cfg

ansible --version將向您顯示所使用的確切路徑。

嚴格來說,最后一點並不總是正確的,因為程序包管理器和虛擬環境管理器可能會導致/etc目錄位於其他位置。

我是否正確安裝

您在安裝過程中沒有提到任何錯誤或警告, ansible --version返回了正確的響應。

沒有理由不相信它已正確安裝。

文件夾/etc/ansible哪里?

它在您的系統上不存在。 沒有默認清單文件,也沒有由安裝包創建的配置文件。

創建一個。

在這里,我自己回答問題。

有多種安裝ansible的方法,然后您會獲得不同的默認設置,具體取決於操作系統。 許多教程只是假設/ etc / ansible中已經有ansible_hosts和ansible.cfg,如果您使用pip安裝ansible,這是不正確的。

實際上,如果使用pip安裝ansible,則在/ etc / ansible中將看不到ansible.cfg和ansible_hosts。 甚至文件夾/ etc / ansible都不存在。 但沒關系,您可以自己創建以下兩個文件:

假設您要將ansible_hosts和ansible.cfg存儲在/ home / ec2-user中,則可以:

echo <remote_host> /home/ec2-user/ansible_hosts
export ANSIBLE_INVENTORY=/home/ec2-user/ansible_hosts
wget https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg
mv ansible.cfg /home/ec2-user/
export ANSIBLE_CONFIG=/home/ec2-user/ansible.cfg

然后如果ansible --version,您將看到

ansible 2.4.1.0
  config file = /home/ec2-user/ansible.cfg
....

並且如果您測試了一個特殊的命令(我的remote_host是ubuntu,所以我使用-u ubuntu,則可以將其更改為您的):

ansible all -m ping -u ubuntu

然后您將看到成功的ping ping remote_host。

這表明ansible確實有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM