قم بتشغيل المهمة فقط إذا كان المضيف لا ينتمي إلى مجموعة

StackOverflow https://stackoverflow.com//questions/21008083

  •  21-12-2019
  •  | 
  •  

سؤال

أود أن أتمكن من تشغيل مهمة غير قابلة للتطبيق فقط إذا كان مضيف دليل التشغيل الحالي لا ينتمي إلى مجموعة معينة.في رمز شبه زائف:

- name: my command
  command: echo stuff
  when: "if {{ ansible_hostname }} not in {{ ansible_current_groups }}"

كيف أفعل هذا?

هل كانت مفيدة؟

المحلول

إليك طريقة أخرى للقيام بذلك:

giveacodicetagpre.

group_names هو متغير سحري كما هو موثق هنا: http://docs.ansible.com/playbooks_variables.html#magic-variables-and-how-to-Access-Information-Apout-About-About- Wearshosts :

group_names هي قائمة (صفيف) لجميع المجموعات المضيف الحالي قيد التشغيل.

نصائح أخرى

يمكنك تعيين متغير تحكم في ملفات فارس الموجودة في group_vars/ أو مباشرة في ملف المضيفين مثل هذا:

[vagrant:vars]
test_var=true

[location-1]
192.168.33.10 hostname=apollo

[location-2]
192.168.33.20 hostname=zeus

[vagrant:children]
location-1
location-2

وتشغيل المهام مثل هذا:

- name: "test"
  command: "echo {{test_var}}"
  when: test_var is defined and test_var
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top