3. Ansible-Pioneer¶
3.1. Introduction¶
3.2. Ansible-Pioneer overview¶
3.4. Ansible-Pioneer procedure¶
3.4.1. Ansible-Pioneer workflow¶
Workflow details and references
- Register OS typeFrom themenu, register the OS type of the target device.For more information, see OS type.
- Register connection information for the targetFrom themenu, register connection information for the target.For more information, see Device list.
- Register operation nameFrom themenu, register an Operation list.For more information, see Operation list.
- **Register Ansible Automation Controller host information (if needed) **From themenu, Register information for the Ansible Automation Controller host.For more information, see Ansible Automation Controller host list.
- Register Interface informationFrom themenu, select Ansible Core, Ansible Automation Controller or Ansible Execution Agent for the execution engine and register connection information for the execution engine serverFor more information, see Interface information.
- Register Execution environment definition template management(If needed)From themenu, Register the template file for the Execution environment definition file (execution-environment.yml) which is used to build the Execution environment by the ansible-builder within the Ansible Execution Agent.For more information, see ansible_execution_environment_definition_template_list and Using the Template file registered to Ansible common ▶ Execution environment definition template ` and :menuselection:"Execution Environment Parameter Definition" Parameter sheet`.Installing ITA registers a template file that allows users to add python module and ansible galaxy collections.
- Register "Execution environment parameter definition" parameter sheet. sheet(If needed)Register Parameters that will be embedded to the execution environment definition file (execution-environment.yml) template file registered in.For more information, see Using the Template file registered to Ansible common ▶ Execution environment definition template ` and :menuselection:"Execution Environment Parameter Definition" Parameter sheet`.Installing ITA registers , thewith the parameters that embeds to the execution environment definition template file (execution-environment.yml) file is registered.
- Register Execution environment management (If needed)Register a link between theand the template file for the execution environment definition file (execution-environment.yml) registered inFor more information, see Execution environment management.Installing ITA registers a link between theand .
- Register Interactive typeFrom themenu, register an Interactive type.For more information, see Interactive type.
- Register Interactive fileFrom themenu, register an interactive file for the Interactive type OS type combination.For more information, see Interactive file colletion.
- **Register Global variables (if needed) **From themenu, register global variables to be used in the Playbook.For more information, see Global variable management.
- **Register Template files (if needed) **From themenu, register template files and template embedded variables to be used in the Playbooks.For more information, see Template management.
- **Register File material (if needed) **From themenu, register file materials and file embedded variables to be used in the Playbooks.For more information, see File management.
- **Register Unmanaged variables (if needed) **From themenu, register extracted variables which will not be displayed in 's .For more information, see Unmanaged target variable list.
- Register Interactive file to MovementFrom themenu, register a link between the Interactive file and Movement.For more information, see Movement-Interactive type link.
- Create parameter sheetFrom themenu, create a Parameter sheet which will have data registered to it that can configure settings for the target.For more information, see Parameter sheet creation function.
- Register data to Parameter sheetRegister data to the parameter sheet created in the previous step.For more information, see Parameter sheet creation function.
- Substitute value auto registration settingsFrom themenu, link the Movement variables with the Parameter sheet's item's setting values.For more information, see Substitute value auto registration settings.
- ExecuteFrom themenu, select the desired Movement and Operation and execute them.For more information, see Execute.
- Confirm execution statusFrom themenu,the status of all previously executed operations will be updated in realtime. Users can also monitor error logs and execution logs as well as stop them with an emergency stop.For more information, see Confirm execution status.
- Confirm execution historyFrom themenu, users can check the history of all previously executed operations..For more information, see Execution management.
3.6. Writing Interactive files (Ansible-Pioneer)¶
Terminology |
Description |
---|---|
Command prompt |
Strings waiting for command input when ssh connecting to the target server from a terminal, |
Standard output |
Command process result output from the Command prompt after input a command to the target server. |

図 3.51 Command prompt standard output¶
3.6.1. Interactive file structure¶
Section name |
Application |
---|---|
conf |
Specify the timeout value according to timeout parameter. timeout value: 1~3600(unit:second) |
exe_list |
Construct the target host with 4 kinds of dialog commands. |
- e.g.)conf session's timeout parameter example
# Comment conf: △△timeout: 10 exec_list: △:half width space
- e.g.)Password authentication input example.
exec_list: # Wait for ssh connection password input prompt and input the correct password. - expect: '*assword' exec: 'password'
3.6.2. Interactive Module¶
Module |
Application |
---|---|
expect |
Input commands after waiting for the command prompt from the target host. |
state |
Input the command to target host. The contents of the standard output until the prompt is output to the standard output are analyzed by external shell, and the result is determined. |
command |
Loops and conditional branching can be performed before and after inputting commands to the target host. |
localaction |
Input command in the environment Ansible Core/Ansible Automation Controller/Ansible execution agent is executed. |
expect module¶
Overview¶

Format¶
Input example¶
- e.g.)expect module input example.
# Wait for ssh connection password input prompt and input the correct password. - expect: '*assword' exec: 'password'
state module¶
Overview¶

Format¶
Input examples¶
- e.g.)state module Input examples
# cat the hosts file and grep the displayed results with parameter value. # If there is line containing 127.0.0.1 or lalhost, the result is determined as normal and proceed to the next. # If there is no such line, the result is determined as abnormal and the interactive file is terminated abnormally. exec_list: - state: 'cat /etc/hosts' prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' parameter: - '127.0.0.1' - 'localhost' - expect: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' exec: exit
- e.g.)Using success_exit
# cat the hosts file and grep the displayed results with parameter value. # If there is line containing 127.0.0.1 or lalhost, the result is determined as normal and proceed to the next. # 対象If there is no such line, the result is determined as abnormal and the interactive file is terminated abnormally. exec_list: - state: 'cat /etc/hosts' prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' parameter: - '127.0.0.1' - 'localhost' success_exit: yes - expect: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' exec: exit
- e.g.)Using ignore_errors
# cat the hosts file and grep the displayed results with parameter value. # If there is line containing 127.0.0.1 or lalhost, the result is determined as normal and proceed to the next. # If there is no such line, the result is determined as abnormal and proceed to the next according to the ignore_errors:yes settings. exec_list: - state: 'cat /etc/hosts' prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' parameter: - '127.0.0.1' - 'localhost' ignore_errors: yes - expect: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' exec: exit
- e.g.)Using shell
# cat the hosts file and evaluate the contents output by the user created shell. # Parameter value is given using user created shell parameter. # If a user created shell ends in an error, the interactive file will end. exec_list: - state: 'cat /etc/hosts' prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' shell: '/tmp/grep.sh' stdout_file: '/tmp/stdout.txt' parameter: - '127.0.0.1' - 'localhost' - expect: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' exec: exit
- e.g.) User shell(/tmp/grep.sh) example
#!/bin/bash STDOUT=/tmp/STDOUT.tmp STDERR=/tmp/STDERR.tmp cat $1 | grep $2 | grep $3 | wc -l >${STDOUT} 2>${STDERR} RET=$? if [ $RET -ne 0 ]; then EXIT_CODE=$RET else if [ -s ${STDERR} ]; then EXIT_CODE=1 else CNT=`cat ${STDOUT}` if [ ${CNT} -eq 0 ]; then EXIT_CODE=1 else EXIT_CODE=0 fi fi fi /bin/rm -rf ${STDOUT} ${STDERR} >/dev/null 2&>1
- e.g.)Save target host file to "Result data" with state.
# cat the hosts file and save the displayed result to the file specified by stdout_file then proceed to the next. # Will end in error if the default shell parameter is not configured. Set ignore_errors: yes in order to move to the next process. exec_list: - state: 'cat /etc/hosts' prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' stdout_file: '{{ __workflowdir__ }}/hosts' ignore_errors: yes - expect: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' exec: exit
command module¶
Overview¶

Format¶
Input examples¶
- e.g.) command module Input examplesInputting the following commands with the command module
systemctl start httpd systemctl start mysql
The variable's specific values used with "with_items" and the interactive file description are as following.- Interactive file contents
- command: "systemctl {{ item.0 }} {{ item.1 }}" prompt: '{{ item.2 }}' timeout: '{{ item.3 }}' with_items: - '{{ VAR_status_list }}' # item.0 - '{{ VAR_service_list }}' # item.1 - '{{ VAR_prompt_list }}' # item.2 - '{{ VAR_timeout_list }}' # item.3
- Variable specific values using with_items
VAR_status_list: - start - start VAR_service_list: - httpd - mysql # there are 2 specific values used by command. # The required amount of specific values for the variables using prompt and timeout is 3. VAR_prompt_list: - Command prompt - Command prompt - Command prompt VAR_timeout_list: - 10 - 10 - 10
- e.g.) Example using when
conf: timeout: 30 exec_list: - expect: 'password:' exec: '{{ __loginpassword__ }}' # If the ITA variable, VAR_hosts_make, is written in host variable file(The parameter sheet items and variables are linked in Susbtitute value auto registration), cat the host file. # If the variable are not written, the command is skipped. - command: cat /etc/hosts prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' when: - VAR_hosts_make is define - expect: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' exec: exit
- e.g.) Example using exec_when and register
conf: timeout: 30 exec_list: - expect: 'password:' exec: '{{ __loginpassword__ }}' # If the ITA variable, VAR_hosts_make, is written in host variable file, cat the host file. # If the variable are not written, the command is skipped. # Use cat to save the contents of the standard output hosts file to result_stdout. - command: cat /etc/hosts prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' register: result_stdout when: - VAR_hosts_make is define # If the ITA variable, VAR_hosts_make, is written in host variable file, cat the host file. # Input commad. If the variable are not written, the command is skipped. # Execute the command for the numbers of the specific values of the multiple specific value variables set in the with_items. # From the result of condition judgment for each loop, if "ip address host name" does not # correspond to the hosts file, Input command. "IP address Host name" is added to the end of the hosts file.。 - command: 'echo {{ item.0 }} {{ item.1 }} >> /etc/hosts' prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' when: - VAR_hosts_make is define with_items: - '{{ VAR_hosts_ip }}' # item.0 - '{{ VAR_hosts_name }}' # item.1 exec_when: - result_stdout no match({{ item.0 }} *{{ item.1 }}) - expect: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' exec: exit
- e.g.)Example using failed_when
conf: timeout: 30 exec_list: - expect: 'password:' exec: '{{ __loginpassword__ }}' # Execute the command for the numbers of the specific values of the multiple specific value variables set in the with_items. # Configure auto startup for the service. - command: 'systemctl enable {{ item.0 }}' prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' with_items: - '{{ VAR_service_name_list }}' # item.0 # Execute the command for the numbers of the specific values of the multiple specific value variables set in the with_items. # Start the service. - command: 'systemctl start {{ item.0 }}' prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' with_items: - '{{ VAR_service_name_list }}' # item.0 # Execute the command for the numbers of the specific values of the multiple specific value variables set in the with_items. # outputs service status (stdout) # If the content of result output to standard output contains the regular expression of item.1, the result is right. # For example, in the case that the specific value of VAR_service_status_list is set to running and the service is running, "running" in "Active: active(running)" matches so the result is right. (Move on to the next loop) # In the case that condition doesn't match, the result is determined as abnormal and the dialog file terminates abnormally. - command: 'systemctl status {{ item.0 }}' prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' with_items: - '{{ VAR_service_name_list }}' # item.0 - '{{ VAR_service_status_list }}' # item.1 failed_when: - stdout match({{ item.1 }}) - expect: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' exec: exit
- e.g.) Example using when with or/and condition
conf: timeout: 30 exec_list: - expect: 'password:' exec: '{{ __loginpassword__ }}' # Example of compound condition using and / or. # When processing with or condition, write the if statement horizontally. # When processing with and condition, describing the statement in multiple lines. # "when" is used as the example here but the same applies to exec_when and failed_when. - command: systemctl stop my_service prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' when: - '{{ VAR_status }} == 10 OR {{ VAR_status }} == 11' - '{{ VAR_sub_status }} == 20 OR {{ VAR_sub_status }} == 21' - expect: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' exec: exit
localaction module¶
Overview¶
Format¶
Input examples¶
- e.g.)localactionのInput examples
exec_list: - expect: 'password:' exec: '{{ __loginpassword__ }}' # Create a directory to output the hosts file for every host in the shared directory ({{ __symphony_workflowdir__ }}) of each Movement. - localaction: mkdir -p 0755 {{ __workflowdir__ }}/{{ __inventory_hostname__ }} ignore_errors: yes # Output hosts file contents to the directory created with localaction. - state: cat /etc/hosts prompt: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' stdout_file: '{{ __workflowdir__ }}/{{ __inventory_hostname__ }}/hosts' ignore_errors: yes - expect: '{{ __loginuser__ }}@{{ __inventory_hostname__ }}' exec: exit
3.6.3. Regular expression¶
Target character |
After Escape |
---|---|
\ |
\\
|
* |
\* |
. |
\. |
+ |
\+ |
? |
\? |
| |
\| |
{ } |
\{ \} |
( ) |
\( \) |
[ ] |
\[ \] |
^ |
\^ |
$ |
\$ |
- e.g.) Good example
expect: 'XAMPP Developer Files ¥[Y/n¥] exec_list:'
- e.g.) Bad example
expect: 'XAMPP Developer Files [Y/n] exec_list:'
3.6.4. Warning¶
Using state module and command module¶
- If the prompt parameter is a backward match in the regular table ". *If the prompt parameter contains the backward match ".If the backward match ". *Ј*", the result of the executed command (standard output) will be empty.D not use backward match regular expressions.
- e.g.)Regular expression backmatches
- state: echo 'saple data' prompt: '\.\*{{ __loginuser__ }}@{{ __inventory_hostname__ }}' stdout_file: '{{ __workflowdir__ }}/{{ __inventory_hostname__ }}/hosts'
- Processing interactive commandsNot processed with command and state modules, Create interactive files with expect module.
- e.g.)Interactive command "ssh-keygen" process example
# Process ssh-keygen in a dialogue file conf: timeout: 10 exec_list: # ssh connection Password authentication - expect: 'assword:' exec: '{{ __loginpassword__ }}' # Execute ssh-keygen command - expect: '{{ __loginuser__ }}@{{ __loginhostname__ }}' exec: ssh-keygen # The following is the process for prompts other than the command prompt. # Set file path of the secret key # Since expect is evaluated in regular notation, the escape character (\) must be inserted for characters that needs escape - expect: 'id_rsa\):' exec: '{{ VAR_id_rsa_path }}' # Configure Passprhase - expect: ' passphrase\):' exec: '{{ VAR_passphrase }}' # Configure Passprhase - expect: ' passphrase again:' exec: '{{ VAR_passphrase }}' # Check generated secret key file - expect: '{{ __loginuser__ }}@{{ __loginhostname__ }}' exec: 'ls -al {{ VAR_id_rsa_path }}' # Close ssh connection - expect: '{{ __loginuser__ }}@{{ __loginhostname__ }}' exec: exit
Using multiple specific value variables¶
Ending interactive files¶
- e.g.)Putting "exit" command for ending the session at the end of the interactive file.
conf: timeout: 10 exec_list: # ssh connection Password authentication - expect: 'assword:' exec: '{{ __loginpassword__ }}' # Copy file - expect: '{{ __loginuser__ }}@{{ __loginhostname__ }}' exec: 'cp -rfp {{ VAR_src_path }} {{ VAR_dest_path }}' # Write a line that waits for the previous command to end in the command prompt and inputs an exit command at the end of the Interactive file. - expect: '{{ __loginuser__ }}@{{ __loginhostname__ }}' exec: exit
Writing interactive files in YAML format¶
- When the Module parameters are not enclosed in quotation marks when inputting variables into them.
- When each parameter is described by a constant only and the entire parameter is not enclosed in quotation marks, e.g. when the constant ends in ":".

図 3.52 Writing Interactive files in yaml format¶
LANG for Target device login user¶
Termination codes for commands input to the target device¶
The termination code for the code executed to the target host sends "LF". If the termination code is "CRLF", add "r" to the end of the command.
conf:
timeout: 10
exec_list:
- expect: 'password:'
exec: 'XXXXXXXX\r'
- command: '{{ VAR_command }}\r'
prompt: '{{ __loginuser__ }}@{{ __loginhostname__ }}'
- state: '{{ VAR_state }}\r'
prompt: '{{ __loginuser__ }}@{{ __loginhostname__ }}'
parameter:
- '{{ VAR_parameter1 }}'
- '{{ VAR_parameter2 }}'
Operating System Command sequence¶
3.7. Appendix¶
3.7.2. Result data created when executing Ansible¶
File list saved to Ansible-Pioneer result data¶
File name |
Recorded contents |
Ansible Core |
Ansible Automation Controller |
Ansible Execution Agent |
---|---|---|---|---|
result.txt |
Records Ansible execution result's execution results |
〇 |
||
error.log |
Error output file with Executing.
Ansible-playbbok command standard error output file.
Contents displayed in the Execute confirmation error log.
|
〇 |
〇 |
|
exec.log.org |
xecution log output by Ansible-playbook |
〇 |
〇 |
〇 |
exec.log |
Edited Aexec.log.org
Contents displayed to the Execution confirmation execution log
|
〇 |
〇 |
〇 |
exec_<Execution number>_<group number> |
Divided execution log file
For more information regarding file name conventions, see the execution log in Confirm execution status .
|
〇 |
||
forced.txt |
Text file if stopped with Emergency stop |
〇 |
〇 |
|
user_files |
A directory where files are recorded when some file is output to ITA's original variable "__workflowdir__" in the playbook executed. |
〇 |
〇 |
〇 |
child_exec.log
child_error.log
|
ansible-builder execution log |
〇 |