Last active
August 20, 2020 10:04
-
-
Save trolologuy/59a81c915d50c590885093cd8debbf84 to your computer and use it in GitHub Desktop.
Example for stackoverflow question 63502738 regarding MOTD issues with vagrant
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
- hosts: all | |
tasks: | |
- name: Update apt cache | |
apt: | |
update_cache: yes | |
become: yes | |
- name: Install zsh | |
apt: | |
name: zsh | |
state: present | |
become: yes | |
- name: Check current shell | |
shell: if echo $0 = "zsh" ; then echo "true"; else echo "false"; fi | |
register: zsh | |
- name: Change default shell to zsh | |
shell: 'sudo chsh -s /bin/zsh vagrant' | |
when: zsh.stdout == "false" | |
- name: Check if Oh My Zsh is already installed | |
shell: '[ -d "/home/vagrant/.oh-my-zsh" ] && echo "true" || echo "false"' | |
register: ohmyzsh_present | |
- name: Install Oh My Zsh (it can take several minutes to complete) | |
shell: 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended' | |
when: ohmyzsh_present.stdout == "false" | |
- name: Check that the message of the day (motd) file.conf exists | |
stat: | |
path: /etc/update-motd.d/01-custom | |
register: motd_custom | |
- name: Create the message of the day (motd) file, if it doesnt exist already (/etc/update-motd.d/01-custom) | |
file: | |
path: /etc/update-motd.d/01-custom | |
state: touch | |
mode: 0755 | |
owner: root | |
group: root | |
become: yes | |
become_user: root | |
when: not motd_custom.stat.exists | |
- name: Set message of the day (motd) | |
blockinfile: | |
path: /etc/update-motd.d/01-custom | |
marker: '' | |
block: | | |
#!/bin/sh | |
# System Overview | |
echo "\033[33;1m\nSystem Overview\n\033[0m" | |
/usr/bin/landscape-sysinfo | |
# System Updates | |
echo "\033[33;1m\nSystem Updates\n\033[0m" | |
/usr/lib/update-notifier/apt-check --human-readable | |
exit 0 | |
become: yes | |
become_user: root | |
when: not motd_custom.stat.exists | |
- name: Remove blank lines blockinfile put in | |
lineinfile : | |
path: /etc/update-motd.d/01-custom | |
state: absent | |
regexp: '^$' | |
become: yes | |
become_user: root | |
- name: update ssh config file to add the motd | |
shell: 'sed -i "s/.*PrintMotd.*/PrintMotd yes/g" /etc/ssh/sshd_config && sudo service ssh restart' | |
become: yes | |
become_user: root | |
when: not motd_custom.stat.exists |
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
Vagrant.require_version ">= 2.2.3" | |
Vagrant.configure("2") do |config| | |
config.vm.provider "virtualbox" do |v| | |
v.memory = 2048 | |
v.cpus = 2 | |
end | |
config.vm.box = "ubuntu/bionic64" | |
config.vm.hostname = "cli-tools" | |
config.vm.provision "ansible", type: "ansible" do |ansible| | |
ansible.playbook = "playbook.yml" | |
end | |
config.ssh.extra_args = ["-t", "zsh; cd /home/vagrant"] | |
config.ssh.forward_x11 = true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Link to the question:
https://stackoverflow.com/questions/63502738/message-of-the-day-motd-not-working-in-vagrant-with-ubuntu-18-04