목차

Ansible

Ubuntu PPA

sudo add-apt-repository ppa:ansible/ansible

AWS

become

ansible-playbook playbook.yml ... --user=username \
   --extra-vars "ansible_become_pass=yourPassword"
ansible-playbook playbook.yml ... \
    --extra-vars="ansible_become_pass='{{ lookup('env', 'SUDO_PASSWORD') }}'"

become_user

Local 실행

- name: playbook name
  hosts: localhost # 혹은 127.0.0.1 로도 작동했음.
  connection: local
  tasks:
    - name: blah.. blah..
# 실행
ansible-playbook playbook.yml

File 생성

  tasks:
  - name: Ansible create file with content example
    copy:
      dest: "/Users/mdtutorials2/Documents/Ansible/remote_server.txt"
      content: "contents"
      mode: 0777
      owner: mdtutorials2

환경변수 읽기

- debug: msg="{{ lookup('env', 'HOME') }} is an environment variable"

변수(var) 외부에 두고 include

- name: blah blah..
  hosts: ...
  vars_files:
    - "vars.yml" # file in the same directory
  tasks: ...
# key/value 쌍.
ubuntu_release: "{{ lookup('pipe', 'lsb_release -cs') }}"
current_user: "{{ lookup('env', 'USER') }}"
vagrant_version: 2.2.10
packer_version: 1.6.1
...

playbook 을 윈해 환경변수

- hosts: all
  roles:
     - php
     - nginx
  environment:
    MY_ENV_VARIABLE: whatever_value

특정 Task 용 환경변수

  tasks:
    - name: Echo my_env_var
      shell: "echo $MY_ENV_VARIABLE"
      environment:
        MY_ENV_VARIABLE: whatever_value

shell & command

apt repository

특정 태스크 지정

retries

ansible-pull

ansible-pull -U https://github.com/.../xxx.git

include / import

Linux System Roles

shell completion

sudo apt install python3-argcomplete
# 필히 "" 로 감싸야한다.
eval "$(register-python-argcomplete3 ansible)"
eval "$(register-python-argcomplete3 ansible-config)"
eval "$(register-python-argcomplete3 ansible-console)"
eval "$(register-python-argcomplete3 ansible-doc)"
eval "$(register-python-argcomplete3 ansible-galaxy)"
eval "$(register-python-argcomplete3 ansible-inventory)"
eval "$(register-python-argcomplete3 ansible-playbook)"
eval "$(register-python-argcomplete3 ansible-pull)"
eval "$(register-python-argcomplete3 ansible-vault)"

lineinfile module

replace module

참조