· ansible chef inventory

Ansible Chef Inventory Orchestration

If you have used or are using chef for configuration management, chances are that you may have rolled some custom deployment scripts with fog or some other libraries. However, why roll your own when you don’t have to? It’s pretty easy to manage and orchestrate with the dynamic inventory of ansible.

Ansible can handle a few of the common orchestration tasks easily that aren’t possible without custom work:

To get the orchestration of ansible with chef, this script needs to be installed into the inventory directory: https://gist.github.com/tjheeta/f3538c32965575e59bcd

Please note that ansible doesn’t allow colons in the group names, so if you have a runlist of recipes like cookbook1::default, all the hosts with that cookbook will be in group cookbook1__default.

The script will try to autoconfigure by looking for a working knife.rb in various locations. If no working knife.rb is available on the host, please setup a chef.ini in the inventory directory:


It also requires pychef to be installed as a pre-requisite, if your distro doesn’t have it, just use pip.

virtualenv ${VIRT_DIR}
source ${VIRT_DIR}/bin/activate

pip install ansible
pip install pychef

Example deploy:

- name: Run database migrations
  hosts: singleton
    - run_chef

- name: Deploy to all the hosts
  hosts: all:!maintenance
    - run_chef

Example creation and orchestration:

- name: Create AWS resources
  hosts: localhost
  connection: local
  gather_facts: False
  - name: Create security group
      module: ec2_group
      name: test_fw
      description: "test_fw"
      region: "{{aws_region}}"
        - proto: tcp
          type: ssh
          from_port: 22
          to_port: 22
        - proto: all
          type: all
    register: worker_fw

  - name: create instance
      module: ec2
      key_name: test_key
      region: "{{aws_region}}"
      group: [ "default", "test_fw" ]
      instance_type: "{{instance_type}}"
        group: test
        group: test
      exact_count: 1
      image: "{{ami_id}}"
      wait: yes
    register: ec2host

  - add_host: hostname="{{ item.public_ip }}" groupname=test_group
    with_items: ec2host.tagged_instances

  - wait_for: host="{{ item.public_ip }}" port=22 search_regex=OpenSSH delay=10 timeout=300
    with_items: ec2host.tagged_instances

- name: bootstrap chef
  hosts: test_group
  delegate_to: localhost
  sudo: true
    - shell: bundle exec knife bootstrap --sudo  -r 'bootstrap::default' {{ ansible_default_ipv4.address }}

tl;dr - ansible allows orchestration of chef inventory with script https://gist.github.com/tjheeta/f3538c32965575e59bcd

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket