Search code examples
ansiblecopyfileserver

Use remote file server as data source in ansible


I am trying to use my file server in my local network as source for the rpm-packages I want to install later on the remote machine in the playbook.

For this I am using a simple apache web server where I have stored my packages under /var/www/httml/packages/list-of-packages

I think that it is possible to declare the ip of your file server with the equivalent hostname somewhere in a file and use that later in a playbook but I can not remember how exactly like

At the end it should be looking like this:

src: {file-server}/packages/airtame/airtame.rpm

Solution

  • I would guess you are looking at the fact that the package name of the yum module of ansible allows you to either:

    • use a package name
    • use an URL to the package
    • use a local path to file to the package

    name: A package name or package specifier with version, like name-1.0.
    If a previous version is specified, the task also needs to turn allow_downgrade on. See the allow_downgrade documentation for caveats with downgrading packages.
    When using state=latest, this can be '*' which means run yum -y update.
    You can also pass a url or a local path to a rpm file (using state=present). To operate on several packages this can accept a comma separated string of packages or (as of 2.0) a list of packages.

    Source: https://docs.ansible.com/ansible/latest/modules/yum_module.html#parameters, emphasis mine.

    From the examples:

    - name: install the nginx rpm from a remote repo
      yum:
        name: http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
        state: present
    
    - name: install nginx rpm from a local file
      yum:
        name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
        state: present
    

    Source: https://docs.ansible.com/ansible/latest/modules/yum_module.html#examples