Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Ansible Cloud Builder

This builder is used to run ansible-playbooks or single Ansible commands.


To execute Ansible command it need invetory which can be passed as parameters or as file inside git repository. Playbook can also be stored in git repository.

Single Ansible module execution

Gather facts from remote host and print hostname:

- name: '$PROJECT_ID/ansible'
  entrypoint: '/usr/bin/ansible'
  - all
  - -i
  - -m
  - setup
  - -a
  - filter=ansible_hostname

Playbook execution

Hosts file and the playbook must be stored in your git repository that is cloned by the builder. In this example both host file and playbook file stored in repository root directory:

- name: '$PROJECT_ID/ansible'
  - -i
  - hosts
  - deploy.yaml


Ansible requires SSH access to remote servers which is usually done with SSH key. This is an example of how execute playbook on servers secured with SSH key and stored in Cloud KMS (read here how to encrypt data). The key is stored in workspace directory to be passed between steps without using shared directory.

# Decrypt ssh key
- name:
  - kms
  - decrypt
  - --ciphertext-file=id_rsa.enc
  - --plaintext-file=id_rsa
  - --location=global
  - --keyring=[KEYRING-NAME]
  - --key=[KEY-NAME]
# Give correct permissions to ssh key
- name: '$PROJECT_ID/ansible'
  entrypoint: 'sh'
  - -c
  - "chmod 400 id_rsa"
# Deploy configurations
- name: '$PROJECT_ID/ansible'
  - -i
  - hosts
  - deploy.yaml
You can’t perform that action at this time.