Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use variables set in preup state inside topology file #1440

Open
patchkez opened this issue Oct 28, 2019 · 0 comments
Open

Use variables set in preup state inside topology file #1440

patchkez opened this issue Oct 28, 2019 · 0 comments

Comments

@patchkez
Copy link

Hello,
we would like to set variables in preup state and use them in topology file.

In this example bellow, we try to retrieve openstack network id dynamically and then use the id in topology file without hardcoding it.
We tried something like this.
PinFile:

cinch:
    topology: jslave_topology.yml
    hooks:
      preup:
        - type: ansible
          name: Get Openstack network ID with most usable IPs
          actions:
            - playbook: get_network_id.yml

jslave_topology file:

---
topology_name: jslave-test
resource_groups:
  - resource_group_name: jslave-group
    resource_group_type: openstack
    resource_definitions:
      - name: {{SERVER_NAME}}
        role: "os_server"
        flavor: "ci.m1.small"
        image: {{IMAGE_NAME}}
        count: 1
        keypair: mykeypair
        networks:
          - {{ DYNAMIC_NETWORK_ID }}
    credentials:
      filename: clouds.yaml
      profile: ci-rhos

get_network_id.yml

---
- name: Get Network ID dynamically
  shell: |
      openstack network list -c ID -c Name -f value |
      egrep 'cci_(10|[4-9])' |
      awk '{print $1}' |
      xargs -n1 openstack ip availability show -f shell |
      awk -F ',' '/ip_version='\''4'\''|^id=/{ if ($0 ~ /^id=/) {split($0,uuid,"="); gsub(/"/,"",uuid[2]);
      printf uuid[2]" "} else { split($5,total,"="); split($6,used,"="); gsub(/'\''/,"",total[2]); gsub(/'\''/,"",used[2]); free=total[2]-used[2]; print free} }' |
      sort -nrk2 |
      cut -f1 -d ' ' |
      head -n1
  environment:
    OS_CLOUD: ci-rhos
  register: dynamic_net
 
- name: set dynamic network id as fact
  set_fact:
    DYNAMIC_NETWORK_ID: "{{ dynamic_net.stdout }}"

We use older linchpin and ansible versions:

venv_linch:
  - linchpin==1.6.1
  - ansible==2.7.6

venv_cinch:
  - cinch==1.2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants