0
在Ansible中,我有两个单独的任务来获取redhat 6和7的现有服务列表,它们注册到一个变量,然后我有另一个任务来停止这些服务如果我使用相同的变量,它会被最后一个任务覆盖,所以它不会阻止任何事情。Ansible为几个任务注册字典或动态变量
有没有区分两种结果的方法?但只能使用一项任务来停止服务?我尝试了动态var名称或创建一个字典,但没有工作。
感谢
- name: Get registered services
command: bash -c "chkconfig --list | awk '{print $1}'"
register: loaded_services_{{ansible_distribution_major_version}}
when: ((ansible_os_family == "RedHat") and (ansible_distribution_major_version == "6"))
changed_when: False
tags: test
- name: Get registered services
command: bash -c "systemctl list-unit-files | grep enabled | cut -d. -f1"
register: loaded_services_{{ansible_distribution_major_version}}
when: ((ansible_os_family == "RedHat") and (ansible_distribution_major_version == "7"))
changed_when: False
tags: test
- name: shutdown unnecessary services
service: name={{ item }} enabled=no state=stopped
with_items: "{{ disable_services | intersect(loaded_services_{{ansible_distribution_major_version}}.stdout_lines)}}"
when: ansible_os_family == "RedHat" and ansible_distribution_major_version == "6"
tags:
- harden
- test
ignore_errors: yes
有趣的是与选项一,变量仍然被跳过程序覆盖:(“loaded_services”:“跳过”:true)...选项二将工作没有块(每个使用不同的变量),但这正是我试图避免的 – Kenneth