Ansible
#handson
Ansible の使い方
ネットワークを自動するための Ansible 入門ガイド — Ansible Documentation
【Ansible】DockerでAnsibleハンズオン
code: /etc/ansible/ansible.cfg
# (pathspec) Colon separated paths in which Ansible will search for Modules.
;library={{ ANSIBLE_HOME ~ "/plugins/modules:/usr/share/ansible/plugins/modules" }}
# (pathspec) Colon separated paths in which Ansible will search for Module utils files, which are shared by modules.
;module_utils={{ ANSIBLE_HOME ~ "/plugins/module_utils:/usr/share/ansible/plugins/module_utils" }}
code: /usr/share/ansible/plugins/modules/custom_module.py
#!/usr/bin/python3
import re
from ansible.module_utils.basic import AnsibleModule
def main():
module_args = dict(
input_file=dict(type='str', required=True)
)
module = AnsibleModule(
argument_spec=module_args,
supports_check_mode=True
)
input_file = module.params'input_file'
with open(input_file, 'r') as f:
html = f.read()
# Convert all lowercase characters to uppercase
html = re.sub(r'a-z', lambda m: m.group(0).upper(), html)
# Save modified HTML to the same file
with open(input_file, 'w') as f:
f.write(html)
module.exit_json(changed=True, result=input_file)
if __name__ == '__main__':
main()
code: zsh
eval $(ssh-agent -s)
ssh-add ~/.ssh/dub.pem
code: install_nginx23.yaml
- name: Use custom module
custom_module:
input_file: '{{ html_path }}index.html'
register: result
code: zsh
ansible-playbook install_nginx23.yaml -i inventory.txt -v