Monday, June 3, 2019

Ansible playbook - prepare the target demo machine

More Scripts:

# Run with ansible-playbook  -k
#  (make sure to add the IPs of machines you want to manage to /etc/ansibles/hosts first)

- hosts: gw
  gather_facts: False
  remote_user: root
  # become: yes
  # become_user: root
  # become_method: sudo

    - name: Install python 2
      raw: test -e /usr/bin/python || (yum update -y && yum install -y python)

    - name: Fancy way of doing authorized_keys
      authorized_key: user=root
                      key="{{ lookup('file', '~/.ssh/') }}"

    #- name: Create /root/.ssh
    #  file: path=/root/.ssh state=directory mode=0700

    #- name: Create /root/.ssh/authorized_keys from our local ssh pubkey
    #  lineinfile: dest=/root/.ssh/authorized_keys lines="{{ lookup('file','~/.ssh/') }}"

    - name: Set timezone to Asia/Singapore
      raw: ( timedatectl |grep "Time zone" |grep -i Singapore) || timedatectl set-timezone Asia/Singapore
    - name: Add lines to avoid "LC_TYPE" error in Mac OSX terminal
      lineinfile: dest=/etc/environment line='{{ item }}' state=present backup=yes
        - '# Add following 2 lines to fix LC_TYPE error'
        - 'LANG=en_US.utf-8'
        - 'LC_ALL=en_US.utf-8'


[gw] ansible_python_interpreter=/usr/bin/python ansible_user=root
Execute the playbook
Donghuas-MacBook-Air:ansible donghua$ ansible-playbook prepare_ansible_target.yaml -i host 

PLAY [gw] ****************************************************************************************************************************************

TASK [Install python 2] **************************************************************************************************************************
changed: []

TASK [Fancy way of doing authorized_keys] ********************************************************************************************************
ok: []

TASK [Set timezone to Asia/Singapore] ************************************************************************************************************
changed: []

TASK [Add lines to avoid "LC_TYPE" error in Mac OSX terminal] ************************************************************************************
ok: [] => (item=# Add following 2 lines to fix LC_TYPE error)
ok: [] => (item=LANG=en_US.utf-8)
ok: [] => (item=LC_ALL=en_US.utf-8)

PLAY RECAP ***************************************************************************************************************************************              : ok=4    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0