Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
how to read all lines from a file in ansible playbook

I have a file called packages.txt which contains a list of packages. I have to read each line of that package.txt through my ansible file rpm.yml. Here is my code

- hosts: myhost
  tasks:

     - name: RPM Filter
       theforeman.foreman.content_view_filter:
         username: "admin"
         password: "admin"
         server_url: "myhost"
         name: "rpm filter"
         organization: "myorg"
         content_view: "My content view"
         filter_type: "rpm"
         package_name: "{{ item }}"
         inclusion: True
       loop:
         - packages.txt


My packages.txt contains these

open-ssh
nginx
grafana
vim

Any help would be appreciated

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

query the lines plugin. For example

    - debug:
        var: item
      loop: "{{ query('lines', 'cat packages.txt') }}"

gives (abridged)

  item: open-ssh
  item: nginx
  item: grafana
  item: vim

See the details about the plugin

shell> ansible-doc -t lookup lines
over 4 years ago · Santiago Trujillo Relatório

0

You will need an additional task to read the file. The simplest way would be to cat the file and register into a variable. Then this variable can be used for the next task.

Something like:

    - name: get contents of package.txt
      command: "cat packages.txt"
      register: _packages

     - name: RPM Filter
       theforeman.foreman.content_view_filter:
         username: "admin"
         password: "admin"
         server_url: "myhost"
         name: "rpm filter"
         organization: "myorg"
         content_view: "My content view"
         filter_type: "rpm"
         package_name: "{{ item }}"
         inclusion: True
       loop: "{{ _packages.stdout_lines }}"
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda