0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Squidをリロードするansible-playbook

Last updated at Posted at 2019-06-08

Amazon Linux 2(Systemd)で動いている Squid のログ出力フォーマットを変更する際に、
Squidをリロードする必要がありました
その時のplaybookです

Systemdモジュールを使ってsquid.serviceをリロードしています
debugで結果(nameとstate)を出しています


- hosts: Proxy_DEV
# ------------------------------------- #
  user: ec2-user
  become: false
  tasks:
    # ------------------------------------------------ #
    - block:
      - name: reload squid
        systemd:
          name: squid.service
          state: reloaded
        register: result_cmd
        become: true

      - name: print result
        debug: msg="{{ result_cmd.name }} is {{ result_cmd.state }}"

Systemd モジュール
https://docs.ansible.com/ansible/latest/modules/systemd_module.html

debug モジュール
https://docs.ansible.com/ansible/latest/modules/debug_module.html

最終系・・・

- hosts: Proxy

# ------------------------------------- #
  user: ec2-user
  become: false
  tasks:
    - block:
      - name: check vars(config.json)
        debug: msg= "{{ inventory_hostname }}"

      - name: copy squid.conf from local to remote host
        copy:
          src: ./put_squid/squid.conf
          dest: /etc/squid/squid.conf
          owner: root
          group: squid
          mode: 0640
          backup: yes
        become: true
        register: result_copy
        when:
          - not ansible_check_mode
      
      - name: reload squid
        systemd:
          name: squid.service
          state: reloaded
        register: result_cmd
        become: true
        when:
          - result_copy.changed == true

      - name: print result
        debug: msg="{{ result_cmd.name }} is {{ result_cmd.state }}"

      - name: print result(file)
        local_action:
          module: copy
          content: "{{ result_cmd.stdout }}"
          dest: "./ansible_logs/{{ inventory_hostname }}/fetch-config.log"
        when: 
          - not ansible_check_mode
      
      #tags: [ 'never',  'exec_config' ]

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?