Created
March 20, 2024 10:07
-
-
Save kraeml/f27391f29bfc9451dc4212d23bd3d2ad to your computer and use it in GitHub Desktop.
Ansible bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Erstellen von LXC Maschinen | |
hosts: lokal | |
vars: | |
lxc_containers: | |
- ansible-lxc | |
- db2 | |
- web | |
- informaticker | |
tasks: | |
- name: Erstelle LXC Maschinen | |
become: true | |
lxc_container: | |
name: "{{ item }}" | |
state: started | |
loop: "{{ lxc_containers }}" | |
register: ansible_lxc_container | |
- debug: | |
var: item | |
loop: "{{ ansible_lxc_container['results'] }}" | |
- name: Netzwerkdienste neu starten | |
become: true | |
service: | |
name: "{{ item }}" | |
state: restarted | |
loop: | |
- lxc-net | |
#- systemd-resolved | |
#- systemd-networkd | |
- name: DHCP Leas erneuern | |
become: true | |
shell: "lxc-attach {{ item }} -- dhclient eth0" | |
loop: "{{ lxc_containers }}" | |
- name: Erstelle LXC Maschinen und sammle die Daten wie IPv4-Addr | |
become: true | |
lxc_container: | |
name: "{{ item }}" | |
state: started | |
loop: "{{ lxc_containers }}" | |
register: ansible_lxc_container | |
- debug: | |
var: item | |
loop: "{{ ansible_lxc_container['results'] }}" | |
- name: "Inventory aus template" | |
template: | |
src: lxc_inventory.j2 | |
dest: lxc_inventory_template | |
- name: Erstelle lxc_inventory | |
copy: | |
dest: lxc_inventory | |
content: | | |
[lxc] | |
[lxc:vars] | |
- name: Hosteinträge | |
lineinfile: | |
path: lxc_inventory | |
insertbefore: [lxc:vars] | |
regexp: "^{{ item.lxc_container.name }} ansible_host={{ item.lxc_container.ips[0] }}" | |
line: "{{ item.lxc_container.name }} ansible_host={{ item.lxc_container.ips[0] }}" | |
loop: "{{ ansible_lxc_container['results'] }}" | |
- name: Gruppenvariable anhängen | |
blockinfile: | |
path: lxc_inventory | |
insertafter: [lxc:vars] | |
block: | | |
ansible_user=ubuntu | |
ansible_password=ubuntu | |
ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" | |
ansible_become_pass=ubuntu | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[lxc] | |
{# Hier ist die Laufvariable host nicht item wie im Playboook #} | |
{% for host in ansible_lxc_container['results'] %} | |
{{ host.lxc_container.name }} ansible_host={{ host.lxc_container.ips[0] }} | |
{% endfor %} | |
[lxc:vars] | |
ansible_user=ubuntu | |
ansible_password=ubuntu | |
ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" | |
ansible_become_pass=ubuntu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment