pkaramol
pkaramol

Reputation: 19332

Use custom configuration file for ansible provisioner

I am trying to provision a machine built with packer, using its ansible provisioner;

Provisioning fails to find some roles which I have set in my custom ansible.cfg file as follows:

[defaults]
stdout_callback = yaml
retry_files_enabled = False
vault_password_file = .vault
roles_path = ./roles

Packer documentation does not indicate a way of passing location to custom ansible.cfg file;

Is there a way around this?

Upvotes: 4

Views: 4278

Answers (2)

Thiago Caiubi
Thiago Caiubi

Reputation: 167

You could use packer's env vars to set the ansible.cfg location instead of moving all the configurations to packer.

"provisioners": [
    {
    "type": "ansible",
    "playbook_file": "ansible/playbooks/install.yml",
    "ansible_env_vars": [ "ANSIBLE_CONFIG=ansible/ansible.cfg" ]
   }
]

Reference: https://docs.ansible.com/ansible/latest/reference_appendices/config.html#the-configuration-file

Upvotes: 8

pkaramol
pkaramol

Reputation: 19332

The problem seems to be solved using ansible environmental vars

e.g.

  "provisioners": [
    {
    "type": "ansible",
    "playbook_file": "ansible/playbooks/install.yml",
    "ansible_env_vars": [ "ANSIBLE_ROLES_PATH=ansible/roles", "ANSIBLE_VAULT_PASSWORD_FILE=ansible/.vault" ]
   },

Upvotes: 1

Related Questions