infra/provision.yml
2019-07-19 11:02:08 +04:00

70 lines
2.0 KiB
YAML

---
- name: check input parameters
hosts: localhost
gather_facts: false
tags: always
tasks:
- fail: msg="env_name should be set"
when: env_name is not defined
- fail: msg="stack_name should be set"
when: stack_name is not defined
- name: provisioning PVE nodes
hosts: localhost
gather_facts: false
roles:
- {role: prepare-config, tags: [ ]}
- {role: pve, tags: [ ]}
- {role: lxc, tags: [ ]}
- {role: inventory, bootstrap: yes, tags: [ ]}
tags: [ provision ]
- name: prepare nodes
hosts: stack
gather_facts: false
# cannot use free strategy due usage of add_host after
# NICs reconfiguration
#strategy: free
pre_tasks:
- meta: end_play
when: destroy_all is defined and destroy_all|bool
- name: check prereqs is already installed
shell: rpm -qa | grep -q python-modules-distutils
register: prereqs_found
changed_when: false
- name: install prereqs
raw: 'apt-get update && apt-get install -qy python2.7\(distutils\)'
when: (destroy_all is not defined or not destroy_all) and (prereqs_found.rc != 0)
- name: gather facts
setup:
when: destroy_all is not defined or not destroy_all
roles:
- {role: prepare-config, tags: [ ]}
- {role: common, tags: [ ]}
tags: [ prepare ]
- name: put ssh host keys to all nodes
hosts: stack
gather_facts: false
strategy: free
pre_tasks:
- meta: end_play
when: destroy_all is defined and destroy_all|bool
tasks:
- name: put keys to known hosts
copy:
src: ".tmp/{{ stack_name }}.known_hosts"
dest: "/etc/openssh/ssh_known_hosts"
owner: root
group: root
mode: 0644
- name: register nodes in /etc/hosts
lineinfile:
path: /etc/hosts
regexp: ".*{{ item }}$"
line: "{{ hostvars[item].ansible_default_ipv4.address }} {{ item }}"
state: present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: "{{ play_hosts }}"
tags: [ prepare ]