Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
Valida los argumentos pasados a ansible-playbook con una especificación de argumento definida

Queremos ejecutar el siguiente libro de jugadas con el archivo yml : ansible-playbook install_os.yml

El libro de playbook install_os.yml está funcionando bien, pero ahora queremos agregar la validación de los argumentos <machine name>,<machine IP> .

Como el seguiente:

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

Desde mi punto, ambos argumentos deben identificarse como cadenas (sin verificar la IP válida) y entre <machine name> a <machine IP> , debemos establecer , separador

Entonces, ¿es posible validar las cadenas? ¿Y salir si uno de ellos o ambos no están definidos?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede acceder al límite especificado en los argumentos de ansible-playbook con la ayuda de la variable especial ansible_limit .

A partir de ahí, puede assert los valores --limit en función de las necesidades de su negocio.

Por ejemplo:

 - 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

Esto probablemente lo limitaría al caso de uso que desee.
Dicho esto, tenga en cuenta que --limit es un indicador existente con su propio comportamiento, por lo que, en función de lo que busca, también podría ser mejor con un parámetro adicional pasado en la línea de comandos .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!