0

I am working on a ansible role to automate the installation of vertica. The role is running on a 3 node cluster . I am stuck in 2 places.

  1. I am trying to run the below command, I want to pass the hosts from my inventory of a group, I have passed run_once which will run only on 1st host ( which is what i want) but how to pass all the 3 hosts , like --hosts xx.xxx.xx.xx,xx.xxx.xx.xx,xx.xxx.xx.xx how can i achieve that?

  2. I want ansible to use the pem key i pass for installing vertica. Where should the key be stored.

    - name: Install vertica
      command: /opt/vertica/sbin/install_vertica --hosts x.xx.xx.xx,xx.xxx.xx.xx,xx.xxx.xx.xx --rpm /opt/vertica-{{ vertica_version }}.x86_64.RHEL6.rpm --dba-user-password-disabled --point-to-point --data-dir /vertica/data --ssh-identity x.pem
      when: vertica_already_installed|failed
      run_once: True
      become: yes
    

Looking for suggestions!

Thanks in advance!

larsks
  • 277,717
  • 41
  • 399
  • 399
user_01_02
  • 711
  • 2
  • 15
  • 31

1 Answers1

1

I am trying to run the below command, I want to pass the hosts from my inventory of a group...

Ansible provides you with the groups variable. This is a dictionary the keys of which are group names are the values are lists of hosts in each group. So for example if you have a group named vertica_servers, you could write something like this:

- name: Install vertica
    command: /opt/vertica/sbin/install_vertica --hosts ','.join(groups.vertica_servers) ...

I want ansible to use the pem key i pass for installing vertica. Where should the key be stored?

It sounds like you have an ssh private key, and this will be used by the install_vertica command to access the hosts in your cluster. You'll need to start by making that private key available on the remote host on which you're running the install_vertica command. You could do that with a copy task:

- name: install private key
  copy:
    src: "{{ private_key_file }}"
    dest: "/root/.ssh/vertica_key.pem"
    mode: "0400"
    owner: root
    group: root

And then pass that path to your install_vertica command:

- name: Install vertica
    command: /opt/vertica/sbin/install_vertica --hosts ','.join(groups.vertica_servers) --ssh-identity /root/.ssh/vertica_key.pem

This assumes that you have set private_key_file to the path to the key on your local system.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Sorry, let me frame my question in a different way, the above command uses the key to login to the other nodes in the cluster to install vertica. So i would like to know how to use the pem key in ansible to achieve this ? if i run manually i give the path of the key where it is stored in host1. So basically its running the above command from host1 but from host1 using the pem key it needs to connect to other 2 hosts and install vertica – user_01_02 Apr 05 '19 at 19:13
  • Where is the key stored *right now*, before you run ansible? Do you have it locally? Is it already installed on the remote host? – larsks Apr 05 '19 at 19:18
  • I am running my ansible command from my dev machine and its logging into the servers using the id_rsa key . i have copied the id_rsa.pub in all 3 nodes in ~/.ssh/authorized_keys. yes i have the key locally in ~/.ssh/x.pem – user_01_02 Apr 05 '19 at 19:20