ansibleで値と一致するストレージを無効にする

ansibleで値と一致するストレージを無効にする

これは間違って書かれています。 rhelとepelを除くすべてのリポジトリを無効にしたいと思います。

- name: yum-clean-metadata
  command: yum clean metadata
  args:
    warn: no

- name: Repos disabled if not rhel.repo
  debug: msg={{ lookup('fileglob', '/etc/yum.repo.d/rhel.repo') }}
  yum:
    name: 
    disablerepo: "ora,ol7_latest"

- name: Ensure the yum package index is up to Date
  yum:
    update_cache: yes
    name: '*'
    state: latest

ベストアンサー1

リポジトリファイル自体を操作することに反対しない場合、この操作は/etc/yum.repos.d/*.repoリストで指定されたファイルを除くすべてのファイルの名前を変更する必要がありますallowed_repos

無効にしたいファイルを正確に知っていれば、他の答えはより簡単です。

  - name: Disable extra repositories
    vars:
      allowed_repos:
        - /etc/yum.repos.d/epel.repo
        - /etc/yum.repos.d/rhel.repo
      found_repo_files: []
    block:
      - name: Find all repositories
        find:
          paths: "/etc/yum.repos.d"
          file_type: file
          recurse: no
          patterns: "*.repo"
        register: repos_d

      - name: Compile repository list
        set_fact:
          found_repo_files: "{{ found_repo_files }} + [ '{{ item.path }}' ]"
        loop_control:
          label: "{{ item.path }}"
        with_items:
          - "{{ repos_d.files }}"

      - name: Rename any extra repositories
        when: not ansible_check_mode
        command:
          cmd: "mv {{ item }} {{ item }}.orig"
          removes: "{{ item }}"
        with_items:
          - "{{ found_repo_files | difference(allowed_repos) }}"

おすすめ記事