Ansible:通过HTTP安装tarball

时间:2014-11-12 10:14:52

标签: http installation ansible

我想扩展我的ansible playbook来安装/验证phantomjs和wkhtmltopdf安装到我的Debian 7机器上。这两个程序都可以通过HTTP作为打包的tarball使用。我知道get_url模块,但它没有解压缩东西,如果我添加一些shell命令来解压缩和移动二进制文件,我怀疑每次运行ansible时,tarball都会被下载,解压缩并再次移动,导致不必要的网络流量。

我该如何解决这个问题?我应该使用apt命令创建一个.deb文件并运行它,还是应该创建一个新的ansible模块来安装tarball,还是有些东西我可以忽略?

2 个答案:

答案 0 :(得分:10)

如果您下载特定版本(例如foo_1.2.3.tar.gz而非foo_latest.tar.gz),则可以通过保留下载的tarball来执行此操作:

- name: Gets tarball
  sudo: yes
  sudo_user: "{{ deploy_user }}"
  get_url:
    url="http://some.host/some_tarball-{{ tarball_version }}.tar.gz"
    dest="/home/{{ deploy_user }}/"
  register: new_archive

- name: Unarchive source
  sudo: yes
  sudo_user: "{{ deploy_user }}"
  unarchive:
    src="/home/{{ deploy_user }}/some_tarball-{{ tarball_version }}.tar.gz"
    dest="/home/{{ deploy_user }}/app/"
    copy=no
  when: new_archive|changed

根据您的环境更改变量。

答案 1 :(得分:2)

您还可以使用unarchive模块直接从HTTP源解压缩tar文件。

using System; using System.Security.Cryptography.X509Certificates; namespace UseCertificateInAzureWebsiteApp { class Program { static void Main(string[] args) { X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); certStore.Open(OpenFlags.ReadOnly); X509Certificate2Collection certCollection = certStore.Certificates.Find( X509FindType.FindByThumbprint, // Replace below with your cert's thumbprint “E661583E8FABEF4C0BEF694CBC41C28FB81CD870”, false); // Get the first cert with the thumbprint if (certCollection.Count > 0) { X509Certificate2 cert = certCollection[0]; // Use certificate Console.WriteLine(cert.FriendlyName); } certStore.Close(); } } }

有关unarchive模块的更多信息,请参阅文档http://docs.ansible.com/ansible/unarchive_module.html

相关问题