Files
vms/ansible/roles/vagrant/tasks/main.yml
T

72 lines
2.3 KiB
YAML
Raw Normal View History

2022-05-02 22:03:37 -05:00
- name: load vars, if needed
2022-05-05 08:17:48 -05:00
ansible.builtin.include_vars: "{{ item }}"
2022-05-02 22:03:37 -05:00
loop:
- "{{ role_path }}/vars/default.yml"
- "{{ role_path }}/vars/{{ ansible_facts.distribution }}.yml"
- "{{ role_path }}/vars/{{ ansible_facts.distribution }}_{{ ansible_facts.distribution_major_version }}.yml"
when: item is file
- name: remove cloud-init
become: true
2022-05-05 08:17:48 -05:00
ansible.builtin.package:
2022-05-02 22:03:37 -05:00
name: cloud-init
state: absent
when: ansible_facts.pkg_mgr not in ['atomic_container']
- name: get build time
become: true
2022-05-05 08:17:48 -05:00
ansible.builtin.copy:
2023-08-03 14:44:02 -05:00
content: "{{ ansible_facts.date_time.date }} {{ ansible_facts.date_time.hour }}:{{ ansible_facts.date_time.minute }}"
2022-05-02 22:03:37 -05:00
dest: /etc/vagrant_box_build_time
owner: root
group: root
mode: 0644
- name: create .ssh directory
2022-05-05 08:17:48 -05:00
ansible.builtin.file:
2022-05-02 22:03:37 -05:00
path: "{{ ansible_user_dir }}/.ssh"
state: directory
mode: "0700"
- name: fetch authorized_keys
2022-05-05 08:17:48 -05:00
ansible.builtin.get_url:
2022-05-02 22:03:37 -05:00
mode: "0600"
dest: "{{ ansible_user_dir }}/.ssh/authorized_keys"
url: https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub
2022-05-31 20:13:29 -05:00
- name: Sudo commands
block:
2022-05-02 22:03:37 -05:00
- name: configure sshd
2022-05-05 08:17:48 -05:00
ansible.builtin.lineinfile:
2022-05-02 22:03:37 -05:00
line: UseDNS no
path: /etc/ssh/sshd_config
- name: check for the sshd_config.d directory
2022-05-05 08:17:48 -05:00
ansible.builtin.stat:
2022-05-02 22:03:37 -05:00
path: /etc/ssh/sshd_config.d
register: _vagrant_sshd_config_d
- name: be sure that sshd is configured properly to accept the pubkey
2022-05-05 08:17:48 -05:00
ansible.builtin.copy:
2022-05-02 22:03:37 -05:00
content: PubkeyAcceptedKeyTypes +ssh-rsa
mode: "0600"
owner: root
group: root
dest: /etc/ssh/sshd_config.d/00-vagrant_accept_pubkey.conf
when: _vagrant_sshd_config_d.stat.exists
- name: enable sshd
2022-05-05 08:17:48 -05:00
ansible.builtin.service:
2022-05-02 22:03:37 -05:00
name: "{{ vagrant_ssh_service_name }}"
state: started
enabled: true
# Fedora 31 has a bug in systemd with kernel >= 5.8 that makes us
# unable to determine state of the service. However, if we were able
# to connect to it to run this Ansible, then we clearly are up
# and running and we can safely ignore this error
2022-05-05 08:17:48 -05:00
# noqa ignore-errors
2022-05-02 22:03:37 -05:00
ignore_errors: >-
{{ ansible_facts.distribution == 'Fedora' and
ansible_facts.distribution_major_version == '31' }}
become: true