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

272
Visualizações
Validates arguments passed to ansible-playbook with a defined argument specification

We want to run the following playbook with the yml file - ansible-playbook install_os.yml

The playbook install_os.yml is working well , but now we want to add the validation of the arguments <machine name>,<machine IP>.

As the following:

ansible-playbook install_os.yml --limit RHEL01,73.22.3.44

From my point both arguments should be identify as strings (without verify of valid IP) and between <machine name> to <machine IP>, we should set the , separator

So, is it possible to validate the strings? And exit if one of them or both them are not defined?

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

0

You can access the limit specified in arguments to ansible-playbook with the help of the special variable ansible_limit.

From there on, you can assert the --limit values based on your business needs.

For example:

- hosts: all
  gather_facts: no

  tasks:
    - assert: 
        that: 
          ## We have exactly one comma, separating two hosts
          - ansible_limit | split(',') | length == 2
          ## We have a string before the comma
          - (ansible_limit | split(',')).0 is string
          ## We have a non-empty string before the comma
          - (ansible_limit | split(',')).0 | length > 0
          ## We have a string after the comma
          - (ansible_limit | split(',')).1 is string
          ## We have a non-empty string after the comma
          - (ansible_limit | split(',')).1 | length > 0
          ## 'all', which has a wildcard meaning, 
          ## is not one of the two hosts separated by the comma
          - "'all' not in ansible_limit | split(',')"
          ## We do not have any character having a special meaning in the limit
          ## see: https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html#common-patterns
          - "'@' not in ansible_limit"
          - "':' not in ansible_limit"
          - "'!' not in ansible_limit"
          - "'&' not in ansible_limit"
          - "'*' not in ansible_limit"
      run_once: true

This would probably limit it to the use case you want.
This said, mind that --limit is an existing flag with its own behaviour, so, based on what you are aiming for, you could also be better with an extra parameter passed in command line.

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