Ansible-playbook "Update Content Views" using variables

Update Content Views

I have a complex set of content views and repositories.
I wanted to use ansible to cycle through the content views and repositories assign the appropriate repositories to the content views.

I tried to loop through each repository, but only the final repository in the loop was added to the content view, any previous repositories are removed using this method.
This is a simplified version of my data and code.

      - { name: "cv_GROUPA", composite: false }
      - { name: "cv_GROUPB", composite: false }
      - { name: "cv_GROUPC", composite: false }

  - { name: "EPEL 6 - x86_64" , product: "EPEL 6" ,label: "EPEL_6", content_type: "yum" , content_view: "cv_GROUPA", url: "" }
  - { name: "EPEL 7 - x86_64" , product: "EPEL 7" ,label: "EPEL_7", content_type: "yum" , content_view: "cv_GROUPA", url: "" }
  - { name: "EPEL 8 - x86_64" , product: "EPEL 8" ,label: "EPEL_8", content_type: "yum" , content_view: "cv_GROUPC", url: "" }

- name: "Update Content Views"
    server_url: "{{ my_server_url  }}"
    username: "{{  my_userid }}"
    password: "{{ my_secret }}"
    organization: "{{ my_org }}"
    name: "{{ item.content_view }}"
      - name: "{{ }}" 
        product: "{{ item.product }}"         
    - "{{ my_repository }}"

Any idea how I should do this?


when you call theforeman.foreman.content_view, you need to pass all repositories in one run, as otherwise each loop iteration will modify the CV and only set it to contain the one repository of that loop iteration (as you see now).

Your intent is to have a list of repositories, and then have each of them also indicate which CV it should go into? That might be a bit complicated to express with Ansible.

1 Like