resources:
  - name: ansibleRepo
    type: GitRepo
    configuration:
      gitProvider: jefferyfryGithub
      path: jefferyfry/JFrog-Cloud-Installers
pipelines:
  - name: ansible_aws_azure_automation_pipeline
    steps:
      - name: execute_aws_ansible_playbook
        type: Bash
        configuration:
          runtime:
            type: image
            image:
              auto:
                language: java
                versions:
                  - "8"
          integrations:
            - name: ansibleAwsKeys
            - name: ansibleEnvVars
            - name: ansiblePrivateKey
          inputResources:
            - name: ansibleRepo
        execution:
          onStart:
            - echo "Executing AWS Ansible playbook..."
          onExecute:
            - sudo apt-get update
            - sudo apt-get install gnupg2
            - sudo apt-get install software-properties-common
            - sudo apt-add-repository --yes --update ppa:ansible/ansible
            - sudo apt -y --allow-unauthenticated install ansible
            - sudo pip install packaging
            - sudo pip install boto3 botocore
            - cd dependencyState/resources/ansibleRepo
            - echo 'Setting environment variables...'
            - export artifactory_version="$int_ansibleEnvVars_artifactory_version"
            - export xray_version="$int_ansibleEnvVars_xray_version"
            - export artifactory_license1="$int_ansibleEnvVars_artifactory_license1"
            - export artifactory_license2="$int_ansibleEnvVars_artifactory_license2"
            - export artifactory_license3="$int_ansibleEnvVars_artifactory_license3"
            - export master_key="$int_ansibleEnvVars_master_key"
            - export join_key="$int_ansibleEnvVars_join_key"
            - export ssh_public_key_name="$int_ansibleEnvVars_ssh_public_key_name"
            - export cfn_template="$int_ansibleEnvVars_cfn_template"
            - export stack_name="$int_ansibleEnvVars_stack_name"
            - export AWS_ACCESS_KEY_ID="$int_ansibleEnvVars_AWS_ACCESS_KEY_ID"
            - export AWS_SECRET_KEY="$int_ansibleEnvVars_AWS_SECRET_KEY"
            - printenv
            - pwd
            - ls
            - eval $(ssh-agent -s)
            - ssh-add <(echo "$int_ansiblePrivateKey_key")
            - ansible-playbook Ansible/test/aws/playbook.yaml
          onComplete:
            - echo "AWS Ansible playbook complete."
      - name: execute_azure_ansible_playbook
        type: Bash
        configuration:
          runtime:
            type: image
            image:
              auto:
                language: java
                versions:
                  - "8"
          integrations:
            - name: ansibleAzureKeys
            - name: ansibleEnvVars
            - name: ansiblePrivateKey
          inputResources:
            - name: ansibleRepo
        execution:
          onStart:
            - echo "Executing Azure Ansible playbook..."
          onExecute:
            - sudo apt-get update
            - sudo apt-get install gnupg2
            - sudo apt-get install software-properties-common
            - sudo apt-add-repository --yes --update ppa:ansible/ansible
            - sudo apt -y --allow-unauthenticated install ansible
            - sudo pip install packaging
            - sudo pip install msrestazure
            - sudo pip install ansible[azure]
            - cd dependencyState/resources/ansibleRepo
            - echo 'Setting environment variables...'
            - export artifactory_version="$int_ansibleEnvVars_artifactory_version"
            - export xray_version="$int_ansibleEnvVars_xray_version"
            - export artifactory_license1="$int_ansibleEnvVars_artifactory_license1"
            - export artifactory_license2="$int_ansibleEnvVars_artifactory_license2"
            - export artifactory_license3="$int_ansibleEnvVars_artifactory_license3"
            - export master_key="$int_ansibleEnvVars_master_key"
            - export join_key="$int_ansibleEnvVars_join_key"
            - export ssh_public_key="$int_ansibleEnvVars_ssh_public_key"
            - export arm_template="$int_ansibleEnvVars_arm_template"
            - export azure_resource_group="$int_ansibleEnvVars_azure_resource_group"
            - export clientId="$int_ansibleAzureKeys_appId"
            - export clientSecret="$int_ansibleAzureKeys_password"
            - export tenantId="$int_ansibleAzureKeys_tenant"
            - printenv
            - pwd
            - ls
            - eval $(ssh-agent -s)
            - ssh-add <(echo "$int_ansiblePrivateKey_key")
            - az login --service-principal -u "$clientId" -p "$clientSecret" --tenant "$tenantId"
            - ansible-playbook Ansible/test/azure/playbook.yaml
          onComplete:
            - echo "Azure Ansible playbook complete."