Skip to content

allanhung/pypillar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pypillar

The purpose of the project is to provide an easy way to setup variable in ansible.

How to install

pip install git+https://github.com/allanhung/pypillar.git

Configuration

The action_plugins and vars_plugins configuration are required for the pypillar, cache plugin is optional.

export pypillar_location=$(python -c "import os,pypillar; print(os.path.dirname(pypillar.__file__))")

cat > ansible.cfg <<EOF
[defaults]
gathering=smart
fact_caching=jsonfile_pillar
fact_caching_connection=/tmp/ansible_facts
fact_caching_timeout=7200
action_plugins = $pypillar_location/plugins/actions
cache_plugins = $pypillar_location/plugins/caches
vars_plugins = $pypillar_location/plugins/vars
# using ":" to spearate multi path
library = $pypillar_location/modules
EOF

Test if it works.

cat > localhost << EOF
[local]  
localhost ansible_connection=local
EOF

mkdir -p pillar
mkdir -p inventory/test/pillar
cp localhost inventory/test/

cat > inventory/test/pillar/vars.yml << EOF
test_message:
  default:
    foo: bar_from_inventory

test_list:
  hostname:
    localhost:
      - foo_from_inventory
EOF

cat > pillar/vars.yml << EOF
test_message:
  default:
    foo: bar

test_list:
  hostname:
    localhost:
      - foo
EOF

cat > pillar_playbook.yml << EOF
- name: pillar test
  hosts: all
  pre_tasks:
    - pillar: {}
  tasks:
    - debug:
        var: pillar
EOF

# modify your host setting in example
ansible-playbook -i localhost pillar_playbook.yml
ansible-playbook -i inventory/test/localhost pillar_playbook.yml

How it work

 .
 ├── inventory
 │   ├── folder1
 │   │   ├── hosts
 │   │   └── pillar
 │   │       └── vars.yml
 │   └── folder2
 │       ├── hosts
 │       └── pillar
 │           └── vars.yml
 ├── pillar
 │   ├── vars.yml
 
 ansible-playbook -i inventory/folder1/hosts site.yml

This will paser file in ./pillar first and then paser file in ./inventory/pillar. If there are duplicate keys, these keys will replace by key in ./inventory/pillar.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages