I have a Vagrant box with centos 7 where I am creating LXC containers. An Ansible run in the Vagrant box. I create the container with Ansible like this:
- name: Create containers lxc_container: name: localdev_nginx container_log: true template: centos container_config: - 'lxc.network.ipv4 = 192.168.42.110/24' - 'lxc.network.ipv4.gateway = 192.168.42.1' container_command: | yum -y install openssh-server echo "Som*th1ng" | passwd root --stdin ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N "" state: started
This is create the container for me, but after this I can't access to the container from the Ansible. Just if I take the container ssh pubkey to the Vagrant known_hosts like this:
- name: Tell the host about our servers it might want to ssh to shell: ssh-keyscan -t rsa 192.168.42.110 >> /root/.ssh/known_hosts
And if I add the container root password in the Ansible hosts file like this:
[dev-webservers] loc-dev-www1.internavenue.com hostname=loc-dev-www1.internavenue.com ansible_ssh_host=192.168.42.110 ansible_connection=ssh ansible_user=root ansible_ssh_pass=Som*th1ng
I hope it has a better solution, because really bad. How can I do it normally?