Mitesh The Mouse
2019-09-09 44eee23f4f6b107ad62b92490bbc056f6c4a8bcc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
- name: Fetching list of names available in Content-Views
  shell: >-
    hammer --output cve 
    content-view list 
    --organization "{{ORG}}" | grep Name
  register: content_view_list
  tags:
    - configure_satellite
    - configure_satellite_content_view
 
- name: Creating list fact of names available in Content-Views
  set_fact: 
    content_view_exist: "{{ content_view_exist + [item.split(':')[1].lstrip(' ')]}}"
  loop: "{{content_view_list.stdout_lines}}"
  tags:
    - configure_satellite
    - configure_satellite_content_view
 
- name: Print fact
  debug: var=content_view_exist
 
- name: Creating Content-view if not exist
  command: >-
    hammer content-view create 
    --name "{{CONTENT_VIEW_NAME}}"  
    --organization "{{ORG}}"
  when: CONTENT_VIEW_NAME not in content_view_exist
  tags:
    - configure_satellite
    - configure_satellite_content_view
#######################################
 
- name: Fetching list of enabled Repo IDs from subscription 
  shell: >-
    hammer --output cve  
    repository list 
    --organization "{{ORG}}" |grep Id
  ignore_errors: yes
  register: repo_list
  tags: 
    - configure_satellite
    - configure_satellite_content_view
 
- name: Creating list fact of enabled Repo IDs from subscription 
  set_fact:
    sub_repos_name_exist: "{{ sub_repos_name_exist + [ item.split(':')[1].lstrip(' ')] }}"
  loop: "{{repo_list.stdout_lines}}"
  when: repo_list is defined
  tags:
    - configure_satellite
    - configure_satellite_content_view
 
# - name: list of enabled repo ID in subscription
#   debug: var=sub_repos_name_exist
######################################
 
- name: Fetching list of existing Repository IDs from Content-View
  shell: >-
    hammer --output cve 
    content-view list 
    --organization "{{ORG}}" 
    --name  "{{CONTENT_VIEW_NAME}}" |grep "Repository IDs"
  ignore_errors: yes
  register: content_view_repos_list
  tags:
    - configure_satellite
    - configure_satellite_content_view
 
- name: Creating list fact of existing Repository IDs from Content-View
  set_fact:
    content_view_repos_exist: "{{ content_view_repos_exist + [item.lstrip(' ')]}}"
  loop: "{{ content_view_repos_list.stdout_lines[0].split(':')[1].split(',') }}"
  when: content_view_repos_list is defined
  tags:
    - configure_satellite
    - configure_satellite_content_view
 
# - name: list existing repos in content view 
#   debug: var=content_view_repos_exist
 
- name: adding repo to content-view
  command: >-
      hammer content-view add-repository
      --organization "{{ORG}}"
      --name "{{CONTENT_VIEW_NAME}}"
      --repository-id  "{{ item }}"
  when: item  not in content_view_repos_exist 
  loop: "{{ sub_repos_name_exist }}"
  tags: 
    - configure_satellite
    - configure_satellite_content_view
#######################
- name: Fetching list of published versions of Content-View
  shell: >-
    hammer --output cve 
    content-view version list 
    --organization "{{ORG}}" 
    --content-view "{{CONTENT_VIEW_NAME}}" |grep Version
  ignore_errors: yes
  register: published_versions
  tags:
    - configure_satellite
    - configure_satellite_content_view
 
- name: Creating facts list of published versions of Content-View
  set_fact:
    published_content_view_versions: "{{ published_content_view_versions + [  item.split(':')[1].strip(' ') | int  ] }}"
  loop: "{{ published_versions.stdout_lines }} "
  when: published_versions is defined
  tags:
    - configure_satellite
    - configure_satellite_content_view
 
 
- name: Publishing content-view
  command: >-
      hammer content-view publish
      --organization "{{ORG}}"
      --name "{{CONTENT_VIEW_NAME}}"
      --async
  when: published_content_view_versions | length == 0
  tags: 
    - configure_satellite
    - configure_satellite_content_view