---

# 1.x agent setup

- name: Create ThreatStack config directory
  file:
    path: "{{ threatstack_config_dir }}"
    state: directory
    owner: root
    group: root
    mode: 0644
    recurse: yes

- name: Create ThreatStack config file
  template:
    src: config.j2
    dest: "{{ threatstack_config }}"
    owner: root
    group: root
    mode: 0644

- name: Agent setup
  command: cloudsight setup --url={{ threatstack_url }} --config={{ threatstack_config }} --agent_type={{ agent_type }} {{ threatstack_agent_extra_args }}
  register: setup_result
  args:
    creates: /opt/threatstack/cloudsight/config/.audit

- name: Create file to track extra cloudsight config
  copy:
    content: "{{ threatstack_agent_config_args }} {{ agent_type }}"
    dest: /opt/threatstack/cloudsight/config/.config_args
    owner: root
    group: root
    mode: 0644
  when:
    - threatstack_agent_config_args is undefined
    - agent_type is undefined
  register: config_args

- name: Configure extra cloudsight parameters
  command: "cloudsight config {{ threatstack_agent_config_args }} {{ agent_type }}"
  when: config_args.changed
  notify: restart cloudsight

- name: Test agent state
  service:
    name: cloudsight
    enabled: yes
    state: started

---

# 1.x agent setup

- name: Create ThreatStack config directory
  file:
    path: "{{ threatstack_config_dir }}"
    state: directory
    owner: root
    group: root
    mode: 0644
    recurse: yes

- name: Create ThreatStack config file
  template:
    src: config.j2
    dest: "{{ threatstack_config }}"
    owner: root
    group: root
    mode: 0644

- name: Agent setup
  command: cloudsight setup --url={{ threatstack_url }} --config={{ threatstack_config }} --agent_type={{ agent_type }} {{ threatstack_agent_extra_args }}
  register: setup_result
  args:
    creates: /opt/threatstack/cloudsight/config/.audit

- name: Create file to track extra cloudsight config
  copy:
    content: "{{ threatstack_agent_config_args }} {{ agent_type }}"
    dest: /opt/threatstack/cloudsight/config/.config_args
    owner: root
    group: root
    mode: 0644
  when:
    - threatstack_agent_config_args is defined
    - agent_type is defined
  register: config_args

- name: Configure extra cloudsight parameters
  command: "cloudsight config {{ threatstack_agent_config_args }} {{ agent_type }}"
  when: config_args.changed
  notify: restart cloudsight

- name: Test agent state
  service:
    name: cloudsight
    enabled: yes
    state: started

Fix when conditional in config task
Fix when conditional in config task
