Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Passando variável entre stages

A variável ${SERVER_IP} funciona no stage: Apply; Porém no stage: Setup ela está em branco;

Não sei onde estou errado? tem alguma forma melhor de passar os valores entre os stage?

image: 
  name: hashicorp/terraform:1.1.4
  entrypoint: [""]

stages:
- Plan
- Apply
- Setup
- PlanDetroy
- Destroy

cache:
  paths:
    - tfplan
    - SERVER_IP
    - server_config
    - WINDOWS_PASSWORD
...
Apply:
  stage: Apply
  script:
      - terraform init -migrate-state
      - terraform apply tfplan
      - terraform output SERVER_IP > SERVER_IP
      - terraform output SERVER_CONFIG > server_config
      - echo ${SERVER_IP}
  except:
    variables:
      - $DESTROY == "true"
  when: manual
  allow_failure: false

Setup:
  stage: Setup
  image: alpine
  script:
    - ls -lha
    - apk add ansible openssh-client
    - apk update && apk add bash
    - ansible --version
    - cd ansible-windows    
    - ls -lha
    - echo "[host]" >> hosts
    - echo ${SERVER_IP} >> hosts
    - echo "[host:vars]" >> hosts
    - echo "ansible_connection=winrm" >> hosts
    - echo "ansible_ssh_port=5986" >> hosts
    - echo "ansible_user=Administrator" >> hosts
    - echo "ansible_password=WINDOWS_PASSWORD >> hosts
    - echo "ansible_winrm_server_cert_validation=ignore" >> hosts
    - echo "ansible_winrm_scheme=https" >> hosts
    - cat hosts
    - ls -lha
    - ansible-playbook -i hosts main.yml
  when: manual
  allow_failure: false          
1 resposta
solução!

Segundo a documentação, para passar de um valores de um job para outro é para utilizar o "artifacts" exemplo aqui: https://docs.gitlab.com/ee/ci/variables/

Plan:
  stage: Plan
  script:
...
  - echo "WINDOWS_PASSWORD2=$SERVER" >> plan.env
  artifacts:
    reports:
      dotenv: plan.env