Installing config-cli on Red Hat/CentOS 7 using Ansible

configTutorialsLeave a Comment

Config Command Line Interface (config-cli) is a powerful tool to pull your configuration files securely from Config servers. Here’s how you can install it in a Linux-based machine.

Here’s how to setup config-cli on Red Hat/CentOS 7 using Ansible. config-cli is Config’s command line utility, which is used to pull configuration files from Config to your machine.

  1. Create the Ansible playbook. Let’s call the file config-cli.yml. Facts are not used so fact gathering can be disabled.
    - hosts: all
      gather_facts: no
  2. To install config-cli, you need your Config API key. You can find your API key by going to your Profile page or your Command Line Tool page.
  3. Create the variables section that contains the base installation directory and the API key. For this example, we will use /opt as our base directory.
    vars:
    base_dir: /opt
    key: MY_API_KEY
  4. config-cli requires Java 8. We also need to unzip config-cli.zip so let’s install unzip as well.
    tasks:
    - name: "yum install unzip"
      yum: name=unzip state=latest

    - name: "yum install JRE"
      yum: name=java-1.8.0-openjdk-headless state=latest
  5. Download config-cli.zip to the base directory.
    - name: "download config-cli.zip"
      get_url:
    url: https://api.configapp.com/v1/user/downloadcli
    dest: "{{ base_dir }}/config-cli.zip"
    headers: apiKey:{{ key }}
  6. Unzip config-cli.zip. This will create a config-cli directory with 3 files: config-cli.jar, config-cli.bat, and config-cli.sh.
    - name: "unzip config-cli"
      unarchive:
    src: "{{ base_dir }}/config-cli.zip"
    dest: "{{ base_dir }}"
    remote_src: yes
    creates: "{{ base_dir }}/config-cli/"
  7. chmod config-cli.sh and make it executable.
    - name: "chmod config-cli.sh"
      file:
    path: "{{ base_dir }}/config-cli/config-cli.sh"
    mode: "u+x"
  8. The playbook is now complete. Now let’s run it using ansible-playbook. Use the –limit option if you wish to target a specific set of machines.
    ansible-playbook config-cli.yml
  9. You should now be ready to run config-cli. The complete deploypull command is specific to your setup. It will look something like this.
    /opt/config-cli/config-cli.sh deploypull -system MY_SYSTEM -app MY_APP -module MY_MODULE -env MY_ENV -version MY_VERSION

    If you don’t specify -version, the latest version will be pulled.

  10. For convenience, you can copy paste the config-cli command from the web interface. Pick the version you want, click Deploy, and select Pull.
    Copy and Paste config-cli command from Config
  11. Here’s the complete config-cli.yml playbook.
    - hosts: all
      gather_facts: no
    
    vars:
    base_dir: /opt
    key: MY_API_KEY
    
    tasks:
    - name: "yum install unzip"
      yum: name=unzip state=latest
    
    - name: "yum install JRE"
      yum: name=java-1.8.0-openjdk-headless state=latest
    
    - name: "download config-cli.zip"
      get_url:
    url: https://api.configapp.com/v1/user/downloadcli
    dest: "{{ base_dir }}/config-cli.zip"
    headers: apiKey:{{ key }}
    
    - name: "unzip config-cli"
      unarchive:
    src: "{{ base_dir }}/config-cli.zip"
    dest: "{{ base_dir }}"
    remote_src: yes
    creates: "{{ base_dir }}/config-cli/"
    
    - name: "chmod config-cli.sh" 
      file:
    path: "{{ base_dir }}/config-cli/config-cli.sh"
    mode: "u+x"
    
    

Leave a Reply

Your email address will not be published. Required fields are marked *